debugfs.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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. if (mvmvif->bf_enabled)
  785. ret = iwl_mvm_enable_beacon_filter(mvm, vif);
  786. else
  787. ret = iwl_mvm_disable_beacon_filter(mvm, vif);
  788. }
  789. mutex_unlock(&mvm->mutex);
  790. return ret ?: count;
  791. }
  792. static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
  793. char __user *user_buf,
  794. size_t count, loff_t *ppos)
  795. {
  796. struct ieee80211_vif *vif = file->private_data;
  797. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  798. char buf[256];
  799. int pos = 0;
  800. const size_t bufsz = sizeof(buf);
  801. struct iwl_beacon_filter_cmd cmd = {
  802. IWL_BF_CMD_CONFIG_DEFAULTS,
  803. .bf_enable_beacon_filter =
  804. cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
  805. .ba_enable_beacon_abort =
  806. cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
  807. };
  808. iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
  809. if (mvmvif->bf_enabled)
  810. cmd.bf_enable_beacon_filter = cpu_to_le32(1);
  811. else
  812. cmd.bf_enable_beacon_filter = 0;
  813. pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
  814. le32_to_cpu(cmd.bf_energy_delta));
  815. pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
  816. le32_to_cpu(cmd.bf_roaming_energy_delta));
  817. pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
  818. le32_to_cpu(cmd.bf_roaming_state));
  819. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
  820. le32_to_cpu(cmd.bf_temp_threshold));
  821. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
  822. le32_to_cpu(cmd.bf_temp_fast_filter));
  823. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
  824. le32_to_cpu(cmd.bf_temp_slow_filter));
  825. pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
  826. le32_to_cpu(cmd.bf_enable_beacon_filter));
  827. pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
  828. le32_to_cpu(cmd.bf_debug_flag));
  829. pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
  830. le32_to_cpu(cmd.bf_escape_timer));
  831. pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
  832. le32_to_cpu(cmd.ba_escape_timer));
  833. pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
  834. le32_to_cpu(cmd.ba_enable_beacon_abort));
  835. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  836. }
  837. #ifdef CONFIG_PM_SLEEP
  838. static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
  839. const char __user *user_buf,
  840. size_t count, loff_t *ppos)
  841. {
  842. struct iwl_mvm *mvm = file->private_data;
  843. char buf[8] = {};
  844. int store;
  845. if (copy_from_user(buf, user_buf, sizeof(buf)))
  846. return -EFAULT;
  847. if (sscanf(buf, "%d", &store) != 1)
  848. return -EINVAL;
  849. mvm->store_d3_resume_sram = store;
  850. return count;
  851. }
  852. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  853. size_t count, loff_t *ppos)
  854. {
  855. struct iwl_mvm *mvm = file->private_data;
  856. const struct fw_img *img;
  857. int ofs, len, pos = 0;
  858. size_t bufsz, ret;
  859. char *buf;
  860. u8 *ptr = mvm->d3_resume_sram;
  861. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  862. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  863. bufsz = len * 4 + 256;
  864. buf = kzalloc(bufsz, GFP_KERNEL);
  865. if (!buf)
  866. return -ENOMEM;
  867. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  868. mvm->store_d3_resume_sram ? "en" : "dis");
  869. if (ptr) {
  870. for (ofs = 0; ofs < len; ofs += 16) {
  871. pos += scnprintf(buf + pos, bufsz - pos,
  872. "0x%.4x ", ofs);
  873. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  874. bufsz - pos, false);
  875. pos += strlen(buf + pos);
  876. if (bufsz - pos > 0)
  877. buf[pos++] = '\n';
  878. }
  879. } else {
  880. pos += scnprintf(buf + pos, bufsz - pos,
  881. "(no data captured)\n");
  882. }
  883. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  884. kfree(buf);
  885. return ret;
  886. }
  887. #endif
  888. #define MVM_DEBUGFS_READ_FILE_OPS(name) \
  889. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  890. .read = iwl_dbgfs_##name##_read, \
  891. .open = simple_open, \
  892. .llseek = generic_file_llseek, \
  893. }
  894. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
  895. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  896. .write = iwl_dbgfs_##name##_write, \
  897. .read = iwl_dbgfs_##name##_read, \
  898. .open = simple_open, \
  899. .llseek = generic_file_llseek, \
  900. };
  901. #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
  902. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  903. .write = iwl_dbgfs_##name##_write, \
  904. .open = simple_open, \
  905. .llseek = generic_file_llseek, \
  906. };
  907. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
  908. if (!debugfs_create_file(#name, mode, parent, mvm, \
  909. &iwl_dbgfs_##name##_ops)) \
  910. goto err; \
  911. } while (0)
  912. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  913. if (!debugfs_create_file(#name, mode, parent, vif, \
  914. &iwl_dbgfs_##name##_ops)) \
  915. goto err; \
  916. } while (0)
  917. /* Device wide debugfs entries */
  918. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
  919. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
  920. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
  921. MVM_DEBUGFS_READ_FILE_OPS(stations);
  922. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  923. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
  924. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
  925. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  926. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
  927. #ifdef CONFIG_PM_SLEEP
  928. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
  929. #endif
  930. /* Interface specific debugfs entries */
  931. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  932. MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params);
  933. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params);
  934. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  935. {
  936. char buf[100];
  937. mvm->debugfs_dir = dbgfs_dir;
  938. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  939. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  940. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  941. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  942. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  943. MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
  944. MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
  945. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  946. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  947. #ifdef CONFIG_PM_SLEEP
  948. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  949. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  950. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  951. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  952. goto err;
  953. #endif
  954. /*
  955. * Create a symlink with mac80211. It will be removed when mac80211
  956. * exists (before the opmode exists which removes the target.)
  957. */
  958. snprintf(buf, 100, "../../%s/%s",
  959. dbgfs_dir->d_parent->d_parent->d_name.name,
  960. dbgfs_dir->d_parent->d_name.name);
  961. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  962. goto err;
  963. return 0;
  964. err:
  965. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  966. return -ENOMEM;
  967. }
  968. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  969. {
  970. struct dentry *dbgfs_dir = vif->debugfs_dir;
  971. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  972. char buf[100];
  973. /*
  974. * Check if debugfs directory already exist before creating it.
  975. * This may happen when, for example, resetting hw or suspend-resume
  976. */
  977. if (!dbgfs_dir || mvmvif->dbgfs_dir)
  978. return;
  979. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  980. mvmvif->dbgfs_data = mvm;
  981. if (!mvmvif->dbgfs_dir) {
  982. IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
  983. dbgfs_dir->d_name.name);
  984. return;
  985. }
  986. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
  987. vif->type == NL80211_IFTYPE_STATION && !vif->p2p)
  988. MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
  989. S_IRUSR);
  990. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
  991. S_IRUSR);
  992. if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  993. mvmvif == mvm->bf_allowed_vif)
  994. MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
  995. S_IRUSR | S_IWUSR);
  996. /*
  997. * Create symlink for convenience pointing to interface specific
  998. * debugfs entries for the driver. For example, under
  999. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  1000. * find
  1001. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  1002. */
  1003. snprintf(buf, 100, "../../../%s/%s/%s/%s",
  1004. dbgfs_dir->d_parent->d_parent->d_name.name,
  1005. dbgfs_dir->d_parent->d_name.name,
  1006. dbgfs_dir->d_name.name,
  1007. mvmvif->dbgfs_dir->d_name.name);
  1008. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  1009. mvm->debugfs_dir, buf);
  1010. if (!mvmvif->dbgfs_slink)
  1011. IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
  1012. dbgfs_dir->d_name.name);
  1013. return;
  1014. err:
  1015. IWL_ERR(mvm, "Can't create debugfs entity\n");
  1016. }
  1017. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1018. {
  1019. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1020. debugfs_remove(mvmvif->dbgfs_slink);
  1021. mvmvif->dbgfs_slink = NULL;
  1022. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  1023. mvmvif->dbgfs_dir = NULL;
  1024. }