debugfs-vif.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  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 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include "mvm.h"
  66. #include "fw-api-tof.h"
  67. #include "debugfs.h"
  68. static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
  69. struct ieee80211_vif *vif,
  70. enum iwl_dbgfs_pm_mask param, int val)
  71. {
  72. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  73. struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
  74. dbgfs_pm->mask |= param;
  75. switch (param) {
  76. case MVM_DEBUGFS_PM_KEEP_ALIVE: {
  77. int dtimper = vif->bss_conf.dtim_period ?: 1;
  78. int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
  79. IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
  80. if (val * MSEC_PER_SEC < 3 * dtimper_msec)
  81. IWL_WARN(mvm,
  82. "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
  83. val * MSEC_PER_SEC, 3 * dtimper_msec);
  84. dbgfs_pm->keep_alive_seconds = val;
  85. break;
  86. }
  87. case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
  88. IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
  89. val ? "enabled" : "disabled");
  90. dbgfs_pm->skip_over_dtim = val;
  91. break;
  92. case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
  93. IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
  94. dbgfs_pm->skip_dtim_periods = val;
  95. break;
  96. case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
  97. IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
  98. dbgfs_pm->rx_data_timeout = val;
  99. break;
  100. case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
  101. IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
  102. dbgfs_pm->tx_data_timeout = val;
  103. break;
  104. case MVM_DEBUGFS_PM_LPRX_ENA:
  105. IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
  106. dbgfs_pm->lprx_ena = val;
  107. break;
  108. case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
  109. IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
  110. dbgfs_pm->lprx_rssi_threshold = val;
  111. break;
  112. case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
  113. IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
  114. dbgfs_pm->snooze_ena = val;
  115. break;
  116. case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
  117. IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
  118. dbgfs_pm->uapsd_misbehaving = val;
  119. break;
  120. case MVM_DEBUGFS_PM_USE_PS_POLL:
  121. IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
  122. dbgfs_pm->use_ps_poll = val;
  123. break;
  124. }
  125. }
  126. static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
  127. size_t count, loff_t *ppos)
  128. {
  129. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  130. struct iwl_mvm *mvm = mvmvif->mvm;
  131. enum iwl_dbgfs_pm_mask param;
  132. int val, ret;
  133. if (!strncmp("keep_alive=", buf, 11)) {
  134. if (sscanf(buf + 11, "%d", &val) != 1)
  135. return -EINVAL;
  136. param = MVM_DEBUGFS_PM_KEEP_ALIVE;
  137. } else if (!strncmp("skip_over_dtim=", buf, 15)) {
  138. if (sscanf(buf + 15, "%d", &val) != 1)
  139. return -EINVAL;
  140. param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
  141. } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
  142. if (sscanf(buf + 18, "%d", &val) != 1)
  143. return -EINVAL;
  144. param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
  145. } else if (!strncmp("rx_data_timeout=", buf, 16)) {
  146. if (sscanf(buf + 16, "%d", &val) != 1)
  147. return -EINVAL;
  148. param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
  149. } else if (!strncmp("tx_data_timeout=", buf, 16)) {
  150. if (sscanf(buf + 16, "%d", &val) != 1)
  151. return -EINVAL;
  152. param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
  153. } else if (!strncmp("lprx=", buf, 5)) {
  154. if (sscanf(buf + 5, "%d", &val) != 1)
  155. return -EINVAL;
  156. param = MVM_DEBUGFS_PM_LPRX_ENA;
  157. } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
  158. if (sscanf(buf + 20, "%d", &val) != 1)
  159. return -EINVAL;
  160. if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
  161. POWER_LPRX_RSSI_THRESHOLD_MIN)
  162. return -EINVAL;
  163. param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
  164. } else if (!strncmp("snooze_enable=", buf, 14)) {
  165. if (sscanf(buf + 14, "%d", &val) != 1)
  166. return -EINVAL;
  167. param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
  168. } else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
  169. if (sscanf(buf + 18, "%d", &val) != 1)
  170. return -EINVAL;
  171. param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
  172. } else if (!strncmp("use_ps_poll=", buf, 12)) {
  173. if (sscanf(buf + 12, "%d", &val) != 1)
  174. return -EINVAL;
  175. param = MVM_DEBUGFS_PM_USE_PS_POLL;
  176. } else {
  177. return -EINVAL;
  178. }
  179. mutex_lock(&mvm->mutex);
  180. iwl_dbgfs_update_pm(mvm, vif, param, val);
  181. ret = iwl_mvm_power_update_mac(mvm);
  182. mutex_unlock(&mvm->mutex);
  183. return ret ?: count;
  184. }
  185. static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
  186. char __user *user_buf,
  187. size_t count, loff_t *ppos)
  188. {
  189. struct ieee80211_vif *vif = file->private_data;
  190. char buf[64];
  191. int bufsz = sizeof(buf);
  192. int pos;
  193. pos = scnprintf(buf, bufsz, "bss limit = %d\n",
  194. vif->bss_conf.txpower);
  195. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  196. }
  197. static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
  198. char __user *user_buf,
  199. size_t count, loff_t *ppos)
  200. {
  201. struct ieee80211_vif *vif = file->private_data;
  202. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  203. struct iwl_mvm *mvm = mvmvif->mvm;
  204. char buf[512];
  205. int bufsz = sizeof(buf);
  206. int pos;
  207. pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
  208. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  209. }
  210. static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
  211. char __user *user_buf,
  212. size_t count, loff_t *ppos)
  213. {
  214. struct ieee80211_vif *vif = file->private_data;
  215. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  216. struct iwl_mvm *mvm = mvmvif->mvm;
  217. u8 ap_sta_id;
  218. struct ieee80211_chanctx_conf *chanctx_conf;
  219. char buf[512];
  220. int bufsz = sizeof(buf);
  221. int pos = 0;
  222. int i;
  223. mutex_lock(&mvm->mutex);
  224. ap_sta_id = mvmvif->ap_sta_id;
  225. switch (ieee80211_vif_type_p2p(vif)) {
  226. case NL80211_IFTYPE_ADHOC:
  227. pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
  228. break;
  229. case NL80211_IFTYPE_STATION:
  230. pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
  231. break;
  232. case NL80211_IFTYPE_AP:
  233. pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
  234. break;
  235. case NL80211_IFTYPE_P2P_CLIENT:
  236. pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
  237. break;
  238. case NL80211_IFTYPE_P2P_GO:
  239. pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
  240. break;
  241. case NL80211_IFTYPE_P2P_DEVICE:
  242. pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
  243. break;
  244. default:
  245. break;
  246. }
  247. pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
  248. mvmvif->id, mvmvif->color);
  249. pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
  250. vif->bss_conf.bssid);
  251. pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
  252. for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
  253. pos += scnprintf(buf+pos, bufsz-pos,
  254. "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
  255. i, mvmvif->queue_params[i].txop,
  256. mvmvif->queue_params[i].cw_min,
  257. mvmvif->queue_params[i].cw_max,
  258. mvmvif->queue_params[i].aifs,
  259. mvmvif->queue_params[i].uapsd);
  260. if (vif->type == NL80211_IFTYPE_STATION &&
  261. ap_sta_id != IWL_MVM_STATION_COUNT) {
  262. struct ieee80211_sta *sta;
  263. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
  264. lockdep_is_held(&mvm->mutex));
  265. if (!IS_ERR_OR_NULL(sta)) {
  266. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  267. pos += scnprintf(buf+pos, bufsz-pos,
  268. "ap_sta_id %d - reduced Tx power %d\n",
  269. ap_sta_id,
  270. mvm_sta->bt_reduced_txpower);
  271. }
  272. }
  273. rcu_read_lock();
  274. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  275. if (chanctx_conf)
  276. pos += scnprintf(buf+pos, bufsz-pos,
  277. "idle rx chains %d, active rx chains: %d\n",
  278. chanctx_conf->rx_chains_static,
  279. chanctx_conf->rx_chains_dynamic);
  280. rcu_read_unlock();
  281. mutex_unlock(&mvm->mutex);
  282. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  283. }
  284. static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
  285. enum iwl_dbgfs_bf_mask param, int value)
  286. {
  287. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  288. struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
  289. dbgfs_bf->mask |= param;
  290. switch (param) {
  291. case MVM_DEBUGFS_BF_ENERGY_DELTA:
  292. dbgfs_bf->bf_energy_delta = value;
  293. break;
  294. case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
  295. dbgfs_bf->bf_roaming_energy_delta = value;
  296. break;
  297. case MVM_DEBUGFS_BF_ROAMING_STATE:
  298. dbgfs_bf->bf_roaming_state = value;
  299. break;
  300. case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
  301. dbgfs_bf->bf_temp_threshold = value;
  302. break;
  303. case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
  304. dbgfs_bf->bf_temp_fast_filter = value;
  305. break;
  306. case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
  307. dbgfs_bf->bf_temp_slow_filter = value;
  308. break;
  309. case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
  310. dbgfs_bf->bf_enable_beacon_filter = value;
  311. break;
  312. case MVM_DEBUGFS_BF_DEBUG_FLAG:
  313. dbgfs_bf->bf_debug_flag = value;
  314. break;
  315. case MVM_DEBUGFS_BF_ESCAPE_TIMER:
  316. dbgfs_bf->bf_escape_timer = value;
  317. break;
  318. case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
  319. dbgfs_bf->ba_enable_beacon_abort = value;
  320. break;
  321. case MVM_DEBUGFS_BA_ESCAPE_TIMER:
  322. dbgfs_bf->ba_escape_timer = value;
  323. break;
  324. }
  325. }
  326. static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
  327. size_t count, loff_t *ppos)
  328. {
  329. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  330. struct iwl_mvm *mvm = mvmvif->mvm;
  331. enum iwl_dbgfs_bf_mask param;
  332. int value, ret = 0;
  333. if (!strncmp("bf_energy_delta=", buf, 16)) {
  334. if (sscanf(buf+16, "%d", &value) != 1)
  335. return -EINVAL;
  336. if (value < IWL_BF_ENERGY_DELTA_MIN ||
  337. value > IWL_BF_ENERGY_DELTA_MAX)
  338. return -EINVAL;
  339. param = MVM_DEBUGFS_BF_ENERGY_DELTA;
  340. } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
  341. if (sscanf(buf+24, "%d", &value) != 1)
  342. return -EINVAL;
  343. if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
  344. value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
  345. return -EINVAL;
  346. param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
  347. } else if (!strncmp("bf_roaming_state=", buf, 17)) {
  348. if (sscanf(buf+17, "%d", &value) != 1)
  349. return -EINVAL;
  350. if (value < IWL_BF_ROAMING_STATE_MIN ||
  351. value > IWL_BF_ROAMING_STATE_MAX)
  352. return -EINVAL;
  353. param = MVM_DEBUGFS_BF_ROAMING_STATE;
  354. } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
  355. if (sscanf(buf+18, "%d", &value) != 1)
  356. return -EINVAL;
  357. if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
  358. value > IWL_BF_TEMP_THRESHOLD_MAX)
  359. return -EINVAL;
  360. param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
  361. } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
  362. if (sscanf(buf+20, "%d", &value) != 1)
  363. return -EINVAL;
  364. if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
  365. value > IWL_BF_TEMP_FAST_FILTER_MAX)
  366. return -EINVAL;
  367. param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
  368. } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
  369. if (sscanf(buf+20, "%d", &value) != 1)
  370. return -EINVAL;
  371. if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
  372. value > IWL_BF_TEMP_SLOW_FILTER_MAX)
  373. return -EINVAL;
  374. param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
  375. } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
  376. if (sscanf(buf+24, "%d", &value) != 1)
  377. return -EINVAL;
  378. if (value < 0 || value > 1)
  379. return -EINVAL;
  380. param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
  381. } else if (!strncmp("bf_debug_flag=", buf, 14)) {
  382. if (sscanf(buf+14, "%d", &value) != 1)
  383. return -EINVAL;
  384. if (value < 0 || value > 1)
  385. return -EINVAL;
  386. param = MVM_DEBUGFS_BF_DEBUG_FLAG;
  387. } else if (!strncmp("bf_escape_timer=", buf, 16)) {
  388. if (sscanf(buf+16, "%d", &value) != 1)
  389. return -EINVAL;
  390. if (value < IWL_BF_ESCAPE_TIMER_MIN ||
  391. value > IWL_BF_ESCAPE_TIMER_MAX)
  392. return -EINVAL;
  393. param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
  394. } else if (!strncmp("ba_escape_timer=", buf, 16)) {
  395. if (sscanf(buf+16, "%d", &value) != 1)
  396. return -EINVAL;
  397. if (value < IWL_BA_ESCAPE_TIMER_MIN ||
  398. value > IWL_BA_ESCAPE_TIMER_MAX)
  399. return -EINVAL;
  400. param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
  401. } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
  402. if (sscanf(buf+23, "%d", &value) != 1)
  403. return -EINVAL;
  404. if (value < 0 || value > 1)
  405. return -EINVAL;
  406. param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
  407. } else {
  408. return -EINVAL;
  409. }
  410. mutex_lock(&mvm->mutex);
  411. iwl_dbgfs_update_bf(vif, param, value);
  412. if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
  413. ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  414. else
  415. ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  416. mutex_unlock(&mvm->mutex);
  417. return ret ?: count;
  418. }
  419. static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
  420. char __user *user_buf,
  421. size_t count, loff_t *ppos)
  422. {
  423. struct ieee80211_vif *vif = file->private_data;
  424. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  425. char buf[256];
  426. int pos = 0;
  427. const size_t bufsz = sizeof(buf);
  428. struct iwl_beacon_filter_cmd cmd = {
  429. IWL_BF_CMD_CONFIG_DEFAULTS,
  430. .bf_enable_beacon_filter =
  431. cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
  432. .ba_enable_beacon_abort =
  433. cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
  434. };
  435. iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
  436. if (mvmvif->bf_data.bf_enabled)
  437. cmd.bf_enable_beacon_filter = cpu_to_le32(1);
  438. else
  439. cmd.bf_enable_beacon_filter = 0;
  440. pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
  441. le32_to_cpu(cmd.bf_energy_delta));
  442. pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
  443. le32_to_cpu(cmd.bf_roaming_energy_delta));
  444. pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
  445. le32_to_cpu(cmd.bf_roaming_state));
  446. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
  447. le32_to_cpu(cmd.bf_temp_threshold));
  448. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
  449. le32_to_cpu(cmd.bf_temp_fast_filter));
  450. pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
  451. le32_to_cpu(cmd.bf_temp_slow_filter));
  452. pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
  453. le32_to_cpu(cmd.bf_enable_beacon_filter));
  454. pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
  455. le32_to_cpu(cmd.bf_debug_flag));
  456. pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
  457. le32_to_cpu(cmd.bf_escape_timer));
  458. pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
  459. le32_to_cpu(cmd.ba_escape_timer));
  460. pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
  461. le32_to_cpu(cmd.ba_enable_beacon_abort));
  462. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  463. }
  464. static inline char *iwl_dbgfs_is_match(char *name, char *buf)
  465. {
  466. int len = strlen(name);
  467. return !strncmp(name, buf, len) ? buf + len : NULL;
  468. }
  469. static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
  470. char *buf,
  471. size_t count, loff_t *ppos)
  472. {
  473. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  474. struct iwl_mvm *mvm = mvmvif->mvm;
  475. u32 value;
  476. int ret = -EINVAL;
  477. char *data;
  478. mutex_lock(&mvm->mutex);
  479. data = iwl_dbgfs_is_match("tof_disabled=", buf);
  480. if (data) {
  481. ret = kstrtou32(data, 10, &value);
  482. if (ret == 0)
  483. mvm->tof_data.tof_cfg.tof_disabled = value;
  484. goto out;
  485. }
  486. data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
  487. if (data) {
  488. ret = kstrtou32(data, 10, &value);
  489. if (ret == 0)
  490. mvm->tof_data.tof_cfg.one_sided_disabled = value;
  491. goto out;
  492. }
  493. data = iwl_dbgfs_is_match("is_debug_mode=", buf);
  494. if (data) {
  495. ret = kstrtou32(data, 10, &value);
  496. if (ret == 0)
  497. mvm->tof_data.tof_cfg.is_debug_mode = value;
  498. goto out;
  499. }
  500. data = iwl_dbgfs_is_match("is_buf=", buf);
  501. if (data) {
  502. ret = kstrtou32(data, 10, &value);
  503. if (ret == 0)
  504. mvm->tof_data.tof_cfg.is_buf_required = value;
  505. goto out;
  506. }
  507. data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
  508. if (data) {
  509. ret = kstrtou32(data, 10, &value);
  510. if (ret == 0 && value) {
  511. ret = iwl_mvm_tof_config_cmd(mvm);
  512. goto out;
  513. }
  514. }
  515. out:
  516. mutex_unlock(&mvm->mutex);
  517. return ret ?: count;
  518. }
  519. static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
  520. char __user *user_buf,
  521. size_t count, loff_t *ppos)
  522. {
  523. struct ieee80211_vif *vif = file->private_data;
  524. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  525. struct iwl_mvm *mvm = mvmvif->mvm;
  526. char buf[256];
  527. int pos = 0;
  528. const size_t bufsz = sizeof(buf);
  529. struct iwl_tof_config_cmd *cmd;
  530. cmd = &mvm->tof_data.tof_cfg;
  531. mutex_lock(&mvm->mutex);
  532. pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
  533. cmd->tof_disabled);
  534. pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
  535. cmd->one_sided_disabled);
  536. pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
  537. cmd->is_debug_mode);
  538. pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
  539. cmd->is_buf_required);
  540. mutex_unlock(&mvm->mutex);
  541. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  542. }
  543. static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
  544. char *buf,
  545. size_t count, loff_t *ppos)
  546. {
  547. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  548. struct iwl_mvm *mvm = mvmvif->mvm;
  549. u32 value;
  550. int ret = 0;
  551. char *data;
  552. mutex_lock(&mvm->mutex);
  553. data = iwl_dbgfs_is_match("burst_period=", buf);
  554. if (data) {
  555. ret = kstrtou32(data, 10, &value);
  556. if (!ret)
  557. mvm->tof_data.responder_cfg.burst_period =
  558. cpu_to_le16(value);
  559. goto out;
  560. }
  561. data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
  562. if (data) {
  563. ret = kstrtou32(data, 10, &value);
  564. if (ret == 0)
  565. mvm->tof_data.responder_cfg.min_delta_ftm = value;
  566. goto out;
  567. }
  568. data = iwl_dbgfs_is_match("burst_duration=", buf);
  569. if (data) {
  570. ret = kstrtou32(data, 10, &value);
  571. if (ret == 0)
  572. mvm->tof_data.responder_cfg.burst_duration = value;
  573. goto out;
  574. }
  575. data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
  576. if (data) {
  577. ret = kstrtou32(data, 10, &value);
  578. if (ret == 0)
  579. mvm->tof_data.responder_cfg.num_of_burst_exp = value;
  580. goto out;
  581. }
  582. data = iwl_dbgfs_is_match("abort_responder=", buf);
  583. if (data) {
  584. ret = kstrtou32(data, 10, &value);
  585. if (ret == 0)
  586. mvm->tof_data.responder_cfg.abort_responder = value;
  587. goto out;
  588. }
  589. data = iwl_dbgfs_is_match("get_ch_est=", buf);
  590. if (data) {
  591. ret = kstrtou32(data, 10, &value);
  592. if (ret == 0)
  593. mvm->tof_data.responder_cfg.get_ch_est = value;
  594. goto out;
  595. }
  596. data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
  597. if (data) {
  598. ret = kstrtou32(data, 10, &value);
  599. if (ret == 0)
  600. mvm->tof_data.responder_cfg.recv_sta_req_params = value;
  601. goto out;
  602. }
  603. data = iwl_dbgfs_is_match("channel_num=", buf);
  604. if (data) {
  605. ret = kstrtou32(data, 10, &value);
  606. if (ret == 0)
  607. mvm->tof_data.responder_cfg.channel_num = value;
  608. goto out;
  609. }
  610. data = iwl_dbgfs_is_match("bandwidth=", buf);
  611. if (data) {
  612. ret = kstrtou32(data, 10, &value);
  613. if (ret == 0)
  614. mvm->tof_data.responder_cfg.bandwidth = value;
  615. goto out;
  616. }
  617. data = iwl_dbgfs_is_match("rate=", buf);
  618. if (data) {
  619. ret = kstrtou32(data, 10, &value);
  620. if (ret == 0)
  621. mvm->tof_data.responder_cfg.rate = value;
  622. goto out;
  623. }
  624. data = iwl_dbgfs_is_match("bssid=", buf);
  625. if (data) {
  626. u8 *mac = mvm->tof_data.responder_cfg.bssid;
  627. if (!mac_pton(data, mac)) {
  628. ret = -EINVAL;
  629. goto out;
  630. }
  631. }
  632. data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
  633. if (data) {
  634. ret = kstrtou32(data, 10, &value);
  635. if (ret == 0)
  636. mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
  637. cpu_to_le16(value);
  638. goto out;
  639. }
  640. data = iwl_dbgfs_is_match("toa_offset=", buf);
  641. if (data) {
  642. ret = kstrtou32(data, 10, &value);
  643. if (ret == 0)
  644. mvm->tof_data.responder_cfg.toa_offset =
  645. cpu_to_le16(value);
  646. goto out;
  647. }
  648. data = iwl_dbgfs_is_match("center_freq=", buf);
  649. if (data) {
  650. struct iwl_tof_responder_config_cmd *cmd =
  651. &mvm->tof_data.responder_cfg;
  652. ret = kstrtou32(data, 10, &value);
  653. if (ret == 0 && value) {
  654. enum ieee80211_band band = (cmd->channel_num <= 14) ?
  655. IEEE80211_BAND_2GHZ :
  656. IEEE80211_BAND_5GHZ;
  657. struct ieee80211_channel chn = {
  658. .band = band,
  659. .center_freq = ieee80211_channel_to_frequency(
  660. cmd->channel_num, band),
  661. };
  662. struct cfg80211_chan_def chandef = {
  663. .chan = &chn,
  664. .center_freq1 =
  665. ieee80211_channel_to_frequency(value,
  666. band),
  667. };
  668. cmd->ctrl_ch_position = iwl_mvm_get_ctrl_pos(&chandef);
  669. }
  670. goto out;
  671. }
  672. data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
  673. if (data) {
  674. ret = kstrtou32(data, 10, &value);
  675. if (ret == 0)
  676. mvm->tof_data.responder_cfg.ftm_per_burst = value;
  677. goto out;
  678. }
  679. data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
  680. if (data) {
  681. ret = kstrtou32(data, 10, &value);
  682. if (ret == 0)
  683. mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
  684. goto out;
  685. }
  686. data = iwl_dbgfs_is_match("asap_mode=", buf);
  687. if (data) {
  688. ret = kstrtou32(data, 10, &value);
  689. if (ret == 0)
  690. mvm->tof_data.responder_cfg.asap_mode = value;
  691. goto out;
  692. }
  693. data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
  694. if (data) {
  695. ret = kstrtou32(data, 10, &value);
  696. if (ret == 0 && value) {
  697. ret = iwl_mvm_tof_responder_cmd(mvm, vif);
  698. goto out;
  699. }
  700. }
  701. out:
  702. mutex_unlock(&mvm->mutex);
  703. return ret ?: count;
  704. }
  705. static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
  706. char __user *user_buf,
  707. size_t count, loff_t *ppos)
  708. {
  709. struct ieee80211_vif *vif = file->private_data;
  710. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  711. struct iwl_mvm *mvm = mvmvif->mvm;
  712. char buf[256];
  713. int pos = 0;
  714. const size_t bufsz = sizeof(buf);
  715. struct iwl_tof_responder_config_cmd *cmd;
  716. cmd = &mvm->tof_data.responder_cfg;
  717. mutex_lock(&mvm->mutex);
  718. pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
  719. le16_to_cpu(cmd->burst_period));
  720. pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
  721. cmd->burst_duration);
  722. pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
  723. cmd->bandwidth);
  724. pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
  725. cmd->channel_num);
  726. pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
  727. cmd->ctrl_ch_position);
  728. pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
  729. cmd->bssid);
  730. pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
  731. cmd->min_delta_ftm);
  732. pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
  733. cmd->num_of_burst_exp);
  734. pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
  735. pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
  736. cmd->abort_responder);
  737. pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
  738. cmd->get_ch_est);
  739. pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
  740. cmd->recv_sta_req_params);
  741. pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
  742. cmd->ftm_per_burst);
  743. pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
  744. cmd->ftm_resp_ts_avail);
  745. pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
  746. cmd->asap_mode);
  747. pos += scnprintf(buf + pos, bufsz - pos,
  748. "tsf_timer_offset_msecs = %d\n",
  749. le16_to_cpu(cmd->tsf_timer_offset_msecs));
  750. pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
  751. le16_to_cpu(cmd->toa_offset));
  752. mutex_unlock(&mvm->mutex);
  753. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  754. }
  755. static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
  756. char *buf, size_t count,
  757. loff_t *ppos)
  758. {
  759. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  760. struct iwl_mvm *mvm = mvmvif->mvm;
  761. u32 value;
  762. int ret = 0;
  763. char *data;
  764. mutex_lock(&mvm->mutex);
  765. data = iwl_dbgfs_is_match("request_id=", buf);
  766. if (data) {
  767. ret = kstrtou32(data, 10, &value);
  768. if (ret == 0)
  769. mvm->tof_data.range_req.request_id = value;
  770. goto out;
  771. }
  772. data = iwl_dbgfs_is_match("initiator=", buf);
  773. if (data) {
  774. ret = kstrtou32(data, 10, &value);
  775. if (ret == 0)
  776. mvm->tof_data.range_req.initiator = value;
  777. goto out;
  778. }
  779. data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
  780. if (data) {
  781. ret = kstrtou32(data, 10, &value);
  782. if (ret == 0)
  783. mvm->tof_data.range_req.one_sided_los_disable = value;
  784. goto out;
  785. }
  786. data = iwl_dbgfs_is_match("req_timeout=", buf);
  787. if (data) {
  788. ret = kstrtou32(data, 10, &value);
  789. if (ret == 0)
  790. mvm->tof_data.range_req.req_timeout = value;
  791. goto out;
  792. }
  793. data = iwl_dbgfs_is_match("report_policy=", buf);
  794. if (data) {
  795. ret = kstrtou32(data, 10, &value);
  796. if (ret == 0)
  797. mvm->tof_data.range_req.report_policy = value;
  798. goto out;
  799. }
  800. data = iwl_dbgfs_is_match("macaddr_random=", buf);
  801. if (data) {
  802. ret = kstrtou32(data, 10, &value);
  803. if (ret == 0)
  804. mvm->tof_data.range_req.macaddr_random = value;
  805. goto out;
  806. }
  807. data = iwl_dbgfs_is_match("num_of_ap=", buf);
  808. if (data) {
  809. ret = kstrtou32(data, 10, &value);
  810. if (ret == 0)
  811. mvm->tof_data.range_req.num_of_ap = value;
  812. goto out;
  813. }
  814. data = iwl_dbgfs_is_match("macaddr_template=", buf);
  815. if (data) {
  816. u8 mac[ETH_ALEN];
  817. if (!mac_pton(data, mac)) {
  818. ret = -EINVAL;
  819. goto out;
  820. }
  821. memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
  822. goto out;
  823. }
  824. data = iwl_dbgfs_is_match("macaddr_mask=", buf);
  825. if (data) {
  826. u8 mac[ETH_ALEN];
  827. if (!mac_pton(data, mac)) {
  828. ret = -EINVAL;
  829. goto out;
  830. }
  831. memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
  832. goto out;
  833. }
  834. data = iwl_dbgfs_is_match("ap=", buf);
  835. if (data) {
  836. struct iwl_tof_range_req_ap_entry ap = {};
  837. int size = sizeof(struct iwl_tof_range_req_ap_entry);
  838. u16 burst_period;
  839. u8 *mac = ap.bssid;
  840. unsigned int i;
  841. if (sscanf(data, "%u %hhd %hhd %hhd"
  842. "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
  843. "%hhd %hhd %hd"
  844. "%hhd %hhd %d"
  845. "%hhx %hhd %hhd %hhd",
  846. &i, &ap.channel_num, &ap.bandwidth,
  847. &ap.ctrl_ch_position,
  848. mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
  849. &ap.measure_type, &ap.num_of_bursts,
  850. &burst_period,
  851. &ap.samples_per_burst, &ap.retries_per_sample,
  852. &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
  853. &ap.enable_dyn_ack, &ap.rssi) != 20) {
  854. ret = -EINVAL;
  855. goto out;
  856. }
  857. if (i >= IWL_MVM_TOF_MAX_APS) {
  858. IWL_ERR(mvm, "Invalid AP index %d\n", i);
  859. ret = -EINVAL;
  860. goto out;
  861. }
  862. ap.burst_period = cpu_to_le16(burst_period);
  863. memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
  864. goto out;
  865. }
  866. data = iwl_dbgfs_is_match("send_range_request=", buf);
  867. if (data) {
  868. ret = kstrtou32(data, 10, &value);
  869. if (ret == 0 && value)
  870. ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
  871. goto out;
  872. }
  873. ret = -EINVAL;
  874. out:
  875. mutex_unlock(&mvm->mutex);
  876. return ret ?: count;
  877. }
  878. static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
  879. char __user *user_buf,
  880. size_t count, loff_t *ppos)
  881. {
  882. struct ieee80211_vif *vif = file->private_data;
  883. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  884. struct iwl_mvm *mvm = mvmvif->mvm;
  885. char buf[512];
  886. int pos = 0;
  887. const size_t bufsz = sizeof(buf);
  888. struct iwl_tof_range_req_cmd *cmd;
  889. int i;
  890. cmd = &mvm->tof_data.range_req;
  891. mutex_lock(&mvm->mutex);
  892. pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
  893. cmd->request_id);
  894. pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
  895. cmd->initiator);
  896. pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
  897. cmd->one_sided_los_disable);
  898. pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
  899. cmd->req_timeout);
  900. pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
  901. cmd->report_policy);
  902. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
  903. cmd->macaddr_random);
  904. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
  905. cmd->macaddr_template);
  906. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
  907. cmd->macaddr_mask);
  908. pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
  909. cmd->num_of_ap);
  910. for (i = 0; i < cmd->num_of_ap; i++) {
  911. struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
  912. pos += scnprintf(buf + pos, bufsz - pos,
  913. "ap %.2d: channel_num=%hhd bw=%hhd"
  914. " control=%hhd bssid=%pM type=%hhd"
  915. " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
  916. " retries=%hhd tsf_delta=%d"
  917. " tsf_delta_direction=%hhd location_req=0x%hhx "
  918. " asap=%hhd enable=%hhd rssi=%hhd\n",
  919. i, ap->channel_num, ap->bandwidth,
  920. ap->ctrl_ch_position, ap->bssid,
  921. ap->measure_type, ap->num_of_bursts,
  922. ap->burst_period, ap->samples_per_burst,
  923. ap->retries_per_sample, ap->tsf_delta,
  924. ap->tsf_delta_direction,
  925. ap->location_req, ap->asap_mode,
  926. ap->enable_dyn_ack, ap->rssi);
  927. }
  928. mutex_unlock(&mvm->mutex);
  929. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  930. }
  931. static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
  932. char *buf,
  933. size_t count, loff_t *ppos)
  934. {
  935. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  936. struct iwl_mvm *mvm = mvmvif->mvm;
  937. u32 value;
  938. int ret = 0;
  939. char *data;
  940. mutex_lock(&mvm->mutex);
  941. data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
  942. if (data) {
  943. ret = kstrtou32(data, 10, &value);
  944. if (ret == 0)
  945. mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
  946. cpu_to_le16(value);
  947. goto out;
  948. }
  949. data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
  950. if (data) {
  951. ret = kstrtou32(data, 10, &value);
  952. if (ret == 0)
  953. mvm->tof_data.range_req_ext.min_delta_ftm = value;
  954. goto out;
  955. }
  956. data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
  957. if (data) {
  958. ret = kstrtou32(data, 10, &value);
  959. if (ret == 0)
  960. mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
  961. value;
  962. goto out;
  963. }
  964. data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
  965. if (data) {
  966. ret = kstrtou32(data, 10, &value);
  967. if (ret == 0)
  968. mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
  969. value;
  970. goto out;
  971. }
  972. data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
  973. if (data) {
  974. ret = kstrtou32(data, 10, &value);
  975. if (ret == 0)
  976. mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
  977. value;
  978. goto out;
  979. }
  980. data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
  981. if (data) {
  982. ret = kstrtou32(data, 10, &value);
  983. if (ret == 0 && value)
  984. ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
  985. goto out;
  986. }
  987. ret = -EINVAL;
  988. out:
  989. mutex_unlock(&mvm->mutex);
  990. return ret ?: count;
  991. }
  992. static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
  993. char __user *user_buf,
  994. size_t count, loff_t *ppos)
  995. {
  996. struct ieee80211_vif *vif = file->private_data;
  997. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  998. struct iwl_mvm *mvm = mvmvif->mvm;
  999. char buf[256];
  1000. int pos = 0;
  1001. const size_t bufsz = sizeof(buf);
  1002. struct iwl_tof_range_req_ext_cmd *cmd;
  1003. cmd = &mvm->tof_data.range_req_ext;
  1004. mutex_lock(&mvm->mutex);
  1005. pos += scnprintf(buf + pos, bufsz - pos,
  1006. "tsf_timer_offset_msec = %hd\n",
  1007. cmd->tsf_timer_offset_msec);
  1008. pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
  1009. cmd->min_delta_ftm);
  1010. pos += scnprintf(buf + pos, bufsz - pos,
  1011. "ftm_format_and_bw20M = %hhd\n",
  1012. cmd->ftm_format_and_bw20M);
  1013. pos += scnprintf(buf + pos, bufsz - pos,
  1014. "ftm_format_and_bw40M = %hhd\n",
  1015. cmd->ftm_format_and_bw40M);
  1016. pos += scnprintf(buf + pos, bufsz - pos,
  1017. "ftm_format_and_bw80M = %hhd\n",
  1018. cmd->ftm_format_and_bw80M);
  1019. mutex_unlock(&mvm->mutex);
  1020. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1021. }
  1022. static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
  1023. char *buf,
  1024. size_t count, loff_t *ppos)
  1025. {
  1026. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1027. struct iwl_mvm *mvm = mvmvif->mvm;
  1028. u32 value;
  1029. int abort_id, ret = 0;
  1030. char *data;
  1031. mutex_lock(&mvm->mutex);
  1032. data = iwl_dbgfs_is_match("abort_id=", buf);
  1033. if (data) {
  1034. ret = kstrtou32(data, 10, &value);
  1035. if (ret == 0)
  1036. mvm->tof_data.last_abort_id = value;
  1037. goto out;
  1038. }
  1039. data = iwl_dbgfs_is_match("send_range_abort=", buf);
  1040. if (data) {
  1041. ret = kstrtou32(data, 10, &value);
  1042. if (ret == 0 && value) {
  1043. abort_id = mvm->tof_data.last_abort_id;
  1044. ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
  1045. goto out;
  1046. }
  1047. }
  1048. out:
  1049. mutex_unlock(&mvm->mutex);
  1050. return ret ?: count;
  1051. }
  1052. static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
  1053. char __user *user_buf,
  1054. size_t count, loff_t *ppos)
  1055. {
  1056. struct ieee80211_vif *vif = file->private_data;
  1057. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1058. struct iwl_mvm *mvm = mvmvif->mvm;
  1059. char buf[32];
  1060. int pos = 0;
  1061. const size_t bufsz = sizeof(buf);
  1062. int last_abort_id;
  1063. mutex_lock(&mvm->mutex);
  1064. last_abort_id = mvm->tof_data.last_abort_id;
  1065. mutex_unlock(&mvm->mutex);
  1066. pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
  1067. last_abort_id);
  1068. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1069. }
  1070. static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
  1071. char __user *user_buf,
  1072. size_t count, loff_t *ppos)
  1073. {
  1074. struct ieee80211_vif *vif = file->private_data;
  1075. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1076. struct iwl_mvm *mvm = mvmvif->mvm;
  1077. char *buf;
  1078. int pos = 0;
  1079. const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
  1080. struct iwl_tof_range_rsp_ntfy *cmd;
  1081. int i, ret;
  1082. buf = kzalloc(bufsz, GFP_KERNEL);
  1083. if (!buf)
  1084. return -ENOMEM;
  1085. mutex_lock(&mvm->mutex);
  1086. cmd = &mvm->tof_data.range_resp;
  1087. pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
  1088. cmd->request_id);
  1089. pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
  1090. cmd->request_status);
  1091. pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
  1092. cmd->last_in_batch);
  1093. pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
  1094. cmd->num_of_aps);
  1095. for (i = 0; i < cmd->num_of_aps; i++) {
  1096. struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
  1097. pos += scnprintf(buf + pos, bufsz - pos,
  1098. "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
  1099. " rtt=%d rtt_var=%d rtt_spread=%d"
  1100. " rssi=%hhd rssi_spread=%hhd"
  1101. " range=%d range_var=%d"
  1102. " time_stamp=%d\n",
  1103. i, ap->bssid, ap->measure_status,
  1104. ap->measure_bw,
  1105. ap->rtt, ap->rtt_variance, ap->rtt_spread,
  1106. ap->rssi, ap->rssi_spread, ap->range,
  1107. ap->range_variance, ap->timestamp);
  1108. }
  1109. mutex_unlock(&mvm->mutex);
  1110. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1111. kfree(buf);
  1112. return ret;
  1113. }
  1114. static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
  1115. size_t count, loff_t *ppos)
  1116. {
  1117. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1118. struct iwl_mvm *mvm = mvmvif->mvm;
  1119. u8 value;
  1120. int ret;
  1121. ret = kstrtou8(buf, 0, &value);
  1122. if (ret)
  1123. return ret;
  1124. if (value > 1)
  1125. return -EINVAL;
  1126. mutex_lock(&mvm->mutex);
  1127. iwl_mvm_update_low_latency(mvm, vif, value);
  1128. mutex_unlock(&mvm->mutex);
  1129. return count;
  1130. }
  1131. static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
  1132. char __user *user_buf,
  1133. size_t count, loff_t *ppos)
  1134. {
  1135. struct ieee80211_vif *vif = file->private_data;
  1136. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1137. char buf[2];
  1138. buf[0] = mvmvif->low_latency ? '1' : '0';
  1139. buf[1] = '\n';
  1140. return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
  1141. }
  1142. static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
  1143. char __user *user_buf,
  1144. size_t count, loff_t *ppos)
  1145. {
  1146. struct ieee80211_vif *vif = file->private_data;
  1147. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1148. char buf[20];
  1149. int len;
  1150. len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
  1151. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1152. }
  1153. static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
  1154. char *buf, size_t count,
  1155. loff_t *ppos)
  1156. {
  1157. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1158. struct iwl_mvm *mvm = mvmvif->mvm;
  1159. bool ret;
  1160. mutex_lock(&mvm->mutex);
  1161. ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
  1162. mutex_unlock(&mvm->mutex);
  1163. return ret ? count : -EINVAL;
  1164. }
  1165. static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
  1166. size_t count, loff_t *ppos)
  1167. {
  1168. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1169. struct iwl_mvm *mvm = mvmvif->mvm;
  1170. struct ieee80211_chanctx_conf *chanctx_conf;
  1171. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1172. u16 value;
  1173. int ret;
  1174. ret = kstrtou16(buf, 0, &value);
  1175. if (ret)
  1176. return ret;
  1177. mutex_lock(&mvm->mutex);
  1178. rcu_read_lock();
  1179. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  1180. /* make sure the channel context is assigned */
  1181. if (!chanctx_conf) {
  1182. rcu_read_unlock();
  1183. mutex_unlock(&mvm->mutex);
  1184. return -EINVAL;
  1185. }
  1186. phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
  1187. rcu_read_unlock();
  1188. mvm->dbgfs_rx_phyinfo = value;
  1189. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
  1190. chanctx_conf->rx_chains_static,
  1191. chanctx_conf->rx_chains_dynamic);
  1192. mutex_unlock(&mvm->mutex);
  1193. return ret ?: count;
  1194. }
  1195. static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
  1196. char __user *user_buf,
  1197. size_t count, loff_t *ppos)
  1198. {
  1199. struct ieee80211_vif *vif = file->private_data;
  1200. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1201. char buf[8];
  1202. snprintf(buf, sizeof(buf), "0x%04x\n", mvmvif->mvm->dbgfs_rx_phyinfo);
  1203. return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
  1204. }
  1205. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1206. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
  1207. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1208. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
  1209. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  1210. if (!debugfs_create_file(#name, mode, parent, vif, \
  1211. &iwl_dbgfs_##name##_ops)) \
  1212. goto err; \
  1213. } while (0)
  1214. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  1215. MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
  1216. MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
  1217. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
  1218. MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
  1219. MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
  1220. MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
  1221. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
  1222. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
  1223. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
  1224. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
  1225. MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
  1226. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
  1227. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1228. {
  1229. struct dentry *dbgfs_dir = vif->debugfs_dir;
  1230. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1231. char buf[100];
  1232. /*
  1233. * Check if debugfs directory already exist before creating it.
  1234. * This may happen when, for example, resetting hw or suspend-resume
  1235. */
  1236. if (!dbgfs_dir || mvmvif->dbgfs_dir)
  1237. return;
  1238. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  1239. if (!mvmvif->dbgfs_dir) {
  1240. IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
  1241. dbgfs_dir->d_name.name);
  1242. return;
  1243. }
  1244. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
  1245. ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
  1246. (vif->type == NL80211_IFTYPE_STATION && vif->p2p &&
  1247. mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)))
  1248. MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
  1249. S_IRUSR);
  1250. MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, S_IRUSR);
  1251. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, S_IRUSR);
  1252. MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir,
  1253. S_IRUSR | S_IWUSR);
  1254. MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir,
  1255. S_IRUSR | S_IWUSR);
  1256. MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir,
  1257. S_IRUSR | S_IWUSR);
  1258. if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  1259. mvmvif == mvm->bf_allowed_vif)
  1260. MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
  1261. S_IRUSR | S_IWUSR);
  1262. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
  1263. !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
  1264. if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
  1265. MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
  1266. mvmvif->dbgfs_dir,
  1267. S_IRUSR | S_IWUSR);
  1268. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
  1269. S_IRUSR | S_IWUSR);
  1270. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
  1271. S_IRUSR | S_IWUSR);
  1272. MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
  1273. S_IRUSR | S_IWUSR);
  1274. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
  1275. S_IRUSR | S_IWUSR);
  1276. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
  1277. S_IRUSR);
  1278. }
  1279. /*
  1280. * Create symlink for convenience pointing to interface specific
  1281. * debugfs entries for the driver. For example, under
  1282. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  1283. * find
  1284. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  1285. */
  1286. snprintf(buf, 100, "../../../%s/%s/%s/%s",
  1287. dbgfs_dir->d_parent->d_parent->d_name.name,
  1288. dbgfs_dir->d_parent->d_name.name,
  1289. dbgfs_dir->d_name.name,
  1290. mvmvif->dbgfs_dir->d_name.name);
  1291. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  1292. mvm->debugfs_dir, buf);
  1293. if (!mvmvif->dbgfs_slink)
  1294. IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
  1295. dbgfs_dir->d_name.name);
  1296. return;
  1297. err:
  1298. IWL_ERR(mvm, "Can't create debugfs entity\n");
  1299. }
  1300. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1301. {
  1302. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1303. debugfs_remove(mvmvif->dbgfs_slink);
  1304. mvmvif->dbgfs_slink = NULL;
  1305. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  1306. mvmvif->dbgfs_dir = NULL;
  1307. }