debugfs.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  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 void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
  253. struct ieee80211_vif *vif,
  254. enum iwl_dbgfs_pm_mask param, int val)
  255. {
  256. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  257. struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
  258. dbgfs_pm->mask |= param;
  259. switch (param) {
  260. case MVM_DEBUGFS_PM_KEEP_ALIVE: {
  261. struct ieee80211_hw *hw = mvm->hw;
  262. int dtimper = hw->conf.ps_dtim_period ?: 1;
  263. int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
  264. IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
  265. if (val * MSEC_PER_SEC < 3 * dtimper_msec) {
  266. IWL_WARN(mvm,
  267. "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
  268. val * MSEC_PER_SEC, 3 * dtimper_msec);
  269. }
  270. dbgfs_pm->keep_alive_seconds = val;
  271. break;
  272. }
  273. case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
  274. IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
  275. val ? "enabled" : "disabled");
  276. dbgfs_pm->skip_over_dtim = val;
  277. break;
  278. case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
  279. IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
  280. dbgfs_pm->skip_dtim_periods = val;
  281. break;
  282. case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
  283. IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
  284. dbgfs_pm->rx_data_timeout = val;
  285. break;
  286. case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
  287. IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
  288. dbgfs_pm->tx_data_timeout = val;
  289. break;
  290. case MVM_DEBUGFS_PM_DISABLE_POWER_OFF:
  291. IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val);
  292. dbgfs_pm->disable_power_off = val;
  293. case MVM_DEBUGFS_PM_LPRX_ENA:
  294. IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
  295. dbgfs_pm->lprx_ena = val;
  296. break;
  297. case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
  298. IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
  299. dbgfs_pm->lprx_rssi_threshold = val;
  300. break;
  301. }
  302. }
  303. static ssize_t iwl_dbgfs_pm_params_write(struct file *file,
  304. const char __user *user_buf,
  305. size_t count, loff_t *ppos)
  306. {
  307. struct ieee80211_vif *vif = file->private_data;
  308. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  309. struct iwl_mvm *mvm = mvmvif->dbgfs_data;
  310. enum iwl_dbgfs_pm_mask param;
  311. char buf[32] = {};
  312. int val;
  313. int ret;
  314. if (copy_from_user(buf, user_buf, sizeof(buf)))
  315. return -EFAULT;
  316. if (!strncmp("keep_alive=", buf, 11)) {
  317. if (sscanf(buf + 11, "%d", &val) != 1)
  318. return -EINVAL;
  319. param = MVM_DEBUGFS_PM_KEEP_ALIVE;
  320. } else if (!strncmp("skip_over_dtim=", buf, 15)) {
  321. if (sscanf(buf + 15, "%d", &val) != 1)
  322. return -EINVAL;
  323. param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
  324. } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
  325. if (sscanf(buf + 18, "%d", &val) != 1)
  326. return -EINVAL;
  327. param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
  328. } else if (!strncmp("rx_data_timeout=", buf, 16)) {
  329. if (sscanf(buf + 16, "%d", &val) != 1)
  330. return -EINVAL;
  331. param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
  332. } else if (!strncmp("tx_data_timeout=", buf, 16)) {
  333. if (sscanf(buf + 16, "%d", &val) != 1)
  334. return -EINVAL;
  335. param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
  336. } else if (!strncmp("disable_power_off=", buf, 18)) {
  337. if (sscanf(buf + 18, "%d", &val) != 1)
  338. return -EINVAL;
  339. param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF;
  340. } else if (!strncmp("lprx=", buf, 5)) {
  341. if (sscanf(buf + 5, "%d", &val) != 1)
  342. return -EINVAL;
  343. param = MVM_DEBUGFS_PM_LPRX_ENA;
  344. } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
  345. if (sscanf(buf + 20, "%d", &val) != 1)
  346. return -EINVAL;
  347. if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
  348. POWER_LPRX_RSSI_THRESHOLD_MIN)
  349. return -EINVAL;
  350. param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
  351. } else {
  352. return -EINVAL;
  353. }
  354. mutex_lock(&mvm->mutex);
  355. iwl_dbgfs_update_pm(mvm, vif, param, val);
  356. ret = iwl_mvm_power_update_mode(mvm, vif);
  357. mutex_unlock(&mvm->mutex);
  358. return ret ?: count;
  359. }
  360. static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
  361. char __user *user_buf,
  362. size_t count, loff_t *ppos)
  363. {
  364. struct ieee80211_vif *vif = file->private_data;
  365. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  366. struct iwl_mvm *mvm = mvmvif->dbgfs_data;
  367. char buf[256];
  368. int bufsz = sizeof(buf);
  369. int pos;
  370. pos = iwl_mvm_power_dbgfs_read(mvm, vif, buf, bufsz);
  371. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  372. }
  373. static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
  374. char __user *user_buf,
  375. size_t count, loff_t *ppos)
  376. {
  377. struct ieee80211_vif *vif = file->private_data;
  378. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  379. struct iwl_mvm *mvm = mvmvif->dbgfs_data;
  380. u8 ap_sta_id;
  381. struct ieee80211_chanctx_conf *chanctx_conf;
  382. char buf[512];
  383. int bufsz = sizeof(buf);
  384. int pos = 0;
  385. int i;
  386. mutex_lock(&mvm->mutex);
  387. ap_sta_id = mvmvif->ap_sta_id;
  388. pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
  389. mvmvif->id, mvmvif->color);
  390. pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
  391. vif->bss_conf.bssid);
  392. pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
  393. for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) {
  394. pos += scnprintf(buf+pos, bufsz-pos,
  395. "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
  396. i, mvmvif->queue_params[i].txop,
  397. mvmvif->queue_params[i].cw_min,
  398. mvmvif->queue_params[i].cw_max,
  399. mvmvif->queue_params[i].aifs,
  400. mvmvif->queue_params[i].uapsd);
  401. }
  402. if (vif->type == NL80211_IFTYPE_STATION &&
  403. ap_sta_id != IWL_MVM_STATION_COUNT) {
  404. struct ieee80211_sta *sta;
  405. struct iwl_mvm_sta *mvm_sta;
  406. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
  407. lockdep_is_held(&mvm->mutex));
  408. mvm_sta = (void *)sta->drv_priv;
  409. pos += scnprintf(buf+pos, bufsz-pos,
  410. "ap_sta_id %d - reduced Tx power %d\n",
  411. ap_sta_id, mvm_sta->bt_reduced_txpower);
  412. }
  413. rcu_read_lock();
  414. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  415. if (chanctx_conf) {
  416. pos += scnprintf(buf+pos, bufsz-pos,
  417. "idle rx chains %d, active rx chains: %d\n",
  418. chanctx_conf->rx_chains_static,
  419. chanctx_conf->rx_chains_dynamic);
  420. }
  421. rcu_read_unlock();
  422. mutex_unlock(&mvm->mutex);
  423. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  424. }
  425. #define BT_MBOX_MSG(_notif, _num, _field) \
  426. ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
  427. >> BT_MBOX##_num##_##_field##_POS)
  428. #define BT_MBOX_PRINT(_num, _field, _end) \
  429. pos += scnprintf(buf + pos, bufsz - pos, \
  430. "\t%s: %d%s", \
  431. #_field, \
  432. BT_MBOX_MSG(notif, _num, _field), \
  433. true ? "\n" : ", ");
  434. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  435. size_t count, loff_t *ppos)
  436. {
  437. struct iwl_mvm *mvm = file->private_data;
  438. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  439. char *buf;
  440. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  441. buf = kmalloc(bufsz, GFP_KERNEL);
  442. if (!buf)
  443. return -ENOMEM;
  444. mutex_lock(&mvm->mutex);
  445. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  446. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  447. BT_MBOX_PRINT(0, LE_PROF1, false);
  448. BT_MBOX_PRINT(0, LE_PROF2, false);
  449. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  450. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  451. BT_MBOX_PRINT(0, INBAND_S, false);
  452. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  453. BT_MBOX_PRINT(0, LE_SCAN, false);
  454. BT_MBOX_PRINT(0, LE_ADV, false);
  455. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  456. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  457. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  458. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  459. BT_MBOX_PRINT(1, IP_SR, false);
  460. BT_MBOX_PRINT(1, LE_MSTR, false);
  461. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  462. BT_MBOX_PRINT(1, MSG_TYPE, false);
  463. BT_MBOX_PRINT(1, SSN, true);
  464. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  465. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  466. BT_MBOX_PRINT(2, PAG, false);
  467. BT_MBOX_PRINT(2, INQUIRY, false);
  468. BT_MBOX_PRINT(2, CONN, false);
  469. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  470. BT_MBOX_PRINT(2, DISC, false);
  471. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  472. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  473. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  474. BT_MBOX_PRINT(2, SCO_DURATION, true);
  475. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  476. BT_MBOX_PRINT(3, SCO_STATE, false);
  477. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  478. BT_MBOX_PRINT(3, A2DP_STATE, false);
  479. BT_MBOX_PRINT(3, ACL_STATE, false);
  480. BT_MBOX_PRINT(3, MSTR_STATE, false);
  481. BT_MBOX_PRINT(3, OBX_STATE, false);
  482. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  483. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  484. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  485. BT_MBOX_PRINT(3, INBAND_P, false);
  486. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  487. BT_MBOX_PRINT(3, SSN_2, false);
  488. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  489. pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
  490. notif->bt_status);
  491. pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
  492. notif->bt_open_conn);
  493. pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
  494. notif->bt_traffic_load);
  495. pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
  496. notif->bt_agg_traffic_load);
  497. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  498. notif->bt_ci_compliance);
  499. mutex_unlock(&mvm->mutex);
  500. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  501. kfree(buf);
  502. return ret;
  503. }
  504. #undef BT_MBOX_PRINT
  505. #define PRINT_STATS_LE32(_str, _val) \
  506. pos += scnprintf(buf + pos, bufsz - pos, \
  507. fmt_table, _str, \
  508. le32_to_cpu(_val))
  509. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  510. char __user *user_buf, size_t count,
  511. loff_t *ppos)
  512. {
  513. struct iwl_mvm *mvm = file->private_data;
  514. static const char *fmt_table = "\t%-30s %10u\n";
  515. static const char *fmt_header = "%-32s\n";
  516. int pos = 0;
  517. char *buf;
  518. int ret;
  519. int bufsz = sizeof(struct mvm_statistics_rx_phy) * 20 +
  520. sizeof(struct mvm_statistics_rx_non_phy) * 10 +
  521. sizeof(struct mvm_statistics_rx_ht_phy) * 10 + 200;
  522. struct mvm_statistics_rx_phy *ofdm;
  523. struct mvm_statistics_rx_phy *cck;
  524. struct mvm_statistics_rx_non_phy *general;
  525. struct mvm_statistics_rx_ht_phy *ht;
  526. buf = kzalloc(bufsz, GFP_KERNEL);
  527. if (!buf)
  528. return -ENOMEM;
  529. mutex_lock(&mvm->mutex);
  530. ofdm = &mvm->rx_stats.ofdm;
  531. cck = &mvm->rx_stats.cck;
  532. general = &mvm->rx_stats.general;
  533. ht = &mvm->rx_stats.ofdm_ht;
  534. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  535. "Statistics_Rx - OFDM");
  536. PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
  537. PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
  538. PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
  539. PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
  540. PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
  541. PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
  542. PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
  543. PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
  544. PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
  545. PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
  546. PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
  547. PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
  548. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  549. ofdm->rxe_frame_limit_overrun);
  550. PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
  551. PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
  552. PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
  553. PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
  554. PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
  555. PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
  556. PRINT_STATS_LE32("reserved", ofdm->reserved);
  557. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  558. "Statistics_Rx - CCK");
  559. PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
  560. PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
  561. PRINT_STATS_LE32("plcp_err", cck->plcp_err);
  562. PRINT_STATS_LE32("crc32_err", cck->crc32_err);
  563. PRINT_STATS_LE32("overrun_err", cck->overrun_err);
  564. PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
  565. PRINT_STATS_LE32("crc32_good", cck->crc32_good);
  566. PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
  567. PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
  568. PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
  569. PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
  570. PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
  571. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  572. cck->rxe_frame_limit_overrun);
  573. PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
  574. PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
  575. PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
  576. PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
  577. PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
  578. PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
  579. PRINT_STATS_LE32("reserved", cck->reserved);
  580. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  581. "Statistics_Rx - GENERAL");
  582. PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
  583. PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
  584. PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
  585. PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
  586. PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
  587. PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
  588. PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
  589. PRINT_STATS_LE32("adc_rx_saturation_time",
  590. general->adc_rx_saturation_time);
  591. PRINT_STATS_LE32("ina_detection_search_time",
  592. general->ina_detection_search_time);
  593. PRINT_STATS_LE32("beacon_silence_rssi_a",
  594. general->beacon_silence_rssi_a);
  595. PRINT_STATS_LE32("beacon_silence_rssi_b",
  596. general->beacon_silence_rssi_b);
  597. PRINT_STATS_LE32("beacon_silence_rssi_c",
  598. general->beacon_silence_rssi_c);
  599. PRINT_STATS_LE32("interference_data_flag",
  600. general->interference_data_flag);
  601. PRINT_STATS_LE32("channel_load", general->channel_load);
  602. PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
  603. PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
  604. PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
  605. PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
  606. PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
  607. PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
  608. PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
  609. PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
  610. PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
  611. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  612. "Statistics_Rx - HT");
  613. PRINT_STATS_LE32("plcp_err", ht->plcp_err);
  614. PRINT_STATS_LE32("overrun_err", ht->overrun_err);
  615. PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
  616. PRINT_STATS_LE32("crc32_good", ht->crc32_good);
  617. PRINT_STATS_LE32("crc32_err", ht->crc32_err);
  618. PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
  619. PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
  620. PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
  621. PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
  622. PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
  623. mutex_unlock(&mvm->mutex);
  624. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  625. kfree(buf);
  626. return ret;
  627. }
  628. #undef PRINT_STAT_LE32
  629. static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
  630. const char __user *user_buf,
  631. size_t count, loff_t *ppos)
  632. {
  633. struct iwl_mvm *mvm = file->private_data;
  634. int ret;
  635. mutex_lock(&mvm->mutex);
  636. /* allow one more restart that we're provoking here */
  637. if (mvm->restart_fw >= 0)
  638. mvm->restart_fw++;
  639. /* take the return value to make compiler happy - it will fail anyway */
  640. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
  641. mutex_unlock(&mvm->mutex);
  642. return count;
  643. }
  644. static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
  645. enum iwl_dbgfs_bf_mask param, int value)
  646. {
  647. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  648. struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
  649. dbgfs_bf->mask |= param;
  650. switch (param) {
  651. case MVM_DEBUGFS_BF_ENERGY_DELTA:
  652. dbgfs_bf->bf_energy_delta = value;
  653. break;
  654. case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
  655. dbgfs_bf->bf_roaming_energy_delta = value;
  656. break;
  657. case MVM_DEBUGFS_BF_ROAMING_STATE:
  658. dbgfs_bf->bf_roaming_state = value;
  659. break;
  660. case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
  661. dbgfs_bf->bf_temp_threshold = value;
  662. break;
  663. case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
  664. dbgfs_bf->bf_temp_fast_filter = value;
  665. break;
  666. case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
  667. dbgfs_bf->bf_temp_slow_filter = value;
  668. break;
  669. case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
  670. dbgfs_bf->bf_enable_beacon_filter = value;
  671. break;
  672. case MVM_DEBUGFS_BF_DEBUG_FLAG:
  673. dbgfs_bf->bf_debug_flag = value;
  674. break;
  675. case MVM_DEBUGFS_BF_ESCAPE_TIMER:
  676. dbgfs_bf->bf_escape_timer = value;
  677. break;
  678. case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
  679. dbgfs_bf->ba_enable_beacon_abort = value;
  680. break;
  681. case MVM_DEBUGFS_BA_ESCAPE_TIMER:
  682. dbgfs_bf->ba_escape_timer = value;
  683. break;
  684. }
  685. }
  686. static ssize_t iwl_dbgfs_bf_params_write(struct file *file,
  687. const char __user *user_buf,
  688. size_t count, loff_t *ppos)
  689. {
  690. struct ieee80211_vif *vif = file->private_data;
  691. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  692. struct iwl_mvm *mvm = mvmvif->dbgfs_data;
  693. enum iwl_dbgfs_bf_mask param;
  694. char buf[256];
  695. int buf_size;
  696. int value;
  697. int ret = 0;
  698. memset(buf, 0, sizeof(buf));
  699. buf_size = min(count, sizeof(buf) - 1);
  700. if (copy_from_user(buf, user_buf, buf_size))
  701. return -EFAULT;
  702. if (!strncmp("bf_energy_delta=", buf, 16)) {
  703. if (sscanf(buf+16, "%d", &value) != 1)
  704. return -EINVAL;
  705. if (value < IWL_BF_ENERGY_DELTA_MIN ||
  706. value > IWL_BF_ENERGY_DELTA_MAX)
  707. return -EINVAL;
  708. param = MVM_DEBUGFS_BF_ENERGY_DELTA;
  709. } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
  710. if (sscanf(buf+24, "%d", &value) != 1)
  711. return -EINVAL;
  712. if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
  713. value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
  714. return -EINVAL;
  715. param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
  716. } else if (!strncmp("bf_roaming_state=", buf, 17)) {
  717. if (sscanf(buf+17, "%d", &value) != 1)
  718. return -EINVAL;
  719. if (value < IWL_BF_ROAMING_STATE_MIN ||
  720. value > IWL_BF_ROAMING_STATE_MAX)
  721. return -EINVAL;
  722. param = MVM_DEBUGFS_BF_ROAMING_STATE;
  723. } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
  724. if (sscanf(buf+18, "%d", &value) != 1)
  725. return -EINVAL;
  726. if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
  727. value > IWL_BF_TEMP_THRESHOLD_MAX)
  728. return -EINVAL;
  729. param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
  730. } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
  731. if (sscanf(buf+20, "%d", &value) != 1)
  732. return -EINVAL;
  733. if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
  734. value > IWL_BF_TEMP_FAST_FILTER_MAX)
  735. return -EINVAL;
  736. param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
  737. } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
  738. if (sscanf(buf+20, "%d", &value) != 1)
  739. return -EINVAL;
  740. if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
  741. value > IWL_BF_TEMP_SLOW_FILTER_MAX)
  742. return -EINVAL;
  743. param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
  744. } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
  745. if (sscanf(buf+24, "%d", &value) != 1)
  746. return -EINVAL;
  747. if (value < 0 || value > 1)
  748. return -EINVAL;
  749. param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
  750. } else if (!strncmp("bf_debug_flag=", buf, 14)) {
  751. if (sscanf(buf+14, "%d", &value) != 1)
  752. return -EINVAL;
  753. if (value < 0 || value > 1)
  754. return -EINVAL;
  755. param = MVM_DEBUGFS_BF_DEBUG_FLAG;
  756. } else if (!strncmp("bf_escape_timer=", buf, 16)) {
  757. if (sscanf(buf+16, "%d", &value) != 1)
  758. return -EINVAL;
  759. if (value < IWL_BF_ESCAPE_TIMER_MIN ||
  760. value > IWL_BF_ESCAPE_TIMER_MAX)
  761. return -EINVAL;
  762. param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
  763. } else if (!strncmp("ba_escape_timer=", buf, 16)) {
  764. if (sscanf(buf+16, "%d", &value) != 1)
  765. return -EINVAL;
  766. if (value < IWL_BA_ESCAPE_TIMER_MIN ||
  767. value > IWL_BA_ESCAPE_TIMER_MAX)
  768. return -EINVAL;
  769. param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
  770. } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
  771. if (sscanf(buf+23, "%d", &value) != 1)
  772. return -EINVAL;
  773. if (value < 0 || value > 1)
  774. return -EINVAL;
  775. param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
  776. } else {
  777. return -EINVAL;
  778. }
  779. mutex_lock(&mvm->mutex);
  780. iwl_dbgfs_update_bf(vif, param, value);
  781. if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value) {
  782. ret = iwl_mvm_disable_beacon_filter(mvm, vif);
  783. } else {
  784. ret = iwl_mvm_enable_beacon_filter(mvm, vif);
  785. }
  786. mutex_unlock(&mvm->mutex);
  787. return ret ?: count;
  788. }
  789. static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
  790. char __user *user_buf,
  791. size_t count, loff_t *ppos)
  792. {
  793. struct ieee80211_vif *vif = file->private_data;
  794. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  795. char buf[256];
  796. int pos = 0;
  797. const size_t bufsz = sizeof(buf);
  798. struct iwl_beacon_filter_cmd cmd = {
  799. IWL_BF_CMD_CONFIG_DEFAULTS,
  800. .bf_enable_beacon_filter =
  801. cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
  802. .ba_enable_beacon_abort =
  803. cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
  804. };
  805. iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
  806. if (mvmvif->bf_enabled)
  807. cmd.bf_enable_beacon_filter = cpu_to_le32(1);
  808. else
  809. cmd.bf_enable_beacon_filter = 0;
  810. pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
  811. le32_to_cpu(cmd.bf_energy_delta));
  812. pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
  813. le32_to_cpu(cmd.bf_roaming_energy_delta));
  814. pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
  815. le32_to_cpu(cmd.bf_roaming_state));
  816. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
  817. le32_to_cpu(cmd.bf_temp_threshold));
  818. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
  819. le32_to_cpu(cmd.bf_temp_fast_filter));
  820. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
  821. le32_to_cpu(cmd.bf_temp_slow_filter));
  822. pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
  823. le32_to_cpu(cmd.bf_enable_beacon_filter));
  824. pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
  825. le32_to_cpu(cmd.bf_debug_flag));
  826. pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
  827. le32_to_cpu(cmd.bf_escape_timer));
  828. pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
  829. le32_to_cpu(cmd.ba_escape_timer));
  830. pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
  831. le32_to_cpu(cmd.ba_enable_beacon_abort));
  832. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  833. }
  834. #ifdef CONFIG_PM_SLEEP
  835. static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
  836. const char __user *user_buf,
  837. size_t count, loff_t *ppos)
  838. {
  839. struct iwl_mvm *mvm = file->private_data;
  840. char buf[8] = {};
  841. int store;
  842. if (copy_from_user(buf, user_buf, sizeof(buf)))
  843. return -EFAULT;
  844. if (sscanf(buf, "%d", &store) != 1)
  845. return -EINVAL;
  846. mvm->store_d3_resume_sram = store;
  847. return count;
  848. }
  849. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  850. size_t count, loff_t *ppos)
  851. {
  852. struct iwl_mvm *mvm = file->private_data;
  853. const struct fw_img *img;
  854. int ofs, len, pos = 0;
  855. size_t bufsz, ret;
  856. char *buf;
  857. u8 *ptr = mvm->d3_resume_sram;
  858. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  859. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  860. bufsz = len * 4 + 256;
  861. buf = kzalloc(bufsz, GFP_KERNEL);
  862. if (!buf)
  863. return -ENOMEM;
  864. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  865. mvm->store_d3_resume_sram ? "en" : "dis");
  866. if (ptr) {
  867. for (ofs = 0; ofs < len; ofs += 16) {
  868. pos += scnprintf(buf + pos, bufsz - pos,
  869. "0x%.4x ", ofs);
  870. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  871. bufsz - pos, false);
  872. pos += strlen(buf + pos);
  873. if (bufsz - pos > 0)
  874. buf[pos++] = '\n';
  875. }
  876. } else {
  877. pos += scnprintf(buf + pos, bufsz - pos,
  878. "(no data captured)\n");
  879. }
  880. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  881. kfree(buf);
  882. return ret;
  883. }
  884. #endif
  885. #define MVM_DEBUGFS_READ_FILE_OPS(name) \
  886. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  887. .read = iwl_dbgfs_##name##_read, \
  888. .open = simple_open, \
  889. .llseek = generic_file_llseek, \
  890. }
  891. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
  892. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  893. .write = iwl_dbgfs_##name##_write, \
  894. .read = iwl_dbgfs_##name##_read, \
  895. .open = simple_open, \
  896. .llseek = generic_file_llseek, \
  897. };
  898. #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
  899. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  900. .write = iwl_dbgfs_##name##_write, \
  901. .open = simple_open, \
  902. .llseek = generic_file_llseek, \
  903. };
  904. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
  905. if (!debugfs_create_file(#name, mode, parent, mvm, \
  906. &iwl_dbgfs_##name##_ops)) \
  907. goto err; \
  908. } while (0)
  909. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  910. if (!debugfs_create_file(#name, mode, parent, vif, \
  911. &iwl_dbgfs_##name##_ops)) \
  912. goto err; \
  913. } while (0)
  914. /* Device wide debugfs entries */
  915. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
  916. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
  917. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
  918. MVM_DEBUGFS_READ_FILE_OPS(stations);
  919. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  920. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
  921. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
  922. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  923. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
  924. #ifdef CONFIG_PM_SLEEP
  925. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
  926. #endif
  927. /* Interface specific debugfs entries */
  928. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  929. MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params);
  930. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params);
  931. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  932. {
  933. char buf[100];
  934. mvm->debugfs_dir = dbgfs_dir;
  935. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  936. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  937. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  938. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  939. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  940. MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
  941. MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
  942. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  943. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  944. #ifdef CONFIG_PM_SLEEP
  945. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  946. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  947. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  948. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  949. goto err;
  950. #endif
  951. /*
  952. * Create a symlink with mac80211. It will be removed when mac80211
  953. * exists (before the opmode exists which removes the target.)
  954. */
  955. snprintf(buf, 100, "../../%s/%s",
  956. dbgfs_dir->d_parent->d_parent->d_name.name,
  957. dbgfs_dir->d_parent->d_name.name);
  958. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  959. goto err;
  960. return 0;
  961. err:
  962. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  963. return -ENOMEM;
  964. }
  965. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  966. {
  967. struct dentry *dbgfs_dir = vif->debugfs_dir;
  968. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  969. char buf[100];
  970. if (!dbgfs_dir)
  971. return;
  972. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  973. mvmvif->dbgfs_data = mvm;
  974. if (!mvmvif->dbgfs_dir) {
  975. IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
  976. dbgfs_dir->d_name.name);
  977. return;
  978. }
  979. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
  980. vif->type == NL80211_IFTYPE_STATION && !vif->p2p)
  981. MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
  982. S_IRUSR);
  983. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
  984. S_IRUSR);
  985. if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  986. mvmvif == mvm->bf_allowed_vif)
  987. MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
  988. S_IRUSR | S_IWUSR);
  989. /*
  990. * Create symlink for convenience pointing to interface specific
  991. * debugfs entries for the driver. For example, under
  992. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  993. * find
  994. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  995. */
  996. snprintf(buf, 100, "../../../%s/%s/%s/%s",
  997. dbgfs_dir->d_parent->d_parent->d_name.name,
  998. dbgfs_dir->d_parent->d_name.name,
  999. dbgfs_dir->d_name.name,
  1000. mvmvif->dbgfs_dir->d_name.name);
  1001. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  1002. mvm->debugfs_dir, buf);
  1003. if (!mvmvif->dbgfs_slink)
  1004. IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
  1005. dbgfs_dir->d_name.name);
  1006. return;
  1007. err:
  1008. IWL_ERR(mvm, "Can't create debugfs entity\n");
  1009. }
  1010. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1011. {
  1012. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1013. debugfs_remove(mvmvif->dbgfs_slink);
  1014. mvmvif->dbgfs_slink = NULL;
  1015. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  1016. mvmvif->dbgfs_dir = NULL;
  1017. }