debugfs.c 37 KB

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