debugfs.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940
  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 <linux/vmalloc.h>
  68. #include <linux/ieee80211.h>
  69. #include <linux/netdevice.h>
  70. #include "mvm.h"
  71. #include "sta.h"
  72. #include "iwl-io.h"
  73. #include "debugfs.h"
  74. #include "fw/error-dump.h"
  75. static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
  76. char __user *user_buf,
  77. size_t count, loff_t *ppos)
  78. {
  79. struct iwl_mvm *mvm = file->private_data;
  80. char buf[16];
  81. int pos, budget;
  82. if (!iwl_mvm_is_ctdp_supported(mvm))
  83. return -EOPNOTSUPP;
  84. if (!iwl_mvm_firmware_running(mvm) ||
  85. mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
  86. return -EIO;
  87. mutex_lock(&mvm->mutex);
  88. budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
  89. mutex_unlock(&mvm->mutex);
  90. if (budget < 0)
  91. return budget;
  92. pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
  93. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  94. }
  95. static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
  96. size_t count, loff_t *ppos)
  97. {
  98. int ret;
  99. if (!iwl_mvm_is_ctdp_supported(mvm))
  100. return -EOPNOTSUPP;
  101. if (!iwl_mvm_firmware_running(mvm) ||
  102. mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
  103. return -EIO;
  104. mutex_lock(&mvm->mutex);
  105. ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
  106. mutex_unlock(&mvm->mutex);
  107. return ret ?: count;
  108. }
  109. static ssize_t iwl_dbgfs_force_ctkill_write(struct iwl_mvm *mvm, char *buf,
  110. size_t count, loff_t *ppos)
  111. {
  112. if (!iwl_mvm_firmware_running(mvm) ||
  113. mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
  114. return -EIO;
  115. iwl_mvm_enter_ctkill(mvm);
  116. return count;
  117. }
  118. static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
  119. size_t count, loff_t *ppos)
  120. {
  121. int ret;
  122. u32 flush_arg;
  123. if (!iwl_mvm_firmware_running(mvm) ||
  124. mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
  125. return -EIO;
  126. if (kstrtou32(buf, 0, &flush_arg))
  127. return -EINVAL;
  128. if (iwl_mvm_has_new_tx_api(mvm)) {
  129. IWL_DEBUG_TX_QUEUES(mvm,
  130. "FLUSHING all tids queues on sta_id = %d\n",
  131. flush_arg);
  132. mutex_lock(&mvm->mutex);
  133. ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFF, 0) ? : count;
  134. mutex_unlock(&mvm->mutex);
  135. return ret;
  136. }
  137. IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n",
  138. flush_arg);
  139. mutex_lock(&mvm->mutex);
  140. ret = iwl_mvm_flush_tx_path(mvm, flush_arg, 0) ? : count;
  141. mutex_unlock(&mvm->mutex);
  142. return ret;
  143. }
  144. static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
  145. size_t count, loff_t *ppos)
  146. {
  147. struct iwl_mvm_sta *mvmsta;
  148. int sta_id, drain, ret;
  149. if (!iwl_mvm_firmware_running(mvm) ||
  150. mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
  151. return -EIO;
  152. if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
  153. return -EINVAL;
  154. if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
  155. return -EINVAL;
  156. if (drain < 0 || drain > 1)
  157. return -EINVAL;
  158. mutex_lock(&mvm->mutex);
  159. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  160. if (!mvmsta)
  161. ret = -ENOENT;
  162. else
  163. ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
  164. mutex_unlock(&mvm->mutex);
  165. return ret;
  166. }
  167. static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
  168. size_t count, loff_t *ppos)
  169. {
  170. struct iwl_mvm *mvm = file->private_data;
  171. const struct fw_img *img;
  172. unsigned int ofs, len;
  173. size_t ret;
  174. u8 *ptr;
  175. if (!iwl_mvm_firmware_running(mvm))
  176. return -EINVAL;
  177. /* default is to dump the entire data segment */
  178. img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
  179. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  180. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  181. if (mvm->dbgfs_sram_len) {
  182. ofs = mvm->dbgfs_sram_offset;
  183. len = mvm->dbgfs_sram_len;
  184. }
  185. ptr = kzalloc(len, GFP_KERNEL);
  186. if (!ptr)
  187. return -ENOMEM;
  188. iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
  189. ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
  190. kfree(ptr);
  191. return ret;
  192. }
  193. static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
  194. size_t count, loff_t *ppos)
  195. {
  196. const struct fw_img *img;
  197. u32 offset, len;
  198. u32 img_offset, img_len;
  199. if (!iwl_mvm_firmware_running(mvm))
  200. return -EINVAL;
  201. img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
  202. img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
  203. img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  204. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  205. if ((offset & 0x3) || (len & 0x3))
  206. return -EINVAL;
  207. if (offset + len > img_offset + img_len)
  208. return -EINVAL;
  209. mvm->dbgfs_sram_offset = offset;
  210. mvm->dbgfs_sram_len = len;
  211. } else {
  212. mvm->dbgfs_sram_offset = 0;
  213. mvm->dbgfs_sram_len = 0;
  214. }
  215. return count;
  216. }
  217. static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
  218. char __user *user_buf,
  219. size_t count, loff_t *ppos)
  220. {
  221. struct iwl_mvm *mvm = file->private_data;
  222. char buf[16];
  223. int pos;
  224. if (!mvm->temperature_test)
  225. pos = scnprintf(buf , sizeof(buf), "disabled\n");
  226. else
  227. pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
  228. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  229. }
  230. /*
  231. * Set NIC Temperature
  232. * Cause the driver to ignore the actual NIC temperature reported by the FW
  233. * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
  234. * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
  235. * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
  236. */
  237. static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
  238. char *buf, size_t count,
  239. loff_t *ppos)
  240. {
  241. int temperature;
  242. if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
  243. return -EIO;
  244. if (kstrtoint(buf, 10, &temperature))
  245. return -EINVAL;
  246. /* not a legal temperature */
  247. if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
  248. temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
  249. temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
  250. return -EINVAL;
  251. mutex_lock(&mvm->mutex);
  252. if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
  253. if (!mvm->temperature_test)
  254. goto out;
  255. mvm->temperature_test = false;
  256. /* Since we can't read the temp while awake, just set
  257. * it to zero until we get the next RX stats from the
  258. * firmware.
  259. */
  260. mvm->temperature = 0;
  261. } else {
  262. mvm->temperature_test = true;
  263. mvm->temperature = temperature;
  264. }
  265. IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
  266. mvm->temperature_test ? "En" : "Dis" ,
  267. mvm->temperature);
  268. /* handle the temperature change */
  269. iwl_mvm_tt_handler(mvm);
  270. out:
  271. mutex_unlock(&mvm->mutex);
  272. return count;
  273. }
  274. static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
  275. char __user *user_buf,
  276. size_t count, loff_t *ppos)
  277. {
  278. struct iwl_mvm *mvm = file->private_data;
  279. char buf[16];
  280. int pos, ret;
  281. s32 temp;
  282. if (!iwl_mvm_firmware_running(mvm))
  283. return -EIO;
  284. mutex_lock(&mvm->mutex);
  285. ret = iwl_mvm_get_temp(mvm, &temp);
  286. mutex_unlock(&mvm->mutex);
  287. if (ret)
  288. return -EIO;
  289. pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
  290. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  291. }
  292. #ifdef CONFIG_ACPI
  293. static ssize_t iwl_dbgfs_sar_geo_profile_read(struct file *file,
  294. char __user *user_buf,
  295. size_t count, loff_t *ppos)
  296. {
  297. struct iwl_mvm *mvm = file->private_data;
  298. char buf[256];
  299. int pos = 0;
  300. int bufsz = sizeof(buf);
  301. int tbl_idx;
  302. u8 *value;
  303. if (!iwl_mvm_firmware_running(mvm))
  304. return -EIO;
  305. mutex_lock(&mvm->mutex);
  306. tbl_idx = iwl_mvm_get_sar_geo_profile(mvm);
  307. if (tbl_idx < 0) {
  308. mutex_unlock(&mvm->mutex);
  309. return tbl_idx;
  310. }
  311. if (!tbl_idx) {
  312. pos = scnprintf(buf, bufsz,
  313. "SAR geographic profile disabled\n");
  314. } else {
  315. value = &mvm->geo_profiles[tbl_idx - 1].values[0];
  316. pos += scnprintf(buf + pos, bufsz - pos,
  317. "Use geographic profile %d\n", tbl_idx);
  318. pos += scnprintf(buf + pos, bufsz - pos,
  319. "2.4GHz:\n\tChain A offset: %hhd dBm\n\tChain B offset: %hhd dBm\n\tmax tx power: %hhd dBm\n",
  320. value[1], value[2], value[0]);
  321. pos += scnprintf(buf + pos, bufsz - pos,
  322. "5.2GHz:\n\tChain A offset: %hhd dBm\n\tChain B offset: %hhd dBm\n\tmax tx power: %hhd dBm\n",
  323. value[4], value[5], value[3]);
  324. }
  325. mutex_unlock(&mvm->mutex);
  326. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  327. }
  328. #endif
  329. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  330. size_t count, loff_t *ppos)
  331. {
  332. struct iwl_mvm *mvm = file->private_data;
  333. struct ieee80211_sta *sta;
  334. char buf[400];
  335. int i, pos = 0, bufsz = sizeof(buf);
  336. mutex_lock(&mvm->mutex);
  337. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
  338. pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
  339. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  340. lockdep_is_held(&mvm->mutex));
  341. if (!sta)
  342. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  343. else if (IS_ERR(sta))
  344. pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
  345. PTR_ERR(sta));
  346. else
  347. pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
  348. sta->addr);
  349. }
  350. mutex_unlock(&mvm->mutex);
  351. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  352. }
  353. static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
  354. char __user *user_buf,
  355. size_t count, loff_t *ppos)
  356. {
  357. struct iwl_mvm *mvm = file->private_data;
  358. char buf[64];
  359. int bufsz = sizeof(buf);
  360. int pos = 0;
  361. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
  362. mvm->disable_power_off);
  363. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
  364. mvm->disable_power_off_d3);
  365. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  366. }
  367. static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
  368. size_t count, loff_t *ppos)
  369. {
  370. int ret, val;
  371. if (!iwl_mvm_firmware_running(mvm))
  372. return -EIO;
  373. if (!strncmp("disable_power_off_d0=", buf, 21)) {
  374. if (sscanf(buf + 21, "%d", &val) != 1)
  375. return -EINVAL;
  376. mvm->disable_power_off = val;
  377. } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
  378. if (sscanf(buf + 21, "%d", &val) != 1)
  379. return -EINVAL;
  380. mvm->disable_power_off_d3 = val;
  381. } else {
  382. return -EINVAL;
  383. }
  384. mutex_lock(&mvm->mutex);
  385. ret = iwl_mvm_power_update_device(mvm);
  386. mutex_unlock(&mvm->mutex);
  387. return ret ?: count;
  388. }
  389. static
  390. int iwl_mvm_coex_dump_mbox(struct iwl_mvm *mvm,
  391. struct iwl_bt_coex_profile_notif *notif, char *buf,
  392. int pos, int bufsz)
  393. {
  394. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  395. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  396. BT_MBOX_PRINT(0, LE_PROF1, false);
  397. BT_MBOX_PRINT(0, LE_PROF2, false);
  398. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  399. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  400. BT_MBOX_PRINT(0, INBAND_S, false);
  401. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  402. BT_MBOX_PRINT(0, LE_SCAN, false);
  403. BT_MBOX_PRINT(0, LE_ADV, false);
  404. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  405. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  406. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  407. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  408. BT_MBOX_PRINT(1, IP_SR, false);
  409. BT_MBOX_PRINT(1, LE_MSTR, false);
  410. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  411. BT_MBOX_PRINT(1, MSG_TYPE, false);
  412. BT_MBOX_PRINT(1, SSN, true);
  413. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  414. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  415. BT_MBOX_PRINT(2, PAG, false);
  416. BT_MBOX_PRINT(2, INQUIRY, false);
  417. BT_MBOX_PRINT(2, CONN, false);
  418. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  419. BT_MBOX_PRINT(2, DISC, false);
  420. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  421. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  422. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  423. BT_MBOX_PRINT(2, SCO_DURATION, true);
  424. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  425. BT_MBOX_PRINT(3, SCO_STATE, false);
  426. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  427. BT_MBOX_PRINT(3, A2DP_STATE, false);
  428. BT_MBOX_PRINT(3, A2DP_SRC, false);
  429. BT_MBOX_PRINT(3, ACL_STATE, false);
  430. BT_MBOX_PRINT(3, MSTR_STATE, false);
  431. BT_MBOX_PRINT(3, OBX_STATE, false);
  432. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  433. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  434. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  435. BT_MBOX_PRINT(3, INBAND_P, false);
  436. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  437. BT_MBOX_PRINT(3, SSN_2, false);
  438. BT_MBOX_PRINT(3, UPDATE_REQUEST, !iwl_mvm_has_new_ats_coex_api(mvm));
  439. if (iwl_mvm_has_new_ats_coex_api(mvm)) {
  440. BT_MBOX_PRINT(4, ATS_BT_INTERVAL, false);
  441. BT_MBOX_PRINT(4, ATS_BT_ACTIVE_MAX_TH, true);
  442. }
  443. return pos;
  444. }
  445. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  446. size_t count, loff_t *ppos)
  447. {
  448. struct iwl_mvm *mvm = file->private_data;
  449. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  450. char *buf;
  451. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  452. buf = kmalloc(bufsz, GFP_KERNEL);
  453. if (!buf)
  454. return -ENOMEM;
  455. mutex_lock(&mvm->mutex);
  456. pos += iwl_mvm_coex_dump_mbox(mvm, notif, buf, pos, bufsz);
  457. pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
  458. notif->bt_ci_compliance);
  459. pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
  460. le32_to_cpu(notif->primary_ch_lut));
  461. pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
  462. le32_to_cpu(notif->secondary_ch_lut));
  463. pos += scnprintf(buf + pos,
  464. bufsz - pos, "bt_activity_grading = %d\n",
  465. le32_to_cpu(notif->bt_activity_grading));
  466. pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
  467. notif->rrc_status & 0xF);
  468. pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
  469. notif->ttc_status & 0xF);
  470. pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
  471. IWL_MVM_BT_COEX_SYNC2SCO);
  472. pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
  473. IWL_MVM_BT_COEX_MPLUT);
  474. mutex_unlock(&mvm->mutex);
  475. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  476. kfree(buf);
  477. return ret;
  478. }
  479. #undef BT_MBOX_PRINT
  480. static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
  481. size_t count, loff_t *ppos)
  482. {
  483. struct iwl_mvm *mvm = file->private_data;
  484. struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
  485. char buf[256];
  486. int bufsz = sizeof(buf);
  487. int pos = 0;
  488. mutex_lock(&mvm->mutex);
  489. pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
  490. pos += scnprintf(buf + pos, bufsz - pos,
  491. "\tPrimary Channel Bitmap 0x%016llx\n",
  492. le64_to_cpu(cmd->bt_primary_ci));
  493. pos += scnprintf(buf + pos, bufsz - pos,
  494. "\tSecondary Channel Bitmap 0x%016llx\n",
  495. le64_to_cpu(cmd->bt_secondary_ci));
  496. mutex_unlock(&mvm->mutex);
  497. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  498. }
  499. static ssize_t
  500. iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
  501. size_t count, loff_t *ppos)
  502. {
  503. u32 bt_tx_prio;
  504. if (sscanf(buf, "%u", &bt_tx_prio) != 1)
  505. return -EINVAL;
  506. if (bt_tx_prio > 4)
  507. return -EINVAL;
  508. mvm->bt_tx_prio = bt_tx_prio;
  509. return count;
  510. }
  511. static ssize_t
  512. iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
  513. size_t count, loff_t *ppos)
  514. {
  515. static const char * const modes_str[BT_FORCE_ANT_MAX] = {
  516. [BT_FORCE_ANT_DIS] = "dis",
  517. [BT_FORCE_ANT_AUTO] = "auto",
  518. [BT_FORCE_ANT_BT] = "bt",
  519. [BT_FORCE_ANT_WIFI] = "wifi",
  520. };
  521. int ret, bt_force_ant_mode;
  522. for (bt_force_ant_mode = 0;
  523. bt_force_ant_mode < ARRAY_SIZE(modes_str);
  524. bt_force_ant_mode++) {
  525. if (!strcmp(buf, modes_str[bt_force_ant_mode]))
  526. break;
  527. }
  528. if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
  529. return -EINVAL;
  530. ret = 0;
  531. mutex_lock(&mvm->mutex);
  532. if (mvm->bt_force_ant_mode == bt_force_ant_mode)
  533. goto out;
  534. mvm->bt_force_ant_mode = bt_force_ant_mode;
  535. IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
  536. modes_str[mvm->bt_force_ant_mode]);
  537. if (iwl_mvm_firmware_running(mvm))
  538. ret = iwl_mvm_send_bt_init_conf(mvm);
  539. else
  540. ret = 0;
  541. out:
  542. mutex_unlock(&mvm->mutex);
  543. return ret ?: count;
  544. }
  545. #define PRINT_STATS_LE32(_struct, _memb) \
  546. pos += scnprintf(buf + pos, bufsz - pos, \
  547. fmt_table, #_memb, \
  548. le32_to_cpu(_struct->_memb))
  549. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  550. char __user *user_buf, size_t count,
  551. loff_t *ppos)
  552. {
  553. struct iwl_mvm *mvm = file->private_data;
  554. static const char *fmt_table = "\t%-30s %10u\n";
  555. static const char *fmt_header = "%-32s\n";
  556. int pos = 0;
  557. char *buf;
  558. int ret;
  559. size_t bufsz;
  560. if (iwl_mvm_has_new_rx_stats_api(mvm))
  561. bufsz = ((sizeof(struct mvm_statistics_rx) /
  562. sizeof(__le32)) * 43) + (4 * 33) + 1;
  563. else
  564. /* 43 = size of each data line; 33 = size of each header */
  565. bufsz = ((sizeof(struct mvm_statistics_rx_v3) /
  566. sizeof(__le32)) * 43) + (4 * 33) + 1;
  567. buf = kzalloc(bufsz, GFP_KERNEL);
  568. if (!buf)
  569. return -ENOMEM;
  570. mutex_lock(&mvm->mutex);
  571. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  572. "Statistics_Rx - OFDM");
  573. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  574. struct mvm_statistics_rx_phy_v2 *ofdm = &mvm->rx_stats_v3.ofdm;
  575. PRINT_STATS_LE32(ofdm, ina_cnt);
  576. PRINT_STATS_LE32(ofdm, fina_cnt);
  577. PRINT_STATS_LE32(ofdm, plcp_err);
  578. PRINT_STATS_LE32(ofdm, crc32_err);
  579. PRINT_STATS_LE32(ofdm, overrun_err);
  580. PRINT_STATS_LE32(ofdm, early_overrun_err);
  581. PRINT_STATS_LE32(ofdm, crc32_good);
  582. PRINT_STATS_LE32(ofdm, false_alarm_cnt);
  583. PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
  584. PRINT_STATS_LE32(ofdm, sfd_timeout);
  585. PRINT_STATS_LE32(ofdm, fina_timeout);
  586. PRINT_STATS_LE32(ofdm, unresponded_rts);
  587. PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
  588. PRINT_STATS_LE32(ofdm, sent_ack_cnt);
  589. PRINT_STATS_LE32(ofdm, sent_cts_cnt);
  590. PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
  591. PRINT_STATS_LE32(ofdm, dsp_self_kill);
  592. PRINT_STATS_LE32(ofdm, mh_format_err);
  593. PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
  594. PRINT_STATS_LE32(ofdm, reserved);
  595. } else {
  596. struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm;
  597. PRINT_STATS_LE32(ofdm, unresponded_rts);
  598. PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
  599. PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
  600. PRINT_STATS_LE32(ofdm, dsp_self_kill);
  601. PRINT_STATS_LE32(ofdm, reserved);
  602. }
  603. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  604. "Statistics_Rx - CCK");
  605. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  606. struct mvm_statistics_rx_phy_v2 *cck = &mvm->rx_stats_v3.cck;
  607. PRINT_STATS_LE32(cck, ina_cnt);
  608. PRINT_STATS_LE32(cck, fina_cnt);
  609. PRINT_STATS_LE32(cck, plcp_err);
  610. PRINT_STATS_LE32(cck, crc32_err);
  611. PRINT_STATS_LE32(cck, overrun_err);
  612. PRINT_STATS_LE32(cck, early_overrun_err);
  613. PRINT_STATS_LE32(cck, crc32_good);
  614. PRINT_STATS_LE32(cck, false_alarm_cnt);
  615. PRINT_STATS_LE32(cck, fina_sync_err_cnt);
  616. PRINT_STATS_LE32(cck, sfd_timeout);
  617. PRINT_STATS_LE32(cck, fina_timeout);
  618. PRINT_STATS_LE32(cck, unresponded_rts);
  619. PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
  620. PRINT_STATS_LE32(cck, sent_ack_cnt);
  621. PRINT_STATS_LE32(cck, sent_cts_cnt);
  622. PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
  623. PRINT_STATS_LE32(cck, dsp_self_kill);
  624. PRINT_STATS_LE32(cck, mh_format_err);
  625. PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
  626. PRINT_STATS_LE32(cck, reserved);
  627. } else {
  628. struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck;
  629. PRINT_STATS_LE32(cck, unresponded_rts);
  630. PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
  631. PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
  632. PRINT_STATS_LE32(cck, dsp_self_kill);
  633. PRINT_STATS_LE32(cck, reserved);
  634. }
  635. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  636. "Statistics_Rx - GENERAL");
  637. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  638. struct mvm_statistics_rx_non_phy_v3 *general =
  639. &mvm->rx_stats_v3.general;
  640. PRINT_STATS_LE32(general, bogus_cts);
  641. PRINT_STATS_LE32(general, bogus_ack);
  642. PRINT_STATS_LE32(general, non_bssid_frames);
  643. PRINT_STATS_LE32(general, filtered_frames);
  644. PRINT_STATS_LE32(general, non_channel_beacons);
  645. PRINT_STATS_LE32(general, channel_beacons);
  646. PRINT_STATS_LE32(general, num_missed_bcon);
  647. PRINT_STATS_LE32(general, adc_rx_saturation_time);
  648. PRINT_STATS_LE32(general, ina_detection_search_time);
  649. PRINT_STATS_LE32(general, beacon_silence_rssi_a);
  650. PRINT_STATS_LE32(general, beacon_silence_rssi_b);
  651. PRINT_STATS_LE32(general, beacon_silence_rssi_c);
  652. PRINT_STATS_LE32(general, interference_data_flag);
  653. PRINT_STATS_LE32(general, channel_load);
  654. PRINT_STATS_LE32(general, dsp_false_alarms);
  655. PRINT_STATS_LE32(general, beacon_rssi_a);
  656. PRINT_STATS_LE32(general, beacon_rssi_b);
  657. PRINT_STATS_LE32(general, beacon_rssi_c);
  658. PRINT_STATS_LE32(general, beacon_energy_a);
  659. PRINT_STATS_LE32(general, beacon_energy_b);
  660. PRINT_STATS_LE32(general, beacon_energy_c);
  661. PRINT_STATS_LE32(general, num_bt_kills);
  662. PRINT_STATS_LE32(general, mac_id);
  663. PRINT_STATS_LE32(general, directed_data_mpdu);
  664. } else {
  665. struct mvm_statistics_rx_non_phy *general =
  666. &mvm->rx_stats.general;
  667. PRINT_STATS_LE32(general, bogus_cts);
  668. PRINT_STATS_LE32(general, bogus_ack);
  669. PRINT_STATS_LE32(general, non_channel_beacons);
  670. PRINT_STATS_LE32(general, channel_beacons);
  671. PRINT_STATS_LE32(general, num_missed_bcon);
  672. PRINT_STATS_LE32(general, adc_rx_saturation_time);
  673. PRINT_STATS_LE32(general, ina_detection_search_time);
  674. PRINT_STATS_LE32(general, beacon_silence_rssi_a);
  675. PRINT_STATS_LE32(general, beacon_silence_rssi_b);
  676. PRINT_STATS_LE32(general, beacon_silence_rssi_c);
  677. PRINT_STATS_LE32(general, interference_data_flag);
  678. PRINT_STATS_LE32(general, channel_load);
  679. PRINT_STATS_LE32(general, beacon_rssi_a);
  680. PRINT_STATS_LE32(general, beacon_rssi_b);
  681. PRINT_STATS_LE32(general, beacon_rssi_c);
  682. PRINT_STATS_LE32(general, beacon_energy_a);
  683. PRINT_STATS_LE32(general, beacon_energy_b);
  684. PRINT_STATS_LE32(general, beacon_energy_c);
  685. PRINT_STATS_LE32(general, num_bt_kills);
  686. PRINT_STATS_LE32(general, mac_id);
  687. }
  688. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  689. "Statistics_Rx - HT");
  690. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  691. struct mvm_statistics_rx_ht_phy_v1 *ht =
  692. &mvm->rx_stats_v3.ofdm_ht;
  693. PRINT_STATS_LE32(ht, plcp_err);
  694. PRINT_STATS_LE32(ht, overrun_err);
  695. PRINT_STATS_LE32(ht, early_overrun_err);
  696. PRINT_STATS_LE32(ht, crc32_good);
  697. PRINT_STATS_LE32(ht, crc32_err);
  698. PRINT_STATS_LE32(ht, mh_format_err);
  699. PRINT_STATS_LE32(ht, agg_crc32_good);
  700. PRINT_STATS_LE32(ht, agg_mpdu_cnt);
  701. PRINT_STATS_LE32(ht, agg_cnt);
  702. PRINT_STATS_LE32(ht, unsupport_mcs);
  703. } else {
  704. struct mvm_statistics_rx_ht_phy *ht =
  705. &mvm->rx_stats.ofdm_ht;
  706. PRINT_STATS_LE32(ht, mh_format_err);
  707. PRINT_STATS_LE32(ht, agg_mpdu_cnt);
  708. PRINT_STATS_LE32(ht, agg_cnt);
  709. PRINT_STATS_LE32(ht, unsupport_mcs);
  710. }
  711. mutex_unlock(&mvm->mutex);
  712. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  713. kfree(buf);
  714. return ret;
  715. }
  716. #undef PRINT_STAT_LE32
  717. static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
  718. char __user *user_buf, size_t count,
  719. loff_t *ppos,
  720. struct iwl_mvm_frame_stats *stats)
  721. {
  722. char *buff, *pos, *endpos;
  723. int idx, i;
  724. int ret;
  725. static const size_t bufsz = 1024;
  726. buff = kmalloc(bufsz, GFP_KERNEL);
  727. if (!buff)
  728. return -ENOMEM;
  729. spin_lock_bh(&mvm->drv_stats_lock);
  730. pos = buff;
  731. endpos = pos + bufsz;
  732. pos += scnprintf(pos, endpos - pos,
  733. "Legacy/HT/VHT\t:\t%d/%d/%d\n",
  734. stats->legacy_frames,
  735. stats->ht_frames,
  736. stats->vht_frames);
  737. pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
  738. stats->bw_20_frames,
  739. stats->bw_40_frames,
  740. stats->bw_80_frames);
  741. pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
  742. stats->ngi_frames,
  743. stats->sgi_frames);
  744. pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
  745. stats->siso_frames,
  746. stats->mimo2_frames);
  747. pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
  748. stats->fail_frames,
  749. stats->success_frames);
  750. pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
  751. stats->agg_frames);
  752. pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
  753. stats->ampdu_count);
  754. pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
  755. stats->ampdu_count > 0 ?
  756. (stats->agg_frames / stats->ampdu_count) : 0);
  757. pos += scnprintf(pos, endpos - pos, "Last Rates\n");
  758. idx = stats->last_frame_idx - 1;
  759. for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
  760. idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
  761. if (stats->last_rates[idx] == 0)
  762. continue;
  763. pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
  764. (int)(ARRAY_SIZE(stats->last_rates) - i));
  765. pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
  766. }
  767. spin_unlock_bh(&mvm->drv_stats_lock);
  768. ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
  769. kfree(buff);
  770. return ret;
  771. }
  772. static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
  773. char __user *user_buf, size_t count,
  774. loff_t *ppos)
  775. {
  776. struct iwl_mvm *mvm = file->private_data;
  777. return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
  778. &mvm->drv_rx_stats);
  779. }
  780. static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
  781. size_t count, loff_t *ppos)
  782. {
  783. int __maybe_unused ret;
  784. if (!iwl_mvm_firmware_running(mvm))
  785. return -EIO;
  786. mutex_lock(&mvm->mutex);
  787. /* allow one more restart that we're provoking here */
  788. if (mvm->fw_restart >= 0)
  789. mvm->fw_restart++;
  790. /* take the return value to make compiler happy - it will fail anyway */
  791. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
  792. mutex_unlock(&mvm->mutex);
  793. return count;
  794. }
  795. static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
  796. size_t count, loff_t *ppos)
  797. {
  798. int ret;
  799. if (!iwl_mvm_firmware_running(mvm))
  800. return -EIO;
  801. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
  802. if (ret)
  803. return ret;
  804. iwl_force_nmi(mvm->trans);
  805. iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
  806. return count;
  807. }
  808. static ssize_t
  809. iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
  810. char __user *user_buf,
  811. size_t count, loff_t *ppos)
  812. {
  813. struct iwl_mvm *mvm = file->private_data;
  814. int pos = 0;
  815. char buf[32];
  816. const size_t bufsz = sizeof(buf);
  817. /* print which antennas were set for the scan command by the user */
  818. pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
  819. if (mvm->scan_rx_ant & ANT_A)
  820. pos += scnprintf(buf + pos, bufsz - pos, "A");
  821. if (mvm->scan_rx_ant & ANT_B)
  822. pos += scnprintf(buf + pos, bufsz - pos, "B");
  823. if (mvm->scan_rx_ant & ANT_C)
  824. pos += scnprintf(buf + pos, bufsz - pos, "C");
  825. pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
  826. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  827. }
  828. static ssize_t
  829. iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
  830. size_t count, loff_t *ppos)
  831. {
  832. u8 scan_rx_ant;
  833. if (!iwl_mvm_firmware_running(mvm))
  834. return -EIO;
  835. if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
  836. return -EINVAL;
  837. if (scan_rx_ant > ANT_ABC)
  838. return -EINVAL;
  839. if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
  840. return -EINVAL;
  841. if (mvm->scan_rx_ant != scan_rx_ant) {
  842. mvm->scan_rx_ant = scan_rx_ant;
  843. if (fw_has_capa(&mvm->fw->ucode_capa,
  844. IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  845. iwl_mvm_config_scan(mvm);
  846. }
  847. return count;
  848. }
  849. static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
  850. char *buf, size_t count,
  851. loff_t *ppos)
  852. {
  853. struct iwl_rss_config_cmd cmd = {
  854. .flags = cpu_to_le32(IWL_RSS_ENABLE),
  855. .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
  856. IWL_RSS_HASH_TYPE_IPV4_UDP |
  857. IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
  858. IWL_RSS_HASH_TYPE_IPV6_TCP |
  859. IWL_RSS_HASH_TYPE_IPV6_UDP |
  860. IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
  861. };
  862. int ret, i, num_repeats, nbytes = count / 2;
  863. ret = hex2bin(cmd.indirection_table, buf, nbytes);
  864. if (ret)
  865. return ret;
  866. /*
  867. * The input is the redirection table, partial or full.
  868. * Repeat the pattern if needed.
  869. * For example, input of 01020F will be repeated 42 times,
  870. * indirecting RSS hash results to queues 1, 2, 15 (skipping
  871. * queues 3 - 14).
  872. */
  873. num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
  874. for (i = 1; i < num_repeats; i++)
  875. memcpy(&cmd.indirection_table[i * nbytes],
  876. cmd.indirection_table, nbytes);
  877. /* handle cut in the middle pattern for the last places */
  878. memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
  879. ARRAY_SIZE(cmd.indirection_table) % nbytes);
  880. netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
  881. mutex_lock(&mvm->mutex);
  882. if (iwl_mvm_firmware_running(mvm))
  883. ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
  884. sizeof(cmd), &cmd);
  885. else
  886. ret = 0;
  887. mutex_unlock(&mvm->mutex);
  888. return ret ?: count;
  889. }
  890. static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
  891. char *buf, size_t count,
  892. loff_t *ppos)
  893. {
  894. struct iwl_rx_cmd_buffer rxb = {
  895. ._rx_page_order = 0,
  896. .truesize = 0, /* not used */
  897. ._offset = 0,
  898. };
  899. struct iwl_rx_packet *pkt;
  900. struct iwl_rx_mpdu_desc *desc;
  901. int bin_len = count / 2;
  902. int ret = -EINVAL;
  903. if (!iwl_mvm_firmware_running(mvm))
  904. return -EIO;
  905. /* supporting only 9000 descriptor */
  906. if (!mvm->trans->cfg->mq_rx_supported)
  907. return -ENOTSUPP;
  908. rxb._page = alloc_pages(GFP_ATOMIC, 0);
  909. if (!rxb._page)
  910. return -ENOMEM;
  911. pkt = rxb_addr(&rxb);
  912. ret = hex2bin(page_address(rxb._page), buf, bin_len);
  913. if (ret)
  914. goto out;
  915. /* avoid invalid memory access */
  916. if (bin_len < sizeof(*pkt) + sizeof(*desc))
  917. goto out;
  918. /* check this is RX packet */
  919. if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
  920. WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
  921. goto out;
  922. /* check the length in metadata matches actual received length */
  923. desc = (void *)pkt->data;
  924. if (le16_to_cpu(desc->mpdu_len) !=
  925. (bin_len - sizeof(*desc) - sizeof(*pkt)))
  926. goto out;
  927. local_bh_disable();
  928. iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
  929. local_bh_enable();
  930. ret = 0;
  931. out:
  932. iwl_free_rxb(&rxb);
  933. return ret ?: count;
  934. }
  935. static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
  936. char __user *user_buf,
  937. size_t count, loff_t *ppos)
  938. {
  939. struct iwl_mvm *mvm = file->private_data;
  940. int conf;
  941. char buf[8];
  942. const size_t bufsz = sizeof(buf);
  943. int pos = 0;
  944. mutex_lock(&mvm->mutex);
  945. conf = mvm->fwrt.dump.conf;
  946. mutex_unlock(&mvm->mutex);
  947. pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
  948. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  949. }
  950. /*
  951. * Enable / Disable continuous recording.
  952. * Cause the FW to start continuous recording, by sending the relevant hcmd.
  953. * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
  954. * Disable: for 0 as input, DISABLE_CONT_RECORDING.
  955. */
  956. static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
  957. char *buf, size_t count,
  958. loff_t *ppos)
  959. {
  960. struct iwl_trans *trans = mvm->trans;
  961. const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
  962. struct iwl_continuous_record_cmd cont_rec = {};
  963. int ret, rec_mode;
  964. if (!iwl_mvm_firmware_running(mvm))
  965. return -EIO;
  966. if (!dest)
  967. return -EOPNOTSUPP;
  968. if (dest->monitor_mode != SMEM_MODE ||
  969. trans->cfg->device_family < IWL_DEVICE_FAMILY_8000)
  970. return -EOPNOTSUPP;
  971. ret = kstrtoint(buf, 0, &rec_mode);
  972. if (ret)
  973. return ret;
  974. cont_rec.record_mode.enable_recording = rec_mode ?
  975. cpu_to_le16(ENABLE_CONT_RECORDING) :
  976. cpu_to_le16(DISABLE_CONT_RECORDING);
  977. mutex_lock(&mvm->mutex);
  978. ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
  979. sizeof(cont_rec), &cont_rec);
  980. mutex_unlock(&mvm->mutex);
  981. return ret ?: count;
  982. }
  983. static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
  984. char *buf, size_t count,
  985. loff_t *ppos)
  986. {
  987. unsigned int conf_id;
  988. int ret;
  989. if (!iwl_mvm_firmware_running(mvm))
  990. return -EIO;
  991. ret = kstrtouint(buf, 0, &conf_id);
  992. if (ret)
  993. return ret;
  994. if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
  995. return -EINVAL;
  996. mutex_lock(&mvm->mutex);
  997. ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id);
  998. mutex_unlock(&mvm->mutex);
  999. return ret ?: count;
  1000. }
  1001. static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
  1002. char *buf, size_t count,
  1003. loff_t *ppos)
  1004. {
  1005. int ret;
  1006. if (!iwl_mvm_firmware_running(mvm))
  1007. return -EIO;
  1008. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  1009. if (ret)
  1010. return ret;
  1011. if (count == 0)
  1012. return 0;
  1013. iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf,
  1014. (count - 1), NULL);
  1015. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  1016. return count;
  1017. }
  1018. static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
  1019. char *buf, size_t count,
  1020. loff_t *ppos)
  1021. {
  1022. unsigned int max_amsdu_len;
  1023. int ret;
  1024. ret = kstrtouint(buf, 0, &max_amsdu_len);
  1025. if (ret)
  1026. return ret;
  1027. if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
  1028. return -EINVAL;
  1029. mvm->max_amsdu_len = max_amsdu_len;
  1030. return count;
  1031. }
  1032. #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
  1033. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1034. static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
  1035. char __user *user_buf,
  1036. size_t count, loff_t *ppos)
  1037. {
  1038. struct iwl_mvm *mvm = file->private_data;
  1039. struct iwl_bcast_filter_cmd cmd;
  1040. const struct iwl_fw_bcast_filter *filter;
  1041. char *buf;
  1042. int bufsz = 1024;
  1043. int i, j, pos = 0;
  1044. ssize_t ret;
  1045. buf = kzalloc(bufsz, GFP_KERNEL);
  1046. if (!buf)
  1047. return -ENOMEM;
  1048. mutex_lock(&mvm->mutex);
  1049. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  1050. ADD_TEXT("None\n");
  1051. mutex_unlock(&mvm->mutex);
  1052. goto out;
  1053. }
  1054. mutex_unlock(&mvm->mutex);
  1055. for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
  1056. filter = &cmd.filters[i];
  1057. ADD_TEXT("Filter [%d]:\n", i);
  1058. ADD_TEXT("\tDiscard=%d\n", filter->discard);
  1059. ADD_TEXT("\tFrame Type: %s\n",
  1060. filter->frame_type ? "IPv4" : "Generic");
  1061. for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
  1062. const struct iwl_fw_bcast_filter_attr *attr;
  1063. attr = &filter->attrs[j];
  1064. if (!attr->mask)
  1065. break;
  1066. ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
  1067. j, attr->offset,
  1068. attr->offset_type ? "IP End" :
  1069. "Payload Start",
  1070. be32_to_cpu(attr->mask),
  1071. be32_to_cpu(attr->val),
  1072. le16_to_cpu(attr->reserved1));
  1073. }
  1074. }
  1075. out:
  1076. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1077. kfree(buf);
  1078. return ret;
  1079. }
  1080. static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
  1081. size_t count, loff_t *ppos)
  1082. {
  1083. int pos, next_pos;
  1084. struct iwl_fw_bcast_filter filter = {};
  1085. struct iwl_bcast_filter_cmd cmd;
  1086. u32 filter_id, attr_id, mask, value;
  1087. int err = 0;
  1088. if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
  1089. &filter.frame_type, &pos) != 3)
  1090. return -EINVAL;
  1091. if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
  1092. filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
  1093. return -EINVAL;
  1094. for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
  1095. attr_id++) {
  1096. struct iwl_fw_bcast_filter_attr *attr =
  1097. &filter.attrs[attr_id];
  1098. if (pos >= count)
  1099. break;
  1100. if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
  1101. &attr->offset, &attr->offset_type,
  1102. &mask, &value, &next_pos) != 4)
  1103. return -EINVAL;
  1104. attr->mask = cpu_to_be32(mask);
  1105. attr->val = cpu_to_be32(value);
  1106. if (mask)
  1107. filter.num_attrs++;
  1108. pos += next_pos;
  1109. }
  1110. mutex_lock(&mvm->mutex);
  1111. memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
  1112. &filter, sizeof(filter));
  1113. /* send updated bcast filtering configuration */
  1114. if (iwl_mvm_firmware_running(mvm) &&
  1115. mvm->dbgfs_bcast_filtering.override &&
  1116. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  1117. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  1118. sizeof(cmd), &cmd);
  1119. mutex_unlock(&mvm->mutex);
  1120. return err ?: count;
  1121. }
  1122. static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
  1123. char __user *user_buf,
  1124. size_t count, loff_t *ppos)
  1125. {
  1126. struct iwl_mvm *mvm = file->private_data;
  1127. struct iwl_bcast_filter_cmd cmd;
  1128. char *buf;
  1129. int bufsz = 1024;
  1130. int i, pos = 0;
  1131. ssize_t ret;
  1132. buf = kzalloc(bufsz, GFP_KERNEL);
  1133. if (!buf)
  1134. return -ENOMEM;
  1135. mutex_lock(&mvm->mutex);
  1136. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  1137. ADD_TEXT("None\n");
  1138. mutex_unlock(&mvm->mutex);
  1139. goto out;
  1140. }
  1141. mutex_unlock(&mvm->mutex);
  1142. for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
  1143. const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
  1144. ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
  1145. i, mac->default_discard, mac->attached_filters);
  1146. }
  1147. out:
  1148. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1149. kfree(buf);
  1150. return ret;
  1151. }
  1152. static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
  1153. char *buf, size_t count,
  1154. loff_t *ppos)
  1155. {
  1156. struct iwl_bcast_filter_cmd cmd;
  1157. struct iwl_fw_bcast_mac mac = {};
  1158. u32 mac_id, attached_filters;
  1159. int err = 0;
  1160. if (!mvm->bcast_filters)
  1161. return -ENOENT;
  1162. if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
  1163. &attached_filters) != 3)
  1164. return -EINVAL;
  1165. if (mac_id >= ARRAY_SIZE(cmd.macs) ||
  1166. mac.default_discard > 1 ||
  1167. attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
  1168. return -EINVAL;
  1169. mac.attached_filters = cpu_to_le16(attached_filters);
  1170. mutex_lock(&mvm->mutex);
  1171. memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
  1172. &mac, sizeof(mac));
  1173. /* send updated bcast filtering configuration */
  1174. if (iwl_mvm_firmware_running(mvm) &&
  1175. mvm->dbgfs_bcast_filtering.override &&
  1176. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  1177. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  1178. sizeof(cmd), &cmd);
  1179. mutex_unlock(&mvm->mutex);
  1180. return err ?: count;
  1181. }
  1182. #endif
  1183. #ifdef CONFIG_PM_SLEEP
  1184. static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
  1185. size_t count, loff_t *ppos)
  1186. {
  1187. int store;
  1188. if (sscanf(buf, "%d", &store) != 1)
  1189. return -EINVAL;
  1190. mvm->store_d3_resume_sram = store;
  1191. return count;
  1192. }
  1193. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  1194. size_t count, loff_t *ppos)
  1195. {
  1196. struct iwl_mvm *mvm = file->private_data;
  1197. const struct fw_img *img;
  1198. int ofs, len, pos = 0;
  1199. size_t bufsz, ret;
  1200. char *buf;
  1201. u8 *ptr = mvm->d3_resume_sram;
  1202. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  1203. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  1204. bufsz = len * 4 + 256;
  1205. buf = kzalloc(bufsz, GFP_KERNEL);
  1206. if (!buf)
  1207. return -ENOMEM;
  1208. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  1209. mvm->store_d3_resume_sram ? "en" : "dis");
  1210. if (ptr) {
  1211. for (ofs = 0; ofs < len; ofs += 16) {
  1212. pos += scnprintf(buf + pos, bufsz - pos,
  1213. "0x%.4x %16ph\n", ofs, ptr + ofs);
  1214. }
  1215. } else {
  1216. pos += scnprintf(buf + pos, bufsz - pos,
  1217. "(no data captured)\n");
  1218. }
  1219. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1220. kfree(buf);
  1221. return ret;
  1222. }
  1223. #endif
  1224. #define PRINT_MVM_REF(ref) do { \
  1225. if (mvm->refs[ref]) \
  1226. pos += scnprintf(buf + pos, bufsz - pos, \
  1227. "\t(0x%lx): %d %s\n", \
  1228. BIT(ref), mvm->refs[ref], #ref); \
  1229. } while (0)
  1230. static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
  1231. char __user *user_buf,
  1232. size_t count, loff_t *ppos)
  1233. {
  1234. struct iwl_mvm *mvm = file->private_data;
  1235. int i, pos = 0;
  1236. char buf[256];
  1237. const size_t bufsz = sizeof(buf);
  1238. u32 refs = 0;
  1239. for (i = 0; i < IWL_MVM_REF_COUNT; i++)
  1240. if (mvm->refs[i])
  1241. refs |= BIT(i);
  1242. pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
  1243. refs);
  1244. PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
  1245. PRINT_MVM_REF(IWL_MVM_REF_SCAN);
  1246. PRINT_MVM_REF(IWL_MVM_REF_ROC);
  1247. PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
  1248. PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
  1249. PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
  1250. PRINT_MVM_REF(IWL_MVM_REF_USER);
  1251. PRINT_MVM_REF(IWL_MVM_REF_TX);
  1252. PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
  1253. PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
  1254. PRINT_MVM_REF(IWL_MVM_REF_START_AP);
  1255. PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
  1256. PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
  1257. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
  1258. PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
  1259. PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
  1260. PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
  1261. PRINT_MVM_REF(IWL_MVM_REF_NMI);
  1262. PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
  1263. PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
  1264. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
  1265. PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
  1266. PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
  1267. PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
  1268. PRINT_MVM_REF(IWL_MVM_REF_RX);
  1269. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1270. }
  1271. static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
  1272. size_t count, loff_t *ppos)
  1273. {
  1274. unsigned long value;
  1275. int ret;
  1276. bool taken;
  1277. ret = kstrtoul(buf, 10, &value);
  1278. if (ret < 0)
  1279. return ret;
  1280. mutex_lock(&mvm->mutex);
  1281. taken = mvm->refs[IWL_MVM_REF_USER];
  1282. if (value == 1 && !taken)
  1283. iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
  1284. else if (value == 0 && taken)
  1285. iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
  1286. else
  1287. ret = -EINVAL;
  1288. mutex_unlock(&mvm->mutex);
  1289. if (ret < 0)
  1290. return ret;
  1291. return count;
  1292. }
  1293. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1294. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1295. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1296. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1297. #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
  1298. if (!debugfs_create_file(alias, mode, parent, mvm, \
  1299. &iwl_dbgfs_##name##_ops)) \
  1300. goto err; \
  1301. } while (0)
  1302. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
  1303. MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
  1304. static ssize_t
  1305. iwl_dbgfs_prph_reg_read(struct file *file,
  1306. char __user *user_buf,
  1307. size_t count, loff_t *ppos)
  1308. {
  1309. struct iwl_mvm *mvm = file->private_data;
  1310. int pos = 0;
  1311. char buf[32];
  1312. const size_t bufsz = sizeof(buf);
  1313. int ret;
  1314. if (!mvm->dbgfs_prph_reg_addr)
  1315. return -EINVAL;
  1316. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
  1317. if (ret)
  1318. return ret;
  1319. pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
  1320. mvm->dbgfs_prph_reg_addr,
  1321. iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
  1322. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
  1323. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1324. }
  1325. static ssize_t
  1326. iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
  1327. size_t count, loff_t *ppos)
  1328. {
  1329. u8 args;
  1330. u32 value;
  1331. int ret;
  1332. args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
  1333. /* if we only want to set the reg address - nothing more to do */
  1334. if (args == 1)
  1335. goto out;
  1336. /* otherwise, make sure we have both address and value */
  1337. if (args != 2)
  1338. return -EINVAL;
  1339. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  1340. if (ret)
  1341. return ret;
  1342. iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
  1343. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  1344. out:
  1345. return count;
  1346. }
  1347. static ssize_t
  1348. iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
  1349. size_t count, loff_t *ppos)
  1350. {
  1351. int ret;
  1352. if (!iwl_mvm_firmware_running(mvm))
  1353. return -EIO;
  1354. mutex_lock(&mvm->mutex);
  1355. ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
  1356. mutex_unlock(&mvm->mutex);
  1357. return ret ?: count;
  1358. }
  1359. MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
  1360. /* Device wide debugfs entries */
  1361. MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
  1362. MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
  1363. MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8);
  1364. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
  1365. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
  1366. MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
  1367. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
  1368. MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
  1369. MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
  1370. MVM_DEBUGFS_READ_FILE_OPS(stations);
  1371. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  1372. MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
  1373. MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
  1374. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  1375. MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
  1376. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
  1377. MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
  1378. MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
  1379. MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
  1380. MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
  1381. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
  1382. MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
  1383. MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
  1384. MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
  1385. MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
  1386. MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
  1387. (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
  1388. MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
  1389. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1390. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
  1391. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
  1392. #endif
  1393. #ifdef CONFIG_PM_SLEEP
  1394. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
  1395. #endif
  1396. #ifdef CONFIG_ACPI
  1397. MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile);
  1398. #endif
  1399. static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
  1400. size_t count, loff_t *ppos)
  1401. {
  1402. struct iwl_mvm *mvm = file->private_data;
  1403. struct iwl_dbg_mem_access_cmd cmd = {};
  1404. struct iwl_dbg_mem_access_rsp *rsp;
  1405. struct iwl_host_cmd hcmd = {
  1406. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1407. .data = { &cmd, },
  1408. .len = { sizeof(cmd) },
  1409. };
  1410. size_t delta;
  1411. ssize_t ret, len;
  1412. if (!iwl_mvm_firmware_running(mvm))
  1413. return -EIO;
  1414. hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
  1415. DEBUG_GROUP, 0);
  1416. cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
  1417. /* Take care of alignment of both the position and the length */
  1418. delta = *ppos & 0x3;
  1419. cmd.addr = cpu_to_le32(*ppos - delta);
  1420. cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
  1421. (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
  1422. mutex_lock(&mvm->mutex);
  1423. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1424. mutex_unlock(&mvm->mutex);
  1425. if (ret < 0)
  1426. return ret;
  1427. rsp = (void *)hcmd.resp_pkt->data;
  1428. if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
  1429. ret = -ENXIO;
  1430. goto out;
  1431. }
  1432. len = min((size_t)le32_to_cpu(rsp->len) << 2,
  1433. iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
  1434. len = min(len - delta, count);
  1435. if (len < 0) {
  1436. ret = -EFAULT;
  1437. goto out;
  1438. }
  1439. ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
  1440. *ppos += ret;
  1441. out:
  1442. iwl_free_resp(&hcmd);
  1443. return ret;
  1444. }
  1445. static ssize_t iwl_dbgfs_mem_write(struct file *file,
  1446. const char __user *user_buf, size_t count,
  1447. loff_t *ppos)
  1448. {
  1449. struct iwl_mvm *mvm = file->private_data;
  1450. struct iwl_dbg_mem_access_cmd *cmd;
  1451. struct iwl_dbg_mem_access_rsp *rsp;
  1452. struct iwl_host_cmd hcmd = {};
  1453. size_t cmd_size;
  1454. size_t data_size;
  1455. u32 op, len;
  1456. ssize_t ret;
  1457. if (!iwl_mvm_firmware_running(mvm))
  1458. return -EIO;
  1459. hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
  1460. DEBUG_GROUP, 0);
  1461. if (*ppos & 0x3 || count < 4) {
  1462. op = DEBUG_MEM_OP_WRITE_BYTES;
  1463. len = min(count, (size_t)(4 - (*ppos & 0x3)));
  1464. data_size = len;
  1465. } else {
  1466. op = DEBUG_MEM_OP_WRITE;
  1467. len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
  1468. data_size = len << 2;
  1469. }
  1470. cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
  1471. cmd = kzalloc(cmd_size, GFP_KERNEL);
  1472. if (!cmd)
  1473. return -ENOMEM;
  1474. cmd->op = cpu_to_le32(op);
  1475. cmd->len = cpu_to_le32(len);
  1476. cmd->addr = cpu_to_le32(*ppos);
  1477. if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
  1478. kfree(cmd);
  1479. return -EFAULT;
  1480. }
  1481. hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1482. hcmd.data[0] = (void *)cmd;
  1483. hcmd.len[0] = cmd_size;
  1484. mutex_lock(&mvm->mutex);
  1485. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1486. mutex_unlock(&mvm->mutex);
  1487. kfree(cmd);
  1488. if (ret < 0)
  1489. return ret;
  1490. rsp = (void *)hcmd.resp_pkt->data;
  1491. if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
  1492. ret = -ENXIO;
  1493. goto out;
  1494. }
  1495. ret = data_size;
  1496. *ppos += ret;
  1497. out:
  1498. iwl_free_resp(&hcmd);
  1499. return ret;
  1500. }
  1501. static const struct file_operations iwl_dbgfs_mem_ops = {
  1502. .read = iwl_dbgfs_mem_read,
  1503. .write = iwl_dbgfs_mem_write,
  1504. .open = simple_open,
  1505. .llseek = default_llseek,
  1506. };
  1507. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  1508. {
  1509. struct dentry *bcast_dir __maybe_unused;
  1510. char buf[100];
  1511. spin_lock_init(&mvm->drv_stats_lock);
  1512. mvm->debugfs_dir = dbgfs_dir;
  1513. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  1514. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  1515. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1516. MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
  1517. S_IWUSR | S_IRUSR);
  1518. MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
  1519. MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
  1520. MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
  1521. MVM_DEBUGFS_ADD_FILE(force_ctkill, dbgfs_dir, S_IWUSR);
  1522. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  1523. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  1524. MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
  1525. MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
  1526. S_IRUSR | S_IWUSR);
  1527. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1528. MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1529. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  1530. MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
  1531. MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
  1532. MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
  1533. MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
  1534. S_IWUSR | S_IRUSR);
  1535. MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1536. MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1537. MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1538. MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
  1539. MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
  1540. MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
  1541. MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
  1542. MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
  1543. MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, S_IWUSR);
  1544. #ifdef CONFIG_ACPI
  1545. MVM_DEBUGFS_ADD_FILE(sar_geo_profile, dbgfs_dir, S_IRUSR);
  1546. #endif
  1547. if (!debugfs_create_bool("enable_scan_iteration_notif",
  1548. S_IRUSR | S_IWUSR,
  1549. mvm->debugfs_dir,
  1550. &mvm->scan_iter_notif_enabled))
  1551. goto err;
  1552. if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
  1553. mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
  1554. goto err;
  1555. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1556. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
  1557. bcast_dir = debugfs_create_dir("bcast_filtering",
  1558. mvm->debugfs_dir);
  1559. if (!bcast_dir)
  1560. goto err;
  1561. if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
  1562. bcast_dir,
  1563. &mvm->dbgfs_bcast_filtering.override))
  1564. goto err;
  1565. MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
  1566. bcast_dir, S_IWUSR | S_IRUSR);
  1567. MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
  1568. bcast_dir, S_IWUSR | S_IRUSR);
  1569. }
  1570. #endif
  1571. #ifdef CONFIG_PM_SLEEP
  1572. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1573. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  1574. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  1575. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  1576. goto err;
  1577. if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
  1578. mvm->debugfs_dir, &mvm->last_netdetect_scans))
  1579. goto err;
  1580. #endif
  1581. if (!debugfs_create_u8("ps_disabled", S_IRUSR,
  1582. mvm->debugfs_dir, &mvm->ps_disabled))
  1583. goto err;
  1584. if (!debugfs_create_blob("nvm_hw", S_IRUSR,
  1585. mvm->debugfs_dir, &mvm->nvm_hw_blob))
  1586. goto err;
  1587. if (!debugfs_create_blob("nvm_sw", S_IRUSR,
  1588. mvm->debugfs_dir, &mvm->nvm_sw_blob))
  1589. goto err;
  1590. if (!debugfs_create_blob("nvm_calib", S_IRUSR,
  1591. mvm->debugfs_dir, &mvm->nvm_calib_blob))
  1592. goto err;
  1593. if (!debugfs_create_blob("nvm_prod", S_IRUSR,
  1594. mvm->debugfs_dir, &mvm->nvm_prod_blob))
  1595. goto err;
  1596. if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
  1597. mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
  1598. goto err;
  1599. debugfs_create_file("mem", S_IRUSR | S_IWUSR, dbgfs_dir, mvm,
  1600. &iwl_dbgfs_mem_ops);
  1601. /*
  1602. * Create a symlink with mac80211. It will be removed when mac80211
  1603. * exists (before the opmode exists which removes the target.)
  1604. */
  1605. snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
  1606. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  1607. goto err;
  1608. return 0;
  1609. err:
  1610. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  1611. return -ENOMEM;
  1612. }