debugfs-vif.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  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("ctrl_ch_position=", buf);
  649. if (data) {
  650. ret = kstrtou32(data, 10, &value);
  651. if (ret == 0)
  652. mvm->tof_data.responder_cfg.ctrl_ch_position = value;
  653. goto out;
  654. }
  655. data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
  656. if (data) {
  657. ret = kstrtou32(data, 10, &value);
  658. if (ret == 0)
  659. mvm->tof_data.responder_cfg.ftm_per_burst = value;
  660. goto out;
  661. }
  662. data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
  663. if (data) {
  664. ret = kstrtou32(data, 10, &value);
  665. if (ret == 0)
  666. mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
  667. goto out;
  668. }
  669. data = iwl_dbgfs_is_match("asap_mode=", buf);
  670. if (data) {
  671. ret = kstrtou32(data, 10, &value);
  672. if (ret == 0)
  673. mvm->tof_data.responder_cfg.asap_mode = value;
  674. goto out;
  675. }
  676. data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
  677. if (data) {
  678. ret = kstrtou32(data, 10, &value);
  679. if (ret == 0 && value) {
  680. ret = iwl_mvm_tof_responder_cmd(mvm, vif);
  681. goto out;
  682. }
  683. }
  684. out:
  685. mutex_unlock(&mvm->mutex);
  686. return ret ?: count;
  687. }
  688. static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
  689. char __user *user_buf,
  690. size_t count, loff_t *ppos)
  691. {
  692. struct ieee80211_vif *vif = file->private_data;
  693. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  694. struct iwl_mvm *mvm = mvmvif->mvm;
  695. char buf[256];
  696. int pos = 0;
  697. const size_t bufsz = sizeof(buf);
  698. struct iwl_tof_responder_config_cmd *cmd;
  699. cmd = &mvm->tof_data.responder_cfg;
  700. mutex_lock(&mvm->mutex);
  701. pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
  702. le16_to_cpu(cmd->burst_period));
  703. pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
  704. cmd->burst_duration);
  705. pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
  706. cmd->bandwidth);
  707. pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
  708. cmd->channel_num);
  709. pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
  710. cmd->ctrl_ch_position);
  711. pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
  712. cmd->bssid);
  713. pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
  714. cmd->min_delta_ftm);
  715. pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
  716. cmd->num_of_burst_exp);
  717. pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
  718. pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
  719. cmd->abort_responder);
  720. pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
  721. cmd->get_ch_est);
  722. pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
  723. cmd->recv_sta_req_params);
  724. pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
  725. cmd->ftm_per_burst);
  726. pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
  727. cmd->ftm_resp_ts_avail);
  728. pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
  729. cmd->asap_mode);
  730. pos += scnprintf(buf + pos, bufsz - pos,
  731. "tsf_timer_offset_msecs = %d\n",
  732. le16_to_cpu(cmd->tsf_timer_offset_msecs));
  733. pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
  734. le16_to_cpu(cmd->toa_offset));
  735. mutex_unlock(&mvm->mutex);
  736. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  737. }
  738. static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
  739. char *buf, size_t count,
  740. loff_t *ppos)
  741. {
  742. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  743. struct iwl_mvm *mvm = mvmvif->mvm;
  744. u32 value;
  745. int ret = 0;
  746. char *data;
  747. mutex_lock(&mvm->mutex);
  748. data = iwl_dbgfs_is_match("request_id=", buf);
  749. if (data) {
  750. ret = kstrtou32(data, 10, &value);
  751. if (ret == 0)
  752. mvm->tof_data.range_req.request_id = value;
  753. goto out;
  754. }
  755. data = iwl_dbgfs_is_match("initiator=", buf);
  756. if (data) {
  757. ret = kstrtou32(data, 10, &value);
  758. if (ret == 0)
  759. mvm->tof_data.range_req.initiator = value;
  760. goto out;
  761. }
  762. data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
  763. if (data) {
  764. ret = kstrtou32(data, 10, &value);
  765. if (ret == 0)
  766. mvm->tof_data.range_req.one_sided_los_disable = value;
  767. goto out;
  768. }
  769. data = iwl_dbgfs_is_match("req_timeout=", buf);
  770. if (data) {
  771. ret = kstrtou32(data, 10, &value);
  772. if (ret == 0)
  773. mvm->tof_data.range_req.req_timeout = value;
  774. goto out;
  775. }
  776. data = iwl_dbgfs_is_match("report_policy=", buf);
  777. if (data) {
  778. ret = kstrtou32(data, 10, &value);
  779. if (ret == 0)
  780. mvm->tof_data.range_req.report_policy = value;
  781. goto out;
  782. }
  783. data = iwl_dbgfs_is_match("macaddr_random=", buf);
  784. if (data) {
  785. ret = kstrtou32(data, 10, &value);
  786. if (ret == 0)
  787. mvm->tof_data.range_req.macaddr_random = value;
  788. goto out;
  789. }
  790. data = iwl_dbgfs_is_match("num_of_ap=", buf);
  791. if (data) {
  792. ret = kstrtou32(data, 10, &value);
  793. if (ret == 0)
  794. mvm->tof_data.range_req.num_of_ap = value;
  795. goto out;
  796. }
  797. data = iwl_dbgfs_is_match("macaddr_template=", buf);
  798. if (data) {
  799. u8 mac[ETH_ALEN];
  800. if (!mac_pton(data, mac)) {
  801. ret = -EINVAL;
  802. goto out;
  803. }
  804. memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
  805. goto out;
  806. }
  807. data = iwl_dbgfs_is_match("macaddr_mask=", buf);
  808. if (data) {
  809. u8 mac[ETH_ALEN];
  810. if (!mac_pton(data, mac)) {
  811. ret = -EINVAL;
  812. goto out;
  813. }
  814. memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
  815. goto out;
  816. }
  817. data = iwl_dbgfs_is_match("ap=", buf);
  818. if (data) {
  819. struct iwl_tof_range_req_ap_entry ap = {};
  820. int size = sizeof(struct iwl_tof_range_req_ap_entry);
  821. u16 burst_period;
  822. u8 *mac = ap.bssid;
  823. unsigned int i;
  824. if (sscanf(data, "%u %hhd %hhd %hhd"
  825. "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
  826. "%hhd %hhd %hd"
  827. "%hhd %hhd %d"
  828. "%hhx %hhd %hhd %hhd",
  829. &i, &ap.channel_num, &ap.bandwidth,
  830. &ap.ctrl_ch_position,
  831. mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
  832. &ap.measure_type, &ap.num_of_bursts,
  833. &burst_period,
  834. &ap.samples_per_burst, &ap.retries_per_sample,
  835. &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
  836. &ap.enable_dyn_ack, &ap.rssi) != 20) {
  837. ret = -EINVAL;
  838. goto out;
  839. }
  840. if (i >= IWL_MVM_TOF_MAX_APS) {
  841. IWL_ERR(mvm, "Invalid AP index %d\n", i);
  842. ret = -EINVAL;
  843. goto out;
  844. }
  845. ap.burst_period = cpu_to_le16(burst_period);
  846. memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
  847. goto out;
  848. }
  849. data = iwl_dbgfs_is_match("send_range_request=", buf);
  850. if (data) {
  851. ret = kstrtou32(data, 10, &value);
  852. if (ret == 0 && value)
  853. ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
  854. goto out;
  855. }
  856. ret = -EINVAL;
  857. out:
  858. mutex_unlock(&mvm->mutex);
  859. return ret ?: count;
  860. }
  861. static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
  862. char __user *user_buf,
  863. size_t count, loff_t *ppos)
  864. {
  865. struct ieee80211_vif *vif = file->private_data;
  866. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  867. struct iwl_mvm *mvm = mvmvif->mvm;
  868. char buf[512];
  869. int pos = 0;
  870. const size_t bufsz = sizeof(buf);
  871. struct iwl_tof_range_req_cmd *cmd;
  872. int i;
  873. cmd = &mvm->tof_data.range_req;
  874. mutex_lock(&mvm->mutex);
  875. pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
  876. cmd->request_id);
  877. pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
  878. cmd->initiator);
  879. pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
  880. cmd->one_sided_los_disable);
  881. pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
  882. cmd->req_timeout);
  883. pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
  884. cmd->report_policy);
  885. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
  886. cmd->macaddr_random);
  887. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
  888. cmd->macaddr_template);
  889. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
  890. cmd->macaddr_mask);
  891. pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
  892. cmd->num_of_ap);
  893. for (i = 0; i < cmd->num_of_ap; i++) {
  894. struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
  895. pos += scnprintf(buf + pos, bufsz - pos,
  896. "ap %.2d: channel_num=%hhd bw=%hhd"
  897. " control=%hhd bssid=%pM type=%hhd"
  898. " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
  899. " retries=%hhd tsf_delta=%d"
  900. " tsf_delta_direction=%hhd location_req=0x%hhx "
  901. " asap=%hhd enable=%hhd rssi=%hhd\n",
  902. i, ap->channel_num, ap->bandwidth,
  903. ap->ctrl_ch_position, ap->bssid,
  904. ap->measure_type, ap->num_of_bursts,
  905. ap->burst_period, ap->samples_per_burst,
  906. ap->retries_per_sample, ap->tsf_delta,
  907. ap->tsf_delta_direction,
  908. ap->location_req, ap->asap_mode,
  909. ap->enable_dyn_ack, ap->rssi);
  910. }
  911. mutex_unlock(&mvm->mutex);
  912. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  913. }
  914. static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
  915. char *buf,
  916. size_t count, loff_t *ppos)
  917. {
  918. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  919. struct iwl_mvm *mvm = mvmvif->mvm;
  920. u32 value;
  921. int ret = 0;
  922. char *data;
  923. mutex_lock(&mvm->mutex);
  924. data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
  925. if (data) {
  926. ret = kstrtou32(data, 10, &value);
  927. if (ret == 0)
  928. mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
  929. cpu_to_le16(value);
  930. goto out;
  931. }
  932. data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
  933. if (data) {
  934. ret = kstrtou32(data, 10, &value);
  935. if (ret == 0)
  936. mvm->tof_data.range_req_ext.min_delta_ftm = value;
  937. goto out;
  938. }
  939. data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
  940. if (data) {
  941. ret = kstrtou32(data, 10, &value);
  942. if (ret == 0)
  943. mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
  944. value;
  945. goto out;
  946. }
  947. data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
  948. if (data) {
  949. ret = kstrtou32(data, 10, &value);
  950. if (ret == 0)
  951. mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
  952. value;
  953. goto out;
  954. }
  955. data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
  956. if (data) {
  957. ret = kstrtou32(data, 10, &value);
  958. if (ret == 0)
  959. mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
  960. value;
  961. goto out;
  962. }
  963. data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
  964. if (data) {
  965. ret = kstrtou32(data, 10, &value);
  966. if (ret == 0 && value)
  967. ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
  968. goto out;
  969. }
  970. ret = -EINVAL;
  971. out:
  972. mutex_unlock(&mvm->mutex);
  973. return ret ?: count;
  974. }
  975. static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
  976. char __user *user_buf,
  977. size_t count, loff_t *ppos)
  978. {
  979. struct ieee80211_vif *vif = file->private_data;
  980. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  981. struct iwl_mvm *mvm = mvmvif->mvm;
  982. char buf[256];
  983. int pos = 0;
  984. const size_t bufsz = sizeof(buf);
  985. struct iwl_tof_range_req_ext_cmd *cmd;
  986. cmd = &mvm->tof_data.range_req_ext;
  987. mutex_lock(&mvm->mutex);
  988. pos += scnprintf(buf + pos, bufsz - pos,
  989. "tsf_timer_offset_msec = %hd\n",
  990. cmd->tsf_timer_offset_msec);
  991. pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
  992. cmd->min_delta_ftm);
  993. pos += scnprintf(buf + pos, bufsz - pos,
  994. "ftm_format_and_bw20M = %hhd\n",
  995. cmd->ftm_format_and_bw20M);
  996. pos += scnprintf(buf + pos, bufsz - pos,
  997. "ftm_format_and_bw40M = %hhd\n",
  998. cmd->ftm_format_and_bw40M);
  999. pos += scnprintf(buf + pos, bufsz - pos,
  1000. "ftm_format_and_bw80M = %hhd\n",
  1001. cmd->ftm_format_and_bw80M);
  1002. mutex_unlock(&mvm->mutex);
  1003. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1004. }
  1005. static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
  1006. char *buf,
  1007. size_t count, loff_t *ppos)
  1008. {
  1009. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1010. struct iwl_mvm *mvm = mvmvif->mvm;
  1011. u32 value;
  1012. int abort_id, ret = 0;
  1013. char *data;
  1014. mutex_lock(&mvm->mutex);
  1015. data = iwl_dbgfs_is_match("abort_id=", buf);
  1016. if (data) {
  1017. ret = kstrtou32(data, 10, &value);
  1018. if (ret == 0)
  1019. mvm->tof_data.last_abort_id = value;
  1020. goto out;
  1021. }
  1022. data = iwl_dbgfs_is_match("send_range_abort=", buf);
  1023. if (data) {
  1024. ret = kstrtou32(data, 10, &value);
  1025. if (ret == 0 && value) {
  1026. abort_id = mvm->tof_data.last_abort_id;
  1027. ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
  1028. goto out;
  1029. }
  1030. }
  1031. out:
  1032. mutex_unlock(&mvm->mutex);
  1033. return ret ?: count;
  1034. }
  1035. static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
  1036. char __user *user_buf,
  1037. size_t count, loff_t *ppos)
  1038. {
  1039. struct ieee80211_vif *vif = file->private_data;
  1040. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1041. struct iwl_mvm *mvm = mvmvif->mvm;
  1042. char buf[32];
  1043. int pos = 0;
  1044. const size_t bufsz = sizeof(buf);
  1045. int last_abort_id;
  1046. mutex_lock(&mvm->mutex);
  1047. last_abort_id = mvm->tof_data.last_abort_id;
  1048. mutex_unlock(&mvm->mutex);
  1049. pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
  1050. last_abort_id);
  1051. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1052. }
  1053. static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
  1054. char __user *user_buf,
  1055. size_t count, loff_t *ppos)
  1056. {
  1057. struct ieee80211_vif *vif = file->private_data;
  1058. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1059. struct iwl_mvm *mvm = mvmvif->mvm;
  1060. char *buf;
  1061. int pos = 0;
  1062. const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
  1063. struct iwl_tof_range_rsp_ntfy *cmd;
  1064. int i, ret;
  1065. buf = kzalloc(bufsz, GFP_KERNEL);
  1066. if (!buf)
  1067. return -ENOMEM;
  1068. mutex_lock(&mvm->mutex);
  1069. cmd = &mvm->tof_data.range_resp;
  1070. pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
  1071. cmd->request_id);
  1072. pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
  1073. cmd->request_status);
  1074. pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
  1075. cmd->last_in_batch);
  1076. pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
  1077. cmd->num_of_aps);
  1078. for (i = 0; i < cmd->num_of_aps; i++) {
  1079. struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
  1080. pos += scnprintf(buf + pos, bufsz - pos,
  1081. "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
  1082. " rtt=%d rtt_var=%d rtt_spread=%d"
  1083. " rssi=%hhd rssi_spread=%hhd"
  1084. " range=%d range_var=%d"
  1085. " time_stamp=%d\n",
  1086. i, ap->bssid, ap->measure_status,
  1087. ap->measure_bw,
  1088. ap->rtt, ap->rtt_variance, ap->rtt_spread,
  1089. ap->rssi, ap->rssi_spread, ap->range,
  1090. ap->range_variance, ap->timestamp);
  1091. }
  1092. mutex_unlock(&mvm->mutex);
  1093. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1094. kfree(buf);
  1095. return ret;
  1096. }
  1097. static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
  1098. size_t count, loff_t *ppos)
  1099. {
  1100. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1101. struct iwl_mvm *mvm = mvmvif->mvm;
  1102. u8 value;
  1103. int ret;
  1104. ret = kstrtou8(buf, 0, &value);
  1105. if (ret)
  1106. return ret;
  1107. if (value > 1)
  1108. return -EINVAL;
  1109. mutex_lock(&mvm->mutex);
  1110. iwl_mvm_update_low_latency(mvm, vif, value);
  1111. mutex_unlock(&mvm->mutex);
  1112. return count;
  1113. }
  1114. static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
  1115. char __user *user_buf,
  1116. size_t count, loff_t *ppos)
  1117. {
  1118. struct ieee80211_vif *vif = file->private_data;
  1119. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1120. char buf[2];
  1121. buf[0] = mvmvif->low_latency ? '1' : '0';
  1122. buf[1] = '\n';
  1123. return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
  1124. }
  1125. static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
  1126. char __user *user_buf,
  1127. size_t count, loff_t *ppos)
  1128. {
  1129. struct ieee80211_vif *vif = file->private_data;
  1130. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1131. char buf[20];
  1132. int len;
  1133. len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
  1134. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1135. }
  1136. static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
  1137. char *buf, size_t count,
  1138. loff_t *ppos)
  1139. {
  1140. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1141. struct iwl_mvm *mvm = mvmvif->mvm;
  1142. bool ret;
  1143. mutex_lock(&mvm->mutex);
  1144. ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
  1145. mutex_unlock(&mvm->mutex);
  1146. return ret ? count : -EINVAL;
  1147. }
  1148. static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
  1149. size_t count, loff_t *ppos)
  1150. {
  1151. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1152. struct iwl_mvm *mvm = mvmvif->mvm;
  1153. struct ieee80211_chanctx_conf *chanctx_conf;
  1154. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1155. u16 value;
  1156. int ret;
  1157. ret = kstrtou16(buf, 0, &value);
  1158. if (ret)
  1159. return ret;
  1160. mutex_lock(&mvm->mutex);
  1161. rcu_read_lock();
  1162. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  1163. /* make sure the channel context is assigned */
  1164. if (!chanctx_conf) {
  1165. rcu_read_unlock();
  1166. mutex_unlock(&mvm->mutex);
  1167. return -EINVAL;
  1168. }
  1169. phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
  1170. rcu_read_unlock();
  1171. mvm->dbgfs_rx_phyinfo = value;
  1172. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
  1173. chanctx_conf->rx_chains_static,
  1174. chanctx_conf->rx_chains_dynamic);
  1175. mutex_unlock(&mvm->mutex);
  1176. return ret ?: count;
  1177. }
  1178. static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
  1179. char __user *user_buf,
  1180. size_t count, loff_t *ppos)
  1181. {
  1182. struct ieee80211_vif *vif = file->private_data;
  1183. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1184. char buf[8];
  1185. snprintf(buf, sizeof(buf), "0x%04x\n", mvmvif->mvm->dbgfs_rx_phyinfo);
  1186. return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
  1187. }
  1188. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1189. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
  1190. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1191. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
  1192. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  1193. if (!debugfs_create_file(#name, mode, parent, vif, \
  1194. &iwl_dbgfs_##name##_ops)) \
  1195. goto err; \
  1196. } while (0)
  1197. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  1198. MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
  1199. MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
  1200. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
  1201. MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
  1202. MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
  1203. MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
  1204. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
  1205. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
  1206. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
  1207. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
  1208. MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
  1209. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
  1210. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1211. {
  1212. struct dentry *dbgfs_dir = vif->debugfs_dir;
  1213. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1214. char buf[100];
  1215. /*
  1216. * Check if debugfs directory already exist before creating it.
  1217. * This may happen when, for example, resetting hw or suspend-resume
  1218. */
  1219. if (!dbgfs_dir || mvmvif->dbgfs_dir)
  1220. return;
  1221. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  1222. if (!mvmvif->dbgfs_dir) {
  1223. IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
  1224. dbgfs_dir->d_name.name);
  1225. return;
  1226. }
  1227. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
  1228. ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
  1229. (vif->type == NL80211_IFTYPE_STATION && vif->p2p &&
  1230. mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)))
  1231. MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
  1232. S_IRUSR);
  1233. MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, S_IRUSR);
  1234. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, S_IRUSR);
  1235. MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir,
  1236. S_IRUSR | S_IWUSR);
  1237. MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir,
  1238. S_IRUSR | S_IWUSR);
  1239. MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir,
  1240. S_IRUSR | S_IWUSR);
  1241. if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  1242. mvmvif == mvm->bf_allowed_vif)
  1243. MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
  1244. S_IRUSR | S_IWUSR);
  1245. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
  1246. !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
  1247. if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
  1248. MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
  1249. mvmvif->dbgfs_dir,
  1250. S_IRUSR | S_IWUSR);
  1251. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
  1252. S_IRUSR | S_IWUSR);
  1253. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
  1254. S_IRUSR | S_IWUSR);
  1255. MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
  1256. S_IRUSR | S_IWUSR);
  1257. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
  1258. S_IRUSR | S_IWUSR);
  1259. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
  1260. S_IRUSR);
  1261. }
  1262. /*
  1263. * Create symlink for convenience pointing to interface specific
  1264. * debugfs entries for the driver. For example, under
  1265. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  1266. * find
  1267. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  1268. */
  1269. snprintf(buf, 100, "../../../%s/%s/%s/%s",
  1270. dbgfs_dir->d_parent->d_parent->d_name.name,
  1271. dbgfs_dir->d_parent->d_name.name,
  1272. dbgfs_dir->d_name.name,
  1273. mvmvif->dbgfs_dir->d_name.name);
  1274. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  1275. mvm->debugfs_dir, buf);
  1276. if (!mvmvif->dbgfs_slink)
  1277. IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
  1278. dbgfs_dir->d_name.name);
  1279. return;
  1280. err:
  1281. IWL_ERR(mvm, "Can't create debugfs entity\n");
  1282. }
  1283. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1284. {
  1285. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1286. debugfs_remove(mvmvif->dbgfs_slink);
  1287. mvmvif->dbgfs_slink = NULL;
  1288. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  1289. mvmvif->dbgfs_dir = NULL;
  1290. }