debugfs-vif.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  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. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include "mvm.h"
  68. #include "fw/api/tof.h"
  69. #include "debugfs.h"
  70. static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
  71. struct ieee80211_vif *vif,
  72. enum iwl_dbgfs_pm_mask param, int val)
  73. {
  74. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  75. struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
  76. dbgfs_pm->mask |= param;
  77. switch (param) {
  78. case MVM_DEBUGFS_PM_KEEP_ALIVE: {
  79. int dtimper = vif->bss_conf.dtim_period ?: 1;
  80. int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
  81. IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
  82. if (val * MSEC_PER_SEC < 3 * dtimper_msec)
  83. IWL_WARN(mvm,
  84. "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
  85. val * MSEC_PER_SEC, 3 * dtimper_msec);
  86. dbgfs_pm->keep_alive_seconds = val;
  87. break;
  88. }
  89. case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
  90. IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
  91. val ? "enabled" : "disabled");
  92. dbgfs_pm->skip_over_dtim = val;
  93. break;
  94. case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
  95. IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
  96. dbgfs_pm->skip_dtim_periods = val;
  97. break;
  98. case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
  99. IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
  100. dbgfs_pm->rx_data_timeout = val;
  101. break;
  102. case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
  103. IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
  104. dbgfs_pm->tx_data_timeout = val;
  105. break;
  106. case MVM_DEBUGFS_PM_LPRX_ENA:
  107. IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
  108. dbgfs_pm->lprx_ena = val;
  109. break;
  110. case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
  111. IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
  112. dbgfs_pm->lprx_rssi_threshold = val;
  113. break;
  114. case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
  115. IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
  116. dbgfs_pm->snooze_ena = val;
  117. break;
  118. case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
  119. IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
  120. dbgfs_pm->uapsd_misbehaving = val;
  121. break;
  122. case MVM_DEBUGFS_PM_USE_PS_POLL:
  123. IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
  124. dbgfs_pm->use_ps_poll = val;
  125. break;
  126. }
  127. }
  128. static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
  129. size_t count, loff_t *ppos)
  130. {
  131. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  132. struct iwl_mvm *mvm = mvmvif->mvm;
  133. enum iwl_dbgfs_pm_mask param;
  134. int val, ret;
  135. if (!strncmp("keep_alive=", buf, 11)) {
  136. if (sscanf(buf + 11, "%d", &val) != 1)
  137. return -EINVAL;
  138. param = MVM_DEBUGFS_PM_KEEP_ALIVE;
  139. } else if (!strncmp("skip_over_dtim=", buf, 15)) {
  140. if (sscanf(buf + 15, "%d", &val) != 1)
  141. return -EINVAL;
  142. param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
  143. } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
  144. if (sscanf(buf + 18, "%d", &val) != 1)
  145. return -EINVAL;
  146. param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
  147. } else if (!strncmp("rx_data_timeout=", buf, 16)) {
  148. if (sscanf(buf + 16, "%d", &val) != 1)
  149. return -EINVAL;
  150. param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
  151. } else if (!strncmp("tx_data_timeout=", buf, 16)) {
  152. if (sscanf(buf + 16, "%d", &val) != 1)
  153. return -EINVAL;
  154. param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
  155. } else if (!strncmp("lprx=", buf, 5)) {
  156. if (sscanf(buf + 5, "%d", &val) != 1)
  157. return -EINVAL;
  158. param = MVM_DEBUGFS_PM_LPRX_ENA;
  159. } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
  160. if (sscanf(buf + 20, "%d", &val) != 1)
  161. return -EINVAL;
  162. if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
  163. POWER_LPRX_RSSI_THRESHOLD_MIN)
  164. return -EINVAL;
  165. param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
  166. } else if (!strncmp("snooze_enable=", buf, 14)) {
  167. if (sscanf(buf + 14, "%d", &val) != 1)
  168. return -EINVAL;
  169. param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
  170. } else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
  171. if (sscanf(buf + 18, "%d", &val) != 1)
  172. return -EINVAL;
  173. param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
  174. } else if (!strncmp("use_ps_poll=", buf, 12)) {
  175. if (sscanf(buf + 12, "%d", &val) != 1)
  176. return -EINVAL;
  177. param = MVM_DEBUGFS_PM_USE_PS_POLL;
  178. } else {
  179. return -EINVAL;
  180. }
  181. mutex_lock(&mvm->mutex);
  182. iwl_dbgfs_update_pm(mvm, vif, param, val);
  183. ret = iwl_mvm_power_update_mac(mvm);
  184. mutex_unlock(&mvm->mutex);
  185. return ret ?: count;
  186. }
  187. static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
  188. char __user *user_buf,
  189. size_t count, loff_t *ppos)
  190. {
  191. struct ieee80211_vif *vif = file->private_data;
  192. char buf[64];
  193. int bufsz = sizeof(buf);
  194. int pos;
  195. pos = scnprintf(buf, bufsz, "bss limit = %d\n",
  196. vif->bss_conf.txpower);
  197. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  198. }
  199. static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
  200. char __user *user_buf,
  201. size_t count, loff_t *ppos)
  202. {
  203. struct ieee80211_vif *vif = file->private_data;
  204. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  205. struct iwl_mvm *mvm = mvmvif->mvm;
  206. char buf[512];
  207. int bufsz = sizeof(buf);
  208. int pos;
  209. pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
  210. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  211. }
  212. static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
  213. char __user *user_buf,
  214. size_t count, loff_t *ppos)
  215. {
  216. struct ieee80211_vif *vif = file->private_data;
  217. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  218. struct iwl_mvm *mvm = mvmvif->mvm;
  219. u8 ap_sta_id;
  220. struct ieee80211_chanctx_conf *chanctx_conf;
  221. char buf[512];
  222. int bufsz = sizeof(buf);
  223. int pos = 0;
  224. int i;
  225. mutex_lock(&mvm->mutex);
  226. ap_sta_id = mvmvif->ap_sta_id;
  227. switch (ieee80211_vif_type_p2p(vif)) {
  228. case NL80211_IFTYPE_ADHOC:
  229. pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
  230. break;
  231. case NL80211_IFTYPE_STATION:
  232. pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
  233. break;
  234. case NL80211_IFTYPE_AP:
  235. pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
  236. break;
  237. case NL80211_IFTYPE_P2P_CLIENT:
  238. pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
  239. break;
  240. case NL80211_IFTYPE_P2P_GO:
  241. pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
  242. break;
  243. case NL80211_IFTYPE_P2P_DEVICE:
  244. pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
  245. break;
  246. default:
  247. break;
  248. }
  249. pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
  250. mvmvif->id, mvmvif->color);
  251. pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
  252. vif->bss_conf.bssid);
  253. pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
  254. for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
  255. pos += scnprintf(buf+pos, bufsz-pos,
  256. "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
  257. i, mvmvif->queue_params[i].txop,
  258. mvmvif->queue_params[i].cw_min,
  259. mvmvif->queue_params[i].cw_max,
  260. mvmvif->queue_params[i].aifs,
  261. mvmvif->queue_params[i].uapsd);
  262. if (vif->type == NL80211_IFTYPE_STATION &&
  263. ap_sta_id != IWL_MVM_INVALID_STA) {
  264. struct iwl_mvm_sta *mvm_sta;
  265. mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
  266. if (mvm_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_os_device_timediff_read(struct file *file,
  470. char __user *user_buf,
  471. size_t count, loff_t *ppos)
  472. {
  473. struct ieee80211_vif *vif = file->private_data;
  474. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  475. struct iwl_mvm *mvm = mvmvif->mvm;
  476. u32 curr_gp2;
  477. u64 curr_os;
  478. s64 diff;
  479. char buf[64];
  480. const size_t bufsz = sizeof(buf);
  481. int pos = 0;
  482. iwl_mvm_get_sync_time(mvm, &curr_gp2, &curr_os);
  483. do_div(curr_os, NSEC_PER_USEC);
  484. diff = curr_os - curr_gp2;
  485. pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
  486. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  487. }
  488. static ssize_t iwl_dbgfs_tof_enable_write(struct ieee80211_vif *vif,
  489. char *buf,
  490. size_t count, loff_t *ppos)
  491. {
  492. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  493. struct iwl_mvm *mvm = mvmvif->mvm;
  494. u32 value;
  495. int ret = -EINVAL;
  496. char *data;
  497. mutex_lock(&mvm->mutex);
  498. data = iwl_dbgfs_is_match("tof_disabled=", buf);
  499. if (data) {
  500. ret = kstrtou32(data, 10, &value);
  501. if (ret == 0)
  502. mvm->tof_data.tof_cfg.tof_disabled = value;
  503. goto out;
  504. }
  505. data = iwl_dbgfs_is_match("one_sided_disabled=", buf);
  506. if (data) {
  507. ret = kstrtou32(data, 10, &value);
  508. if (ret == 0)
  509. mvm->tof_data.tof_cfg.one_sided_disabled = value;
  510. goto out;
  511. }
  512. data = iwl_dbgfs_is_match("is_debug_mode=", buf);
  513. if (data) {
  514. ret = kstrtou32(data, 10, &value);
  515. if (ret == 0)
  516. mvm->tof_data.tof_cfg.is_debug_mode = value;
  517. goto out;
  518. }
  519. data = iwl_dbgfs_is_match("is_buf=", buf);
  520. if (data) {
  521. ret = kstrtou32(data, 10, &value);
  522. if (ret == 0)
  523. mvm->tof_data.tof_cfg.is_buf_required = value;
  524. goto out;
  525. }
  526. data = iwl_dbgfs_is_match("send_tof_cfg=", buf);
  527. if (data) {
  528. ret = kstrtou32(data, 10, &value);
  529. if (ret == 0 && value) {
  530. ret = iwl_mvm_tof_config_cmd(mvm);
  531. goto out;
  532. }
  533. }
  534. out:
  535. mutex_unlock(&mvm->mutex);
  536. return ret ?: count;
  537. }
  538. static ssize_t iwl_dbgfs_tof_enable_read(struct file *file,
  539. char __user *user_buf,
  540. size_t count, loff_t *ppos)
  541. {
  542. struct ieee80211_vif *vif = file->private_data;
  543. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  544. struct iwl_mvm *mvm = mvmvif->mvm;
  545. char buf[256];
  546. int pos = 0;
  547. const size_t bufsz = sizeof(buf);
  548. struct iwl_tof_config_cmd *cmd;
  549. cmd = &mvm->tof_data.tof_cfg;
  550. mutex_lock(&mvm->mutex);
  551. pos += scnprintf(buf + pos, bufsz - pos, "tof_disabled = %d\n",
  552. cmd->tof_disabled);
  553. pos += scnprintf(buf + pos, bufsz - pos, "one_sided_disabled = %d\n",
  554. cmd->one_sided_disabled);
  555. pos += scnprintf(buf + pos, bufsz - pos, "is_debug_mode = %d\n",
  556. cmd->is_debug_mode);
  557. pos += scnprintf(buf + pos, bufsz - pos, "is_buf_required = %d\n",
  558. cmd->is_buf_required);
  559. mutex_unlock(&mvm->mutex);
  560. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  561. }
  562. static ssize_t iwl_dbgfs_tof_responder_params_write(struct ieee80211_vif *vif,
  563. char *buf,
  564. size_t count, loff_t *ppos)
  565. {
  566. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  567. struct iwl_mvm *mvm = mvmvif->mvm;
  568. u32 value;
  569. int ret = 0;
  570. char *data;
  571. mutex_lock(&mvm->mutex);
  572. data = iwl_dbgfs_is_match("burst_period=", buf);
  573. if (data) {
  574. ret = kstrtou32(data, 10, &value);
  575. if (!ret)
  576. mvm->tof_data.responder_cfg.burst_period =
  577. cpu_to_le16(value);
  578. goto out;
  579. }
  580. data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
  581. if (data) {
  582. ret = kstrtou32(data, 10, &value);
  583. if (ret == 0)
  584. mvm->tof_data.responder_cfg.min_delta_ftm = value;
  585. goto out;
  586. }
  587. data = iwl_dbgfs_is_match("burst_duration=", buf);
  588. if (data) {
  589. ret = kstrtou32(data, 10, &value);
  590. if (ret == 0)
  591. mvm->tof_data.responder_cfg.burst_duration = value;
  592. goto out;
  593. }
  594. data = iwl_dbgfs_is_match("num_of_burst_exp=", buf);
  595. if (data) {
  596. ret = kstrtou32(data, 10, &value);
  597. if (ret == 0)
  598. mvm->tof_data.responder_cfg.num_of_burst_exp = value;
  599. goto out;
  600. }
  601. data = iwl_dbgfs_is_match("abort_responder=", buf);
  602. if (data) {
  603. ret = kstrtou32(data, 10, &value);
  604. if (ret == 0)
  605. mvm->tof_data.responder_cfg.abort_responder = value;
  606. goto out;
  607. }
  608. data = iwl_dbgfs_is_match("get_ch_est=", buf);
  609. if (data) {
  610. ret = kstrtou32(data, 10, &value);
  611. if (ret == 0)
  612. mvm->tof_data.responder_cfg.get_ch_est = value;
  613. goto out;
  614. }
  615. data = iwl_dbgfs_is_match("recv_sta_req_params=", buf);
  616. if (data) {
  617. ret = kstrtou32(data, 10, &value);
  618. if (ret == 0)
  619. mvm->tof_data.responder_cfg.recv_sta_req_params = value;
  620. goto out;
  621. }
  622. data = iwl_dbgfs_is_match("channel_num=", buf);
  623. if (data) {
  624. ret = kstrtou32(data, 10, &value);
  625. if (ret == 0)
  626. mvm->tof_data.responder_cfg.channel_num = value;
  627. goto out;
  628. }
  629. data = iwl_dbgfs_is_match("bandwidth=", buf);
  630. if (data) {
  631. ret = kstrtou32(data, 10, &value);
  632. if (ret == 0)
  633. mvm->tof_data.responder_cfg.bandwidth = value;
  634. goto out;
  635. }
  636. data = iwl_dbgfs_is_match("rate=", buf);
  637. if (data) {
  638. ret = kstrtou32(data, 10, &value);
  639. if (ret == 0)
  640. mvm->tof_data.responder_cfg.rate = value;
  641. goto out;
  642. }
  643. data = iwl_dbgfs_is_match("bssid=", buf);
  644. if (data) {
  645. u8 *mac = mvm->tof_data.responder_cfg.bssid;
  646. if (!mac_pton(data, mac)) {
  647. ret = -EINVAL;
  648. goto out;
  649. }
  650. }
  651. data = iwl_dbgfs_is_match("tsf_timer_offset_msecs=", buf);
  652. if (data) {
  653. ret = kstrtou32(data, 10, &value);
  654. if (ret == 0)
  655. mvm->tof_data.responder_cfg.tsf_timer_offset_msecs =
  656. cpu_to_le16(value);
  657. goto out;
  658. }
  659. data = iwl_dbgfs_is_match("toa_offset=", buf);
  660. if (data) {
  661. ret = kstrtou32(data, 10, &value);
  662. if (ret == 0)
  663. mvm->tof_data.responder_cfg.toa_offset =
  664. cpu_to_le16(value);
  665. goto out;
  666. }
  667. data = iwl_dbgfs_is_match("center_freq=", buf);
  668. if (data) {
  669. struct iwl_tof_responder_config_cmd *cmd =
  670. &mvm->tof_data.responder_cfg;
  671. ret = kstrtou32(data, 10, &value);
  672. if (ret == 0 && value) {
  673. enum nl80211_band band = (cmd->channel_num <= 14) ?
  674. NL80211_BAND_2GHZ :
  675. NL80211_BAND_5GHZ;
  676. struct ieee80211_channel chn = {
  677. .band = band,
  678. .center_freq = ieee80211_channel_to_frequency(
  679. cmd->channel_num, band),
  680. };
  681. struct cfg80211_chan_def chandef = {
  682. .chan = &chn,
  683. .center_freq1 =
  684. ieee80211_channel_to_frequency(value,
  685. band),
  686. };
  687. cmd->ctrl_ch_position = iwl_mvm_get_ctrl_pos(&chandef);
  688. }
  689. goto out;
  690. }
  691. data = iwl_dbgfs_is_match("ftm_per_burst=", buf);
  692. if (data) {
  693. ret = kstrtou32(data, 10, &value);
  694. if (ret == 0)
  695. mvm->tof_data.responder_cfg.ftm_per_burst = value;
  696. goto out;
  697. }
  698. data = iwl_dbgfs_is_match("ftm_resp_ts_avail=", buf);
  699. if (data) {
  700. ret = kstrtou32(data, 10, &value);
  701. if (ret == 0)
  702. mvm->tof_data.responder_cfg.ftm_resp_ts_avail = value;
  703. goto out;
  704. }
  705. data = iwl_dbgfs_is_match("asap_mode=", buf);
  706. if (data) {
  707. ret = kstrtou32(data, 10, &value);
  708. if (ret == 0)
  709. mvm->tof_data.responder_cfg.asap_mode = value;
  710. goto out;
  711. }
  712. data = iwl_dbgfs_is_match("send_responder_cfg=", buf);
  713. if (data) {
  714. ret = kstrtou32(data, 10, &value);
  715. if (ret == 0 && value) {
  716. ret = iwl_mvm_tof_responder_cmd(mvm, vif);
  717. goto out;
  718. }
  719. }
  720. out:
  721. mutex_unlock(&mvm->mutex);
  722. return ret ?: count;
  723. }
  724. static ssize_t iwl_dbgfs_tof_responder_params_read(struct file *file,
  725. char __user *user_buf,
  726. size_t count, loff_t *ppos)
  727. {
  728. struct ieee80211_vif *vif = file->private_data;
  729. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  730. struct iwl_mvm *mvm = mvmvif->mvm;
  731. char buf[256];
  732. int pos = 0;
  733. const size_t bufsz = sizeof(buf);
  734. struct iwl_tof_responder_config_cmd *cmd;
  735. cmd = &mvm->tof_data.responder_cfg;
  736. mutex_lock(&mvm->mutex);
  737. pos += scnprintf(buf + pos, bufsz - pos, "burst_period = %d\n",
  738. le16_to_cpu(cmd->burst_period));
  739. pos += scnprintf(buf + pos, bufsz - pos, "burst_duration = %d\n",
  740. cmd->burst_duration);
  741. pos += scnprintf(buf + pos, bufsz - pos, "bandwidth = %d\n",
  742. cmd->bandwidth);
  743. pos += scnprintf(buf + pos, bufsz - pos, "channel_num = %d\n",
  744. cmd->channel_num);
  745. pos += scnprintf(buf + pos, bufsz - pos, "ctrl_ch_position = 0x%x\n",
  746. cmd->ctrl_ch_position);
  747. pos += scnprintf(buf + pos, bufsz - pos, "bssid = %pM\n",
  748. cmd->bssid);
  749. pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %d\n",
  750. cmd->min_delta_ftm);
  751. pos += scnprintf(buf + pos, bufsz - pos, "num_of_burst_exp = %d\n",
  752. cmd->num_of_burst_exp);
  753. pos += scnprintf(buf + pos, bufsz - pos, "rate = %d\n", cmd->rate);
  754. pos += scnprintf(buf + pos, bufsz - pos, "abort_responder = %d\n",
  755. cmd->abort_responder);
  756. pos += scnprintf(buf + pos, bufsz - pos, "get_ch_est = %d\n",
  757. cmd->get_ch_est);
  758. pos += scnprintf(buf + pos, bufsz - pos, "recv_sta_req_params = %d\n",
  759. cmd->recv_sta_req_params);
  760. pos += scnprintf(buf + pos, bufsz - pos, "ftm_per_burst = %d\n",
  761. cmd->ftm_per_burst);
  762. pos += scnprintf(buf + pos, bufsz - pos, "ftm_resp_ts_avail = %d\n",
  763. cmd->ftm_resp_ts_avail);
  764. pos += scnprintf(buf + pos, bufsz - pos, "asap_mode = %d\n",
  765. cmd->asap_mode);
  766. pos += scnprintf(buf + pos, bufsz - pos,
  767. "tsf_timer_offset_msecs = %d\n",
  768. le16_to_cpu(cmd->tsf_timer_offset_msecs));
  769. pos += scnprintf(buf + pos, bufsz - pos, "toa_offset = %d\n",
  770. le16_to_cpu(cmd->toa_offset));
  771. mutex_unlock(&mvm->mutex);
  772. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  773. }
  774. static ssize_t iwl_dbgfs_tof_range_request_write(struct ieee80211_vif *vif,
  775. char *buf, size_t count,
  776. loff_t *ppos)
  777. {
  778. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  779. struct iwl_mvm *mvm = mvmvif->mvm;
  780. u32 value;
  781. int ret = 0;
  782. char *data;
  783. mutex_lock(&mvm->mutex);
  784. data = iwl_dbgfs_is_match("request_id=", buf);
  785. if (data) {
  786. ret = kstrtou32(data, 10, &value);
  787. if (ret == 0)
  788. mvm->tof_data.range_req.request_id = value;
  789. goto out;
  790. }
  791. data = iwl_dbgfs_is_match("initiator=", buf);
  792. if (data) {
  793. ret = kstrtou32(data, 10, &value);
  794. if (ret == 0)
  795. mvm->tof_data.range_req.initiator = value;
  796. goto out;
  797. }
  798. data = iwl_dbgfs_is_match("one_sided_los_disable=", buf);
  799. if (data) {
  800. ret = kstrtou32(data, 10, &value);
  801. if (ret == 0)
  802. mvm->tof_data.range_req.one_sided_los_disable = value;
  803. goto out;
  804. }
  805. data = iwl_dbgfs_is_match("req_timeout=", buf);
  806. if (data) {
  807. ret = kstrtou32(data, 10, &value);
  808. if (ret == 0)
  809. mvm->tof_data.range_req.req_timeout = value;
  810. goto out;
  811. }
  812. data = iwl_dbgfs_is_match("report_policy=", buf);
  813. if (data) {
  814. ret = kstrtou32(data, 10, &value);
  815. if (ret == 0)
  816. mvm->tof_data.range_req.report_policy = value;
  817. goto out;
  818. }
  819. data = iwl_dbgfs_is_match("macaddr_random=", buf);
  820. if (data) {
  821. ret = kstrtou32(data, 10, &value);
  822. if (ret == 0)
  823. mvm->tof_data.range_req.macaddr_random = value;
  824. goto out;
  825. }
  826. data = iwl_dbgfs_is_match("num_of_ap=", buf);
  827. if (data) {
  828. ret = kstrtou32(data, 10, &value);
  829. if (ret == 0)
  830. mvm->tof_data.range_req.num_of_ap = value;
  831. goto out;
  832. }
  833. data = iwl_dbgfs_is_match("macaddr_template=", buf);
  834. if (data) {
  835. u8 mac[ETH_ALEN];
  836. if (!mac_pton(data, mac)) {
  837. ret = -EINVAL;
  838. goto out;
  839. }
  840. memcpy(mvm->tof_data.range_req.macaddr_template, mac, ETH_ALEN);
  841. goto out;
  842. }
  843. data = iwl_dbgfs_is_match("macaddr_mask=", buf);
  844. if (data) {
  845. u8 mac[ETH_ALEN];
  846. if (!mac_pton(data, mac)) {
  847. ret = -EINVAL;
  848. goto out;
  849. }
  850. memcpy(mvm->tof_data.range_req.macaddr_mask, mac, ETH_ALEN);
  851. goto out;
  852. }
  853. data = iwl_dbgfs_is_match("ap=", buf);
  854. if (data) {
  855. struct iwl_tof_range_req_ap_entry ap = {};
  856. int size = sizeof(struct iwl_tof_range_req_ap_entry);
  857. u16 burst_period;
  858. u8 *mac = ap.bssid;
  859. unsigned int i;
  860. if (sscanf(data, "%u %hhd %hhd %hhd"
  861. "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
  862. "%hhd %hhd %hd"
  863. "%hhd %hhd %d"
  864. "%hhx %hhd %hhd %hhd",
  865. &i, &ap.channel_num, &ap.bandwidth,
  866. &ap.ctrl_ch_position,
  867. mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5,
  868. &ap.measure_type, &ap.num_of_bursts,
  869. &burst_period,
  870. &ap.samples_per_burst, &ap.retries_per_sample,
  871. &ap.tsf_delta, &ap.location_req, &ap.asap_mode,
  872. &ap.enable_dyn_ack, &ap.rssi) != 20) {
  873. ret = -EINVAL;
  874. goto out;
  875. }
  876. if (i >= IWL_MVM_TOF_MAX_APS) {
  877. IWL_ERR(mvm, "Invalid AP index %d\n", i);
  878. ret = -EINVAL;
  879. goto out;
  880. }
  881. ap.burst_period = cpu_to_le16(burst_period);
  882. memcpy(&mvm->tof_data.range_req.ap[i], &ap, size);
  883. goto out;
  884. }
  885. data = iwl_dbgfs_is_match("send_range_request=", buf);
  886. if (data) {
  887. ret = kstrtou32(data, 10, &value);
  888. if (ret == 0 && value)
  889. ret = iwl_mvm_tof_range_request_cmd(mvm, vif);
  890. goto out;
  891. }
  892. ret = -EINVAL;
  893. out:
  894. mutex_unlock(&mvm->mutex);
  895. return ret ?: count;
  896. }
  897. static ssize_t iwl_dbgfs_tof_range_request_read(struct file *file,
  898. char __user *user_buf,
  899. size_t count, loff_t *ppos)
  900. {
  901. struct ieee80211_vif *vif = file->private_data;
  902. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  903. struct iwl_mvm *mvm = mvmvif->mvm;
  904. char buf[512];
  905. int pos = 0;
  906. const size_t bufsz = sizeof(buf);
  907. struct iwl_tof_range_req_cmd *cmd;
  908. int i;
  909. cmd = &mvm->tof_data.range_req;
  910. mutex_lock(&mvm->mutex);
  911. pos += scnprintf(buf + pos, bufsz - pos, "request_id= %d\n",
  912. cmd->request_id);
  913. pos += scnprintf(buf + pos, bufsz - pos, "initiator= %d\n",
  914. cmd->initiator);
  915. pos += scnprintf(buf + pos, bufsz - pos, "one_sided_los_disable = %d\n",
  916. cmd->one_sided_los_disable);
  917. pos += scnprintf(buf + pos, bufsz - pos, "req_timeout= %d\n",
  918. cmd->req_timeout);
  919. pos += scnprintf(buf + pos, bufsz - pos, "report_policy= %d\n",
  920. cmd->report_policy);
  921. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_random= %d\n",
  922. cmd->macaddr_random);
  923. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_template= %pM\n",
  924. cmd->macaddr_template);
  925. pos += scnprintf(buf + pos, bufsz - pos, "macaddr_mask= %pM\n",
  926. cmd->macaddr_mask);
  927. pos += scnprintf(buf + pos, bufsz - pos, "num_of_ap= %d\n",
  928. cmd->num_of_ap);
  929. for (i = 0; i < cmd->num_of_ap; i++) {
  930. struct iwl_tof_range_req_ap_entry *ap = &cmd->ap[i];
  931. pos += scnprintf(buf + pos, bufsz - pos,
  932. "ap %.2d: channel_num=%hhd bw=%hhd"
  933. " control=%hhd bssid=%pM type=%hhd"
  934. " num_of_bursts=%hhd burst_period=%hd ftm=%hhd"
  935. " retries=%hhd tsf_delta=%d"
  936. " tsf_delta_direction=%hhd location_req=0x%hhx "
  937. " asap=%hhd enable=%hhd rssi=%hhd\n",
  938. i, ap->channel_num, ap->bandwidth,
  939. ap->ctrl_ch_position, ap->bssid,
  940. ap->measure_type, ap->num_of_bursts,
  941. ap->burst_period, ap->samples_per_burst,
  942. ap->retries_per_sample, ap->tsf_delta,
  943. ap->tsf_delta_direction,
  944. ap->location_req, ap->asap_mode,
  945. ap->enable_dyn_ack, ap->rssi);
  946. }
  947. mutex_unlock(&mvm->mutex);
  948. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  949. }
  950. static ssize_t iwl_dbgfs_tof_range_req_ext_write(struct ieee80211_vif *vif,
  951. char *buf,
  952. size_t count, loff_t *ppos)
  953. {
  954. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  955. struct iwl_mvm *mvm = mvmvif->mvm;
  956. u32 value;
  957. int ret = 0;
  958. char *data;
  959. mutex_lock(&mvm->mutex);
  960. data = iwl_dbgfs_is_match("tsf_timer_offset_msec=", buf);
  961. if (data) {
  962. ret = kstrtou32(data, 10, &value);
  963. if (ret == 0)
  964. mvm->tof_data.range_req_ext.tsf_timer_offset_msec =
  965. cpu_to_le16(value);
  966. goto out;
  967. }
  968. data = iwl_dbgfs_is_match("min_delta_ftm=", buf);
  969. if (data) {
  970. ret = kstrtou32(data, 10, &value);
  971. if (ret == 0)
  972. mvm->tof_data.range_req_ext.min_delta_ftm = value;
  973. goto out;
  974. }
  975. data = iwl_dbgfs_is_match("ftm_format_and_bw20M=", buf);
  976. if (data) {
  977. ret = kstrtou32(data, 10, &value);
  978. if (ret == 0)
  979. mvm->tof_data.range_req_ext.ftm_format_and_bw20M =
  980. value;
  981. goto out;
  982. }
  983. data = iwl_dbgfs_is_match("ftm_format_and_bw40M=", buf);
  984. if (data) {
  985. ret = kstrtou32(data, 10, &value);
  986. if (ret == 0)
  987. mvm->tof_data.range_req_ext.ftm_format_and_bw40M =
  988. value;
  989. goto out;
  990. }
  991. data = iwl_dbgfs_is_match("ftm_format_and_bw80M=", buf);
  992. if (data) {
  993. ret = kstrtou32(data, 10, &value);
  994. if (ret == 0)
  995. mvm->tof_data.range_req_ext.ftm_format_and_bw80M =
  996. value;
  997. goto out;
  998. }
  999. data = iwl_dbgfs_is_match("send_range_req_ext=", buf);
  1000. if (data) {
  1001. ret = kstrtou32(data, 10, &value);
  1002. if (ret == 0 && value)
  1003. ret = iwl_mvm_tof_range_request_ext_cmd(mvm, vif);
  1004. goto out;
  1005. }
  1006. ret = -EINVAL;
  1007. out:
  1008. mutex_unlock(&mvm->mutex);
  1009. return ret ?: count;
  1010. }
  1011. static ssize_t iwl_dbgfs_tof_range_req_ext_read(struct file *file,
  1012. char __user *user_buf,
  1013. size_t count, loff_t *ppos)
  1014. {
  1015. struct ieee80211_vif *vif = file->private_data;
  1016. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1017. struct iwl_mvm *mvm = mvmvif->mvm;
  1018. char buf[256];
  1019. int pos = 0;
  1020. const size_t bufsz = sizeof(buf);
  1021. struct iwl_tof_range_req_ext_cmd *cmd;
  1022. cmd = &mvm->tof_data.range_req_ext;
  1023. mutex_lock(&mvm->mutex);
  1024. pos += scnprintf(buf + pos, bufsz - pos,
  1025. "tsf_timer_offset_msec = %hd\n",
  1026. cmd->tsf_timer_offset_msec);
  1027. pos += scnprintf(buf + pos, bufsz - pos, "min_delta_ftm = %hhd\n",
  1028. cmd->min_delta_ftm);
  1029. pos += scnprintf(buf + pos, bufsz - pos,
  1030. "ftm_format_and_bw20M = %hhd\n",
  1031. cmd->ftm_format_and_bw20M);
  1032. pos += scnprintf(buf + pos, bufsz - pos,
  1033. "ftm_format_and_bw40M = %hhd\n",
  1034. cmd->ftm_format_and_bw40M);
  1035. pos += scnprintf(buf + pos, bufsz - pos,
  1036. "ftm_format_and_bw80M = %hhd\n",
  1037. cmd->ftm_format_and_bw80M);
  1038. mutex_unlock(&mvm->mutex);
  1039. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1040. }
  1041. static ssize_t iwl_dbgfs_tof_range_abort_write(struct ieee80211_vif *vif,
  1042. char *buf,
  1043. size_t count, loff_t *ppos)
  1044. {
  1045. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1046. struct iwl_mvm *mvm = mvmvif->mvm;
  1047. u32 value;
  1048. int abort_id, ret = 0;
  1049. char *data;
  1050. mutex_lock(&mvm->mutex);
  1051. data = iwl_dbgfs_is_match("abort_id=", buf);
  1052. if (data) {
  1053. ret = kstrtou32(data, 10, &value);
  1054. if (ret == 0)
  1055. mvm->tof_data.last_abort_id = value;
  1056. goto out;
  1057. }
  1058. data = iwl_dbgfs_is_match("send_range_abort=", buf);
  1059. if (data) {
  1060. ret = kstrtou32(data, 10, &value);
  1061. if (ret == 0 && value) {
  1062. abort_id = mvm->tof_data.last_abort_id;
  1063. ret = iwl_mvm_tof_range_abort_cmd(mvm, abort_id);
  1064. goto out;
  1065. }
  1066. }
  1067. out:
  1068. mutex_unlock(&mvm->mutex);
  1069. return ret ?: count;
  1070. }
  1071. static ssize_t iwl_dbgfs_tof_range_abort_read(struct file *file,
  1072. char __user *user_buf,
  1073. size_t count, loff_t *ppos)
  1074. {
  1075. struct ieee80211_vif *vif = file->private_data;
  1076. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1077. struct iwl_mvm *mvm = mvmvif->mvm;
  1078. char buf[32];
  1079. int pos = 0;
  1080. const size_t bufsz = sizeof(buf);
  1081. int last_abort_id;
  1082. mutex_lock(&mvm->mutex);
  1083. last_abort_id = mvm->tof_data.last_abort_id;
  1084. mutex_unlock(&mvm->mutex);
  1085. pos += scnprintf(buf + pos, bufsz - pos, "last_abort_id = %d\n",
  1086. last_abort_id);
  1087. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1088. }
  1089. static ssize_t iwl_dbgfs_tof_range_response_read(struct file *file,
  1090. char __user *user_buf,
  1091. size_t count, loff_t *ppos)
  1092. {
  1093. struct ieee80211_vif *vif = file->private_data;
  1094. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1095. struct iwl_mvm *mvm = mvmvif->mvm;
  1096. char *buf;
  1097. int pos = 0;
  1098. const size_t bufsz = sizeof(struct iwl_tof_range_rsp_ntfy) + 256;
  1099. struct iwl_tof_range_rsp_ntfy *cmd;
  1100. int i, ret;
  1101. buf = kzalloc(bufsz, GFP_KERNEL);
  1102. if (!buf)
  1103. return -ENOMEM;
  1104. mutex_lock(&mvm->mutex);
  1105. cmd = &mvm->tof_data.range_resp;
  1106. pos += scnprintf(buf + pos, bufsz - pos, "request_id = %d\n",
  1107. cmd->request_id);
  1108. pos += scnprintf(buf + pos, bufsz - pos, "status = %d\n",
  1109. cmd->request_status);
  1110. pos += scnprintf(buf + pos, bufsz - pos, "last_in_batch = %d\n",
  1111. cmd->last_in_batch);
  1112. pos += scnprintf(buf + pos, bufsz - pos, "num_of_aps = %d\n",
  1113. cmd->num_of_aps);
  1114. for (i = 0; i < cmd->num_of_aps; i++) {
  1115. struct iwl_tof_range_rsp_ap_entry_ntfy *ap = &cmd->ap[i];
  1116. pos += scnprintf(buf + pos, bufsz - pos,
  1117. "ap %.2d: bssid=%pM status=%hhd bw=%hhd"
  1118. " rtt=%d rtt_var=%d rtt_spread=%d"
  1119. " rssi=%hhd rssi_spread=%hhd"
  1120. " range=%d range_var=%d"
  1121. " time_stamp=%d\n",
  1122. i, ap->bssid, ap->measure_status,
  1123. ap->measure_bw,
  1124. ap->rtt, ap->rtt_variance, ap->rtt_spread,
  1125. ap->rssi, ap->rssi_spread, ap->range,
  1126. ap->range_variance, ap->timestamp);
  1127. }
  1128. mutex_unlock(&mvm->mutex);
  1129. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1130. kfree(buf);
  1131. return ret;
  1132. }
  1133. static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
  1134. size_t count, loff_t *ppos)
  1135. {
  1136. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1137. struct iwl_mvm *mvm = mvmvif->mvm;
  1138. bool prev;
  1139. u8 value;
  1140. int ret;
  1141. ret = kstrtou8(buf, 0, &value);
  1142. if (ret)
  1143. return ret;
  1144. if (value > 1)
  1145. return -EINVAL;
  1146. mutex_lock(&mvm->mutex);
  1147. prev = iwl_mvm_vif_low_latency(mvmvif);
  1148. mvmvif->low_latency_dbgfs = value;
  1149. iwl_mvm_update_low_latency(mvm, vif, prev);
  1150. mutex_unlock(&mvm->mutex);
  1151. return count;
  1152. }
  1153. static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
  1154. char __user *user_buf,
  1155. size_t count, loff_t *ppos)
  1156. {
  1157. struct ieee80211_vif *vif = file->private_data;
  1158. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1159. char buf[30] = {};
  1160. int len;
  1161. len = scnprintf(buf, sizeof(buf) - 1,
  1162. "traffic=%d\ndbgfs=%d\nvcmd=%d\n",
  1163. mvmvif->low_latency_traffic,
  1164. mvmvif->low_latency_dbgfs,
  1165. mvmvif->low_latency_vcmd);
  1166. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1167. }
  1168. static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
  1169. char __user *user_buf,
  1170. size_t count, loff_t *ppos)
  1171. {
  1172. struct ieee80211_vif *vif = file->private_data;
  1173. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1174. char buf[20];
  1175. int len;
  1176. len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
  1177. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1178. }
  1179. static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
  1180. char *buf, size_t count,
  1181. loff_t *ppos)
  1182. {
  1183. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1184. struct iwl_mvm *mvm = mvmvif->mvm;
  1185. bool ret;
  1186. mutex_lock(&mvm->mutex);
  1187. ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
  1188. mutex_unlock(&mvm->mutex);
  1189. return ret ? count : -EINVAL;
  1190. }
  1191. static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
  1192. size_t count, loff_t *ppos)
  1193. {
  1194. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1195. struct iwl_mvm *mvm = mvmvif->mvm;
  1196. struct ieee80211_chanctx_conf *chanctx_conf;
  1197. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1198. u16 value;
  1199. int ret;
  1200. ret = kstrtou16(buf, 0, &value);
  1201. if (ret)
  1202. return ret;
  1203. mutex_lock(&mvm->mutex);
  1204. rcu_read_lock();
  1205. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  1206. /* make sure the channel context is assigned */
  1207. if (!chanctx_conf) {
  1208. rcu_read_unlock();
  1209. mutex_unlock(&mvm->mutex);
  1210. return -EINVAL;
  1211. }
  1212. phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
  1213. rcu_read_unlock();
  1214. mvm->dbgfs_rx_phyinfo = value;
  1215. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
  1216. chanctx_conf->rx_chains_static,
  1217. chanctx_conf->rx_chains_dynamic);
  1218. mutex_unlock(&mvm->mutex);
  1219. return ret ?: count;
  1220. }
  1221. static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
  1222. char __user *user_buf,
  1223. size_t count, loff_t *ppos)
  1224. {
  1225. struct ieee80211_vif *vif = file->private_data;
  1226. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1227. char buf[8];
  1228. int len;
  1229. len = scnprintf(buf, sizeof(buf), "0x%04x\n",
  1230. mvmvif->mvm->dbgfs_rx_phyinfo);
  1231. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1232. }
  1233. static void iwl_dbgfs_quota_check(void *data, u8 *mac,
  1234. struct ieee80211_vif *vif)
  1235. {
  1236. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1237. int *ret = data;
  1238. if (mvmvif->dbgfs_quota_min)
  1239. *ret = -EINVAL;
  1240. }
  1241. static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
  1242. size_t count, loff_t *ppos)
  1243. {
  1244. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1245. struct iwl_mvm *mvm = mvmvif->mvm;
  1246. u16 value;
  1247. int ret;
  1248. ret = kstrtou16(buf, 0, &value);
  1249. if (ret)
  1250. return ret;
  1251. if (value > 95)
  1252. return -EINVAL;
  1253. mutex_lock(&mvm->mutex);
  1254. mvmvif->dbgfs_quota_min = 0;
  1255. ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1256. iwl_dbgfs_quota_check, &ret);
  1257. if (ret == 0) {
  1258. mvmvif->dbgfs_quota_min = value;
  1259. iwl_mvm_update_quotas(mvm, false, NULL);
  1260. }
  1261. mutex_unlock(&mvm->mutex);
  1262. return ret ?: count;
  1263. }
  1264. static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
  1265. char __user *user_buf,
  1266. size_t count, loff_t *ppos)
  1267. {
  1268. struct ieee80211_vif *vif = file->private_data;
  1269. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1270. char buf[10];
  1271. int len;
  1272. len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
  1273. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1274. }
  1275. static const char * const chanwidths[] = {
  1276. [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
  1277. [NL80211_CHAN_WIDTH_20] = "ht20",
  1278. [NL80211_CHAN_WIDTH_40] = "ht40",
  1279. [NL80211_CHAN_WIDTH_80] = "vht80",
  1280. [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
  1281. [NL80211_CHAN_WIDTH_160] = "vht160",
  1282. };
  1283. static bool iwl_mvm_lqm_notif_wait(struct iwl_notif_wait_data *notif_wait,
  1284. struct iwl_rx_packet *pkt, void *data)
  1285. {
  1286. struct ieee80211_vif *vif = data;
  1287. struct iwl_mvm *mvm =
  1288. container_of(notif_wait, struct iwl_mvm, notif_wait);
  1289. struct iwl_link_qual_msrmnt_notif *report = (void *)pkt->data;
  1290. u32 num_of_stations = le32_to_cpu(report->number_of_stations);
  1291. int i;
  1292. IWL_INFO(mvm, "LQM report:\n");
  1293. IWL_INFO(mvm, "\tstatus: %d\n", report->status);
  1294. IWL_INFO(mvm, "\tmacID: %d\n", le32_to_cpu(report->mac_id));
  1295. IWL_INFO(mvm, "\ttx_frame_dropped: %d\n",
  1296. le32_to_cpu(report->tx_frame_dropped));
  1297. IWL_INFO(mvm, "\ttime_in_measurement_window: %d us\n",
  1298. le32_to_cpu(report->time_in_measurement_window));
  1299. IWL_INFO(mvm, "\ttotal_air_time_other_stations: %d\n",
  1300. le32_to_cpu(report->total_air_time_other_stations));
  1301. IWL_INFO(mvm, "\tchannel_freq: %d\n",
  1302. vif->bss_conf.chandef.center_freq1);
  1303. IWL_INFO(mvm, "\tchannel_width: %s\n",
  1304. chanwidths[vif->bss_conf.chandef.width]);
  1305. IWL_INFO(mvm, "\tnumber_of_stations: %d\n", num_of_stations);
  1306. for (i = 0; i < num_of_stations; i++)
  1307. IWL_INFO(mvm, "\t\tsta[%d]: %d\n", i,
  1308. report->frequent_stations_air_time[i]);
  1309. return true;
  1310. }
  1311. static ssize_t iwl_dbgfs_lqm_send_cmd_write(struct ieee80211_vif *vif,
  1312. char *buf, size_t count,
  1313. loff_t *ppos)
  1314. {
  1315. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1316. struct iwl_mvm *mvm = mvmvif->mvm;
  1317. struct iwl_notification_wait wait_lqm_notif;
  1318. static u16 lqm_notif[] = {
  1319. WIDE_ID(MAC_CONF_GROUP,
  1320. LINK_QUALITY_MEASUREMENT_COMPLETE_NOTIF)
  1321. };
  1322. int err;
  1323. u32 duration;
  1324. u32 timeout;
  1325. if (sscanf(buf, "%d,%d", &duration, &timeout) != 2)
  1326. return -EINVAL;
  1327. iwl_init_notification_wait(&mvm->notif_wait, &wait_lqm_notif,
  1328. lqm_notif, ARRAY_SIZE(lqm_notif),
  1329. iwl_mvm_lqm_notif_wait, vif);
  1330. mutex_lock(&mvm->mutex);
  1331. err = iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_START_MEASUREMENT,
  1332. duration, timeout);
  1333. mutex_unlock(&mvm->mutex);
  1334. if (err) {
  1335. IWL_ERR(mvm, "Failed to send lqm cmdf(err=%d)\n", err);
  1336. iwl_remove_notification(&mvm->notif_wait, &wait_lqm_notif);
  1337. return err;
  1338. }
  1339. /* wait for 2 * timeout (safety guard) and convert to jiffies*/
  1340. timeout = msecs_to_jiffies((timeout * 2) / 1000);
  1341. err = iwl_wait_notification(&mvm->notif_wait, &wait_lqm_notif,
  1342. timeout);
  1343. if (err)
  1344. IWL_ERR(mvm, "Getting lqm notif timed out\n");
  1345. return count;
  1346. }
  1347. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1348. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
  1349. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1350. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
  1351. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  1352. if (!debugfs_create_file(#name, mode, parent, vif, \
  1353. &iwl_dbgfs_##name##_ops)) \
  1354. goto err; \
  1355. } while (0)
  1356. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  1357. MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
  1358. MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
  1359. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
  1360. MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
  1361. MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
  1362. MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
  1363. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_enable, 32);
  1364. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_request, 512);
  1365. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_req_ext, 32);
  1366. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_range_abort, 32);
  1367. MVM_DEBUGFS_READ_FILE_OPS(tof_range_response);
  1368. MVM_DEBUGFS_READ_WRITE_FILE_OPS(tof_responder_params, 32);
  1369. MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
  1370. MVM_DEBUGFS_WRITE_FILE_OPS(lqm_send_cmd, 64);
  1371. MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
  1372. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1373. {
  1374. struct dentry *dbgfs_dir = vif->debugfs_dir;
  1375. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1376. char buf[100];
  1377. /*
  1378. * Check if debugfs directory already exist before creating it.
  1379. * This may happen when, for example, resetting hw or suspend-resume
  1380. */
  1381. if (!dbgfs_dir || mvmvif->dbgfs_dir)
  1382. return;
  1383. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  1384. if (!mvmvif->dbgfs_dir) {
  1385. IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
  1386. dbgfs_dir);
  1387. return;
  1388. }
  1389. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
  1390. ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
  1391. (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
  1392. MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
  1393. S_IRUSR);
  1394. MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, S_IRUSR);
  1395. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, S_IRUSR);
  1396. MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir,
  1397. S_IRUSR | S_IWUSR);
  1398. MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir,
  1399. S_IRUSR | S_IWUSR);
  1400. MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir,
  1401. S_IRUSR | S_IWUSR);
  1402. MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir,
  1403. S_IRUSR | S_IWUSR);
  1404. MVM_DEBUGFS_ADD_FILE_VIF(lqm_send_cmd, mvmvif->dbgfs_dir, S_IWUSR);
  1405. MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff,
  1406. mvmvif->dbgfs_dir, S_IRUSR);
  1407. if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  1408. mvmvif == mvm->bf_allowed_vif)
  1409. MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
  1410. S_IRUSR | S_IWUSR);
  1411. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT) &&
  1412. !vif->p2p && (vif->type != NL80211_IFTYPE_P2P_DEVICE)) {
  1413. if (IWL_MVM_TOF_IS_RESPONDER && vif->type == NL80211_IFTYPE_AP)
  1414. MVM_DEBUGFS_ADD_FILE_VIF(tof_responder_params,
  1415. mvmvif->dbgfs_dir,
  1416. S_IRUSR | S_IWUSR);
  1417. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_request, mvmvif->dbgfs_dir,
  1418. S_IRUSR | S_IWUSR);
  1419. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_req_ext, mvmvif->dbgfs_dir,
  1420. S_IRUSR | S_IWUSR);
  1421. MVM_DEBUGFS_ADD_FILE_VIF(tof_enable, mvmvif->dbgfs_dir,
  1422. S_IRUSR | S_IWUSR);
  1423. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_abort, mvmvif->dbgfs_dir,
  1424. S_IRUSR | S_IWUSR);
  1425. MVM_DEBUGFS_ADD_FILE_VIF(tof_range_response, mvmvif->dbgfs_dir,
  1426. S_IRUSR);
  1427. }
  1428. /*
  1429. * Create symlink for convenience pointing to interface specific
  1430. * debugfs entries for the driver. For example, under
  1431. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  1432. * find
  1433. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  1434. */
  1435. snprintf(buf, 100, "../../../%pd3/%pd",
  1436. dbgfs_dir,
  1437. mvmvif->dbgfs_dir);
  1438. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  1439. mvm->debugfs_dir, buf);
  1440. if (!mvmvif->dbgfs_slink)
  1441. IWL_ERR(mvm, "Can't create debugfs symbolic link under %pd\n",
  1442. dbgfs_dir);
  1443. return;
  1444. err:
  1445. IWL_ERR(mvm, "Can't create debugfs entity\n");
  1446. }
  1447. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1448. {
  1449. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1450. debugfs_remove(mvmvif->dbgfs_slink);
  1451. mvmvif->dbgfs_slink = NULL;
  1452. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  1453. mvmvif->dbgfs_dir = NULL;
  1454. }