debugfs-vif.c 42 KB

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