debugfs.c 40 KB

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