debugfs.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972
  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. static ssize_t iwl_dbgfs_fw_ver_read(struct file *file, char __user *user_buf,
  546. size_t count, loff_t *ppos)
  547. {
  548. struct iwl_mvm *mvm = file->private_data;
  549. char *buff, *pos, *endpos;
  550. static const size_t bufsz = 1024;
  551. int ret;
  552. buff = kmalloc(bufsz, GFP_KERNEL);
  553. if (!buff)
  554. return -ENOMEM;
  555. pos = buff;
  556. endpos = pos + bufsz;
  557. pos += scnprintf(pos, endpos - pos, "FW prefix: %s\n",
  558. mvm->trans->cfg->fw_name_pre);
  559. pos += scnprintf(pos, endpos - pos, "FW: %s\n",
  560. mvm->fwrt.fw->human_readable);
  561. pos += scnprintf(pos, endpos - pos, "Device: %s\n",
  562. mvm->fwrt.trans->cfg->name);
  563. pos += scnprintf(pos, endpos - pos, "Bus: %s\n",
  564. mvm->fwrt.dev->bus->name);
  565. ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
  566. kfree(buff);
  567. return ret;
  568. }
  569. #define PRINT_STATS_LE32(_struct, _memb) \
  570. pos += scnprintf(buf + pos, bufsz - pos, \
  571. fmt_table, #_memb, \
  572. le32_to_cpu(_struct->_memb))
  573. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  574. char __user *user_buf, size_t count,
  575. loff_t *ppos)
  576. {
  577. struct iwl_mvm *mvm = file->private_data;
  578. static const char *fmt_table = "\t%-30s %10u\n";
  579. static const char *fmt_header = "%-32s\n";
  580. int pos = 0;
  581. char *buf;
  582. int ret;
  583. size_t bufsz;
  584. if (iwl_mvm_has_new_rx_stats_api(mvm))
  585. bufsz = ((sizeof(struct mvm_statistics_rx) /
  586. sizeof(__le32)) * 43) + (4 * 33) + 1;
  587. else
  588. /* 43 = size of each data line; 33 = size of each header */
  589. bufsz = ((sizeof(struct mvm_statistics_rx_v3) /
  590. sizeof(__le32)) * 43) + (4 * 33) + 1;
  591. buf = kzalloc(bufsz, GFP_KERNEL);
  592. if (!buf)
  593. return -ENOMEM;
  594. mutex_lock(&mvm->mutex);
  595. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  596. "Statistics_Rx - OFDM");
  597. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  598. struct mvm_statistics_rx_phy_v2 *ofdm = &mvm->rx_stats_v3.ofdm;
  599. PRINT_STATS_LE32(ofdm, ina_cnt);
  600. PRINT_STATS_LE32(ofdm, fina_cnt);
  601. PRINT_STATS_LE32(ofdm, plcp_err);
  602. PRINT_STATS_LE32(ofdm, crc32_err);
  603. PRINT_STATS_LE32(ofdm, overrun_err);
  604. PRINT_STATS_LE32(ofdm, early_overrun_err);
  605. PRINT_STATS_LE32(ofdm, crc32_good);
  606. PRINT_STATS_LE32(ofdm, false_alarm_cnt);
  607. PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
  608. PRINT_STATS_LE32(ofdm, sfd_timeout);
  609. PRINT_STATS_LE32(ofdm, fina_timeout);
  610. PRINT_STATS_LE32(ofdm, unresponded_rts);
  611. PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
  612. PRINT_STATS_LE32(ofdm, sent_ack_cnt);
  613. PRINT_STATS_LE32(ofdm, sent_cts_cnt);
  614. PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
  615. PRINT_STATS_LE32(ofdm, dsp_self_kill);
  616. PRINT_STATS_LE32(ofdm, mh_format_err);
  617. PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
  618. PRINT_STATS_LE32(ofdm, reserved);
  619. } else {
  620. struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm;
  621. PRINT_STATS_LE32(ofdm, unresponded_rts);
  622. PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
  623. PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
  624. PRINT_STATS_LE32(ofdm, dsp_self_kill);
  625. PRINT_STATS_LE32(ofdm, reserved);
  626. }
  627. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  628. "Statistics_Rx - CCK");
  629. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  630. struct mvm_statistics_rx_phy_v2 *cck = &mvm->rx_stats_v3.cck;
  631. PRINT_STATS_LE32(cck, ina_cnt);
  632. PRINT_STATS_LE32(cck, fina_cnt);
  633. PRINT_STATS_LE32(cck, plcp_err);
  634. PRINT_STATS_LE32(cck, crc32_err);
  635. PRINT_STATS_LE32(cck, overrun_err);
  636. PRINT_STATS_LE32(cck, early_overrun_err);
  637. PRINT_STATS_LE32(cck, crc32_good);
  638. PRINT_STATS_LE32(cck, false_alarm_cnt);
  639. PRINT_STATS_LE32(cck, fina_sync_err_cnt);
  640. PRINT_STATS_LE32(cck, sfd_timeout);
  641. PRINT_STATS_LE32(cck, fina_timeout);
  642. PRINT_STATS_LE32(cck, unresponded_rts);
  643. PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
  644. PRINT_STATS_LE32(cck, sent_ack_cnt);
  645. PRINT_STATS_LE32(cck, sent_cts_cnt);
  646. PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
  647. PRINT_STATS_LE32(cck, dsp_self_kill);
  648. PRINT_STATS_LE32(cck, mh_format_err);
  649. PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
  650. PRINT_STATS_LE32(cck, reserved);
  651. } else {
  652. struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck;
  653. PRINT_STATS_LE32(cck, unresponded_rts);
  654. PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
  655. PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
  656. PRINT_STATS_LE32(cck, dsp_self_kill);
  657. PRINT_STATS_LE32(cck, reserved);
  658. }
  659. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  660. "Statistics_Rx - GENERAL");
  661. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  662. struct mvm_statistics_rx_non_phy_v3 *general =
  663. &mvm->rx_stats_v3.general;
  664. PRINT_STATS_LE32(general, bogus_cts);
  665. PRINT_STATS_LE32(general, bogus_ack);
  666. PRINT_STATS_LE32(general, non_bssid_frames);
  667. PRINT_STATS_LE32(general, filtered_frames);
  668. PRINT_STATS_LE32(general, non_channel_beacons);
  669. PRINT_STATS_LE32(general, channel_beacons);
  670. PRINT_STATS_LE32(general, num_missed_bcon);
  671. PRINT_STATS_LE32(general, adc_rx_saturation_time);
  672. PRINT_STATS_LE32(general, ina_detection_search_time);
  673. PRINT_STATS_LE32(general, beacon_silence_rssi_a);
  674. PRINT_STATS_LE32(general, beacon_silence_rssi_b);
  675. PRINT_STATS_LE32(general, beacon_silence_rssi_c);
  676. PRINT_STATS_LE32(general, interference_data_flag);
  677. PRINT_STATS_LE32(general, channel_load);
  678. PRINT_STATS_LE32(general, dsp_false_alarms);
  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. PRINT_STATS_LE32(general, directed_data_mpdu);
  688. } else {
  689. struct mvm_statistics_rx_non_phy *general =
  690. &mvm->rx_stats.general;
  691. PRINT_STATS_LE32(general, bogus_cts);
  692. PRINT_STATS_LE32(general, bogus_ack);
  693. PRINT_STATS_LE32(general, non_channel_beacons);
  694. PRINT_STATS_LE32(general, channel_beacons);
  695. PRINT_STATS_LE32(general, num_missed_bcon);
  696. PRINT_STATS_LE32(general, adc_rx_saturation_time);
  697. PRINT_STATS_LE32(general, ina_detection_search_time);
  698. PRINT_STATS_LE32(general, beacon_silence_rssi_a);
  699. PRINT_STATS_LE32(general, beacon_silence_rssi_b);
  700. PRINT_STATS_LE32(general, beacon_silence_rssi_c);
  701. PRINT_STATS_LE32(general, interference_data_flag);
  702. PRINT_STATS_LE32(general, channel_load);
  703. PRINT_STATS_LE32(general, beacon_rssi_a);
  704. PRINT_STATS_LE32(general, beacon_rssi_b);
  705. PRINT_STATS_LE32(general, beacon_rssi_c);
  706. PRINT_STATS_LE32(general, beacon_energy_a);
  707. PRINT_STATS_LE32(general, beacon_energy_b);
  708. PRINT_STATS_LE32(general, beacon_energy_c);
  709. PRINT_STATS_LE32(general, num_bt_kills);
  710. PRINT_STATS_LE32(general, mac_id);
  711. }
  712. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  713. "Statistics_Rx - HT");
  714. if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
  715. struct mvm_statistics_rx_ht_phy_v1 *ht =
  716. &mvm->rx_stats_v3.ofdm_ht;
  717. PRINT_STATS_LE32(ht, plcp_err);
  718. PRINT_STATS_LE32(ht, overrun_err);
  719. PRINT_STATS_LE32(ht, early_overrun_err);
  720. PRINT_STATS_LE32(ht, crc32_good);
  721. PRINT_STATS_LE32(ht, crc32_err);
  722. PRINT_STATS_LE32(ht, mh_format_err);
  723. PRINT_STATS_LE32(ht, agg_crc32_good);
  724. PRINT_STATS_LE32(ht, agg_mpdu_cnt);
  725. PRINT_STATS_LE32(ht, agg_cnt);
  726. PRINT_STATS_LE32(ht, unsupport_mcs);
  727. } else {
  728. struct mvm_statistics_rx_ht_phy *ht =
  729. &mvm->rx_stats.ofdm_ht;
  730. PRINT_STATS_LE32(ht, mh_format_err);
  731. PRINT_STATS_LE32(ht, agg_mpdu_cnt);
  732. PRINT_STATS_LE32(ht, agg_cnt);
  733. PRINT_STATS_LE32(ht, unsupport_mcs);
  734. }
  735. mutex_unlock(&mvm->mutex);
  736. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  737. kfree(buf);
  738. return ret;
  739. }
  740. #undef PRINT_STAT_LE32
  741. static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
  742. char __user *user_buf, size_t count,
  743. loff_t *ppos,
  744. struct iwl_mvm_frame_stats *stats)
  745. {
  746. char *buff, *pos, *endpos;
  747. int idx, i;
  748. int ret;
  749. static const size_t bufsz = 1024;
  750. buff = kmalloc(bufsz, GFP_KERNEL);
  751. if (!buff)
  752. return -ENOMEM;
  753. spin_lock_bh(&mvm->drv_stats_lock);
  754. pos = buff;
  755. endpos = pos + bufsz;
  756. pos += scnprintf(pos, endpos - pos,
  757. "Legacy/HT/VHT\t:\t%d/%d/%d\n",
  758. stats->legacy_frames,
  759. stats->ht_frames,
  760. stats->vht_frames);
  761. pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
  762. stats->bw_20_frames,
  763. stats->bw_40_frames,
  764. stats->bw_80_frames);
  765. pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
  766. stats->ngi_frames,
  767. stats->sgi_frames);
  768. pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
  769. stats->siso_frames,
  770. stats->mimo2_frames);
  771. pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
  772. stats->fail_frames,
  773. stats->success_frames);
  774. pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
  775. stats->agg_frames);
  776. pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
  777. stats->ampdu_count);
  778. pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
  779. stats->ampdu_count > 0 ?
  780. (stats->agg_frames / stats->ampdu_count) : 0);
  781. pos += scnprintf(pos, endpos - pos, "Last Rates\n");
  782. idx = stats->last_frame_idx - 1;
  783. for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
  784. idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
  785. if (stats->last_rates[idx] == 0)
  786. continue;
  787. pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
  788. (int)(ARRAY_SIZE(stats->last_rates) - i));
  789. pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
  790. }
  791. spin_unlock_bh(&mvm->drv_stats_lock);
  792. ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
  793. kfree(buff);
  794. return ret;
  795. }
  796. static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
  797. char __user *user_buf, size_t count,
  798. loff_t *ppos)
  799. {
  800. struct iwl_mvm *mvm = file->private_data;
  801. return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
  802. &mvm->drv_rx_stats);
  803. }
  804. static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
  805. size_t count, loff_t *ppos)
  806. {
  807. int __maybe_unused ret;
  808. if (!iwl_mvm_firmware_running(mvm))
  809. return -EIO;
  810. mutex_lock(&mvm->mutex);
  811. /* allow one more restart that we're provoking here */
  812. if (mvm->fw_restart >= 0)
  813. mvm->fw_restart++;
  814. /* take the return value to make compiler happy - it will fail anyway */
  815. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
  816. mutex_unlock(&mvm->mutex);
  817. return count;
  818. }
  819. static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
  820. size_t count, loff_t *ppos)
  821. {
  822. int ret;
  823. if (!iwl_mvm_firmware_running(mvm))
  824. return -EIO;
  825. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
  826. if (ret)
  827. return ret;
  828. iwl_force_nmi(mvm->trans);
  829. iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
  830. return count;
  831. }
  832. static ssize_t
  833. iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
  834. char __user *user_buf,
  835. size_t count, loff_t *ppos)
  836. {
  837. struct iwl_mvm *mvm = file->private_data;
  838. int pos = 0;
  839. char buf[32];
  840. const size_t bufsz = sizeof(buf);
  841. /* print which antennas were set for the scan command by the user */
  842. pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
  843. if (mvm->scan_rx_ant & ANT_A)
  844. pos += scnprintf(buf + pos, bufsz - pos, "A");
  845. if (mvm->scan_rx_ant & ANT_B)
  846. pos += scnprintf(buf + pos, bufsz - pos, "B");
  847. if (mvm->scan_rx_ant & ANT_C)
  848. pos += scnprintf(buf + pos, bufsz - pos, "C");
  849. pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
  850. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  851. }
  852. static ssize_t
  853. iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
  854. size_t count, loff_t *ppos)
  855. {
  856. u8 scan_rx_ant;
  857. if (!iwl_mvm_firmware_running(mvm))
  858. return -EIO;
  859. if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
  860. return -EINVAL;
  861. if (scan_rx_ant > ANT_ABC)
  862. return -EINVAL;
  863. if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
  864. return -EINVAL;
  865. if (mvm->scan_rx_ant != scan_rx_ant) {
  866. mvm->scan_rx_ant = scan_rx_ant;
  867. if (fw_has_capa(&mvm->fw->ucode_capa,
  868. IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  869. iwl_mvm_config_scan(mvm);
  870. }
  871. return count;
  872. }
  873. static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
  874. char *buf, size_t count,
  875. loff_t *ppos)
  876. {
  877. struct iwl_rss_config_cmd cmd = {
  878. .flags = cpu_to_le32(IWL_RSS_ENABLE),
  879. .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
  880. IWL_RSS_HASH_TYPE_IPV4_UDP |
  881. IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
  882. IWL_RSS_HASH_TYPE_IPV6_TCP |
  883. IWL_RSS_HASH_TYPE_IPV6_UDP |
  884. IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
  885. };
  886. int ret, i, num_repeats, nbytes = count / 2;
  887. ret = hex2bin(cmd.indirection_table, buf, nbytes);
  888. if (ret)
  889. return ret;
  890. /*
  891. * The input is the redirection table, partial or full.
  892. * Repeat the pattern if needed.
  893. * For example, input of 01020F will be repeated 42 times,
  894. * indirecting RSS hash results to queues 1, 2, 15 (skipping
  895. * queues 3 - 14).
  896. */
  897. num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
  898. for (i = 1; i < num_repeats; i++)
  899. memcpy(&cmd.indirection_table[i * nbytes],
  900. cmd.indirection_table, nbytes);
  901. /* handle cut in the middle pattern for the last places */
  902. memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
  903. ARRAY_SIZE(cmd.indirection_table) % nbytes);
  904. netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
  905. mutex_lock(&mvm->mutex);
  906. if (iwl_mvm_firmware_running(mvm))
  907. ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
  908. sizeof(cmd), &cmd);
  909. else
  910. ret = 0;
  911. mutex_unlock(&mvm->mutex);
  912. return ret ?: count;
  913. }
  914. static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
  915. char *buf, size_t count,
  916. loff_t *ppos)
  917. {
  918. struct iwl_rx_cmd_buffer rxb = {
  919. ._rx_page_order = 0,
  920. .truesize = 0, /* not used */
  921. ._offset = 0,
  922. };
  923. struct iwl_rx_packet *pkt;
  924. struct iwl_rx_mpdu_desc *desc;
  925. int bin_len = count / 2;
  926. int ret = -EINVAL;
  927. if (!iwl_mvm_firmware_running(mvm))
  928. return -EIO;
  929. /* supporting only 9000 descriptor */
  930. if (!mvm->trans->cfg->mq_rx_supported)
  931. return -ENOTSUPP;
  932. rxb._page = alloc_pages(GFP_ATOMIC, 0);
  933. if (!rxb._page)
  934. return -ENOMEM;
  935. pkt = rxb_addr(&rxb);
  936. ret = hex2bin(page_address(rxb._page), buf, bin_len);
  937. if (ret)
  938. goto out;
  939. /* avoid invalid memory access */
  940. if (bin_len < sizeof(*pkt) + sizeof(*desc))
  941. goto out;
  942. /* check this is RX packet */
  943. if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
  944. WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
  945. goto out;
  946. /* check the length in metadata matches actual received length */
  947. desc = (void *)pkt->data;
  948. if (le16_to_cpu(desc->mpdu_len) !=
  949. (bin_len - sizeof(*desc) - sizeof(*pkt)))
  950. goto out;
  951. local_bh_disable();
  952. iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
  953. local_bh_enable();
  954. ret = 0;
  955. out:
  956. iwl_free_rxb(&rxb);
  957. return ret ?: count;
  958. }
  959. static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
  960. char __user *user_buf,
  961. size_t count, loff_t *ppos)
  962. {
  963. struct iwl_mvm *mvm = file->private_data;
  964. int conf;
  965. char buf[8];
  966. const size_t bufsz = sizeof(buf);
  967. int pos = 0;
  968. mutex_lock(&mvm->mutex);
  969. conf = mvm->fwrt.dump.conf;
  970. mutex_unlock(&mvm->mutex);
  971. pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
  972. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  973. }
  974. /*
  975. * Enable / Disable continuous recording.
  976. * Cause the FW to start continuous recording, by sending the relevant hcmd.
  977. * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
  978. * Disable: for 0 as input, DISABLE_CONT_RECORDING.
  979. */
  980. static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
  981. char *buf, size_t count,
  982. loff_t *ppos)
  983. {
  984. struct iwl_trans *trans = mvm->trans;
  985. const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
  986. struct iwl_continuous_record_cmd cont_rec = {};
  987. int ret, rec_mode;
  988. if (!iwl_mvm_firmware_running(mvm))
  989. return -EIO;
  990. if (!dest)
  991. return -EOPNOTSUPP;
  992. if (dest->monitor_mode != SMEM_MODE ||
  993. trans->cfg->device_family < IWL_DEVICE_FAMILY_8000)
  994. return -EOPNOTSUPP;
  995. ret = kstrtoint(buf, 0, &rec_mode);
  996. if (ret)
  997. return ret;
  998. cont_rec.record_mode.enable_recording = rec_mode ?
  999. cpu_to_le16(ENABLE_CONT_RECORDING) :
  1000. cpu_to_le16(DISABLE_CONT_RECORDING);
  1001. mutex_lock(&mvm->mutex);
  1002. ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
  1003. sizeof(cont_rec), &cont_rec);
  1004. mutex_unlock(&mvm->mutex);
  1005. return ret ?: count;
  1006. }
  1007. static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
  1008. char *buf, size_t count,
  1009. loff_t *ppos)
  1010. {
  1011. unsigned int conf_id;
  1012. int ret;
  1013. if (!iwl_mvm_firmware_running(mvm))
  1014. return -EIO;
  1015. ret = kstrtouint(buf, 0, &conf_id);
  1016. if (ret)
  1017. return ret;
  1018. if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
  1019. return -EINVAL;
  1020. mutex_lock(&mvm->mutex);
  1021. ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id);
  1022. mutex_unlock(&mvm->mutex);
  1023. return ret ?: count;
  1024. }
  1025. static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
  1026. char *buf, size_t count,
  1027. loff_t *ppos)
  1028. {
  1029. int ret;
  1030. if (!iwl_mvm_firmware_running(mvm))
  1031. return -EIO;
  1032. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  1033. if (ret)
  1034. return ret;
  1035. if (count == 0)
  1036. return 0;
  1037. iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf,
  1038. (count - 1), NULL);
  1039. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  1040. return count;
  1041. }
  1042. static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
  1043. char *buf, size_t count,
  1044. loff_t *ppos)
  1045. {
  1046. unsigned int max_amsdu_len;
  1047. int ret;
  1048. ret = kstrtouint(buf, 0, &max_amsdu_len);
  1049. if (ret)
  1050. return ret;
  1051. if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
  1052. return -EINVAL;
  1053. mvm->max_amsdu_len = max_amsdu_len;
  1054. return count;
  1055. }
  1056. #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
  1057. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1058. static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
  1059. char __user *user_buf,
  1060. size_t count, loff_t *ppos)
  1061. {
  1062. struct iwl_mvm *mvm = file->private_data;
  1063. struct iwl_bcast_filter_cmd cmd;
  1064. const struct iwl_fw_bcast_filter *filter;
  1065. char *buf;
  1066. int bufsz = 1024;
  1067. int i, j, pos = 0;
  1068. ssize_t ret;
  1069. buf = kzalloc(bufsz, GFP_KERNEL);
  1070. if (!buf)
  1071. return -ENOMEM;
  1072. mutex_lock(&mvm->mutex);
  1073. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  1074. ADD_TEXT("None\n");
  1075. mutex_unlock(&mvm->mutex);
  1076. goto out;
  1077. }
  1078. mutex_unlock(&mvm->mutex);
  1079. for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
  1080. filter = &cmd.filters[i];
  1081. ADD_TEXT("Filter [%d]:\n", i);
  1082. ADD_TEXT("\tDiscard=%d\n", filter->discard);
  1083. ADD_TEXT("\tFrame Type: %s\n",
  1084. filter->frame_type ? "IPv4" : "Generic");
  1085. for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
  1086. const struct iwl_fw_bcast_filter_attr *attr;
  1087. attr = &filter->attrs[j];
  1088. if (!attr->mask)
  1089. break;
  1090. ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
  1091. j, attr->offset,
  1092. attr->offset_type ? "IP End" :
  1093. "Payload Start",
  1094. be32_to_cpu(attr->mask),
  1095. be32_to_cpu(attr->val),
  1096. le16_to_cpu(attr->reserved1));
  1097. }
  1098. }
  1099. out:
  1100. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1101. kfree(buf);
  1102. return ret;
  1103. }
  1104. static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
  1105. size_t count, loff_t *ppos)
  1106. {
  1107. int pos, next_pos;
  1108. struct iwl_fw_bcast_filter filter = {};
  1109. struct iwl_bcast_filter_cmd cmd;
  1110. u32 filter_id, attr_id, mask, value;
  1111. int err = 0;
  1112. if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
  1113. &filter.frame_type, &pos) != 3)
  1114. return -EINVAL;
  1115. if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
  1116. filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
  1117. return -EINVAL;
  1118. for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
  1119. attr_id++) {
  1120. struct iwl_fw_bcast_filter_attr *attr =
  1121. &filter.attrs[attr_id];
  1122. if (pos >= count)
  1123. break;
  1124. if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
  1125. &attr->offset, &attr->offset_type,
  1126. &mask, &value, &next_pos) != 4)
  1127. return -EINVAL;
  1128. attr->mask = cpu_to_be32(mask);
  1129. attr->val = cpu_to_be32(value);
  1130. if (mask)
  1131. filter.num_attrs++;
  1132. pos += next_pos;
  1133. }
  1134. mutex_lock(&mvm->mutex);
  1135. memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
  1136. &filter, sizeof(filter));
  1137. /* send updated bcast filtering configuration */
  1138. if (iwl_mvm_firmware_running(mvm) &&
  1139. mvm->dbgfs_bcast_filtering.override &&
  1140. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  1141. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  1142. sizeof(cmd), &cmd);
  1143. mutex_unlock(&mvm->mutex);
  1144. return err ?: count;
  1145. }
  1146. static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
  1147. char __user *user_buf,
  1148. size_t count, loff_t *ppos)
  1149. {
  1150. struct iwl_mvm *mvm = file->private_data;
  1151. struct iwl_bcast_filter_cmd cmd;
  1152. char *buf;
  1153. int bufsz = 1024;
  1154. int i, pos = 0;
  1155. ssize_t ret;
  1156. buf = kzalloc(bufsz, GFP_KERNEL);
  1157. if (!buf)
  1158. return -ENOMEM;
  1159. mutex_lock(&mvm->mutex);
  1160. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  1161. ADD_TEXT("None\n");
  1162. mutex_unlock(&mvm->mutex);
  1163. goto out;
  1164. }
  1165. mutex_unlock(&mvm->mutex);
  1166. for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
  1167. const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
  1168. ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
  1169. i, mac->default_discard, mac->attached_filters);
  1170. }
  1171. out:
  1172. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1173. kfree(buf);
  1174. return ret;
  1175. }
  1176. static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
  1177. char *buf, size_t count,
  1178. loff_t *ppos)
  1179. {
  1180. struct iwl_bcast_filter_cmd cmd;
  1181. struct iwl_fw_bcast_mac mac = {};
  1182. u32 mac_id, attached_filters;
  1183. int err = 0;
  1184. if (!mvm->bcast_filters)
  1185. return -ENOENT;
  1186. if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
  1187. &attached_filters) != 3)
  1188. return -EINVAL;
  1189. if (mac_id >= ARRAY_SIZE(cmd.macs) ||
  1190. mac.default_discard > 1 ||
  1191. attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
  1192. return -EINVAL;
  1193. mac.attached_filters = cpu_to_le16(attached_filters);
  1194. mutex_lock(&mvm->mutex);
  1195. memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
  1196. &mac, sizeof(mac));
  1197. /* send updated bcast filtering configuration */
  1198. if (iwl_mvm_firmware_running(mvm) &&
  1199. mvm->dbgfs_bcast_filtering.override &&
  1200. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  1201. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  1202. sizeof(cmd), &cmd);
  1203. mutex_unlock(&mvm->mutex);
  1204. return err ?: count;
  1205. }
  1206. #endif
  1207. #ifdef CONFIG_PM_SLEEP
  1208. static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
  1209. size_t count, loff_t *ppos)
  1210. {
  1211. int store;
  1212. if (sscanf(buf, "%d", &store) != 1)
  1213. return -EINVAL;
  1214. mvm->store_d3_resume_sram = store;
  1215. return count;
  1216. }
  1217. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  1218. size_t count, loff_t *ppos)
  1219. {
  1220. struct iwl_mvm *mvm = file->private_data;
  1221. const struct fw_img *img;
  1222. int ofs, len, pos = 0;
  1223. size_t bufsz, ret;
  1224. char *buf;
  1225. u8 *ptr = mvm->d3_resume_sram;
  1226. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  1227. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  1228. bufsz = len * 4 + 256;
  1229. buf = kzalloc(bufsz, GFP_KERNEL);
  1230. if (!buf)
  1231. return -ENOMEM;
  1232. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  1233. mvm->store_d3_resume_sram ? "en" : "dis");
  1234. if (ptr) {
  1235. for (ofs = 0; ofs < len; ofs += 16) {
  1236. pos += scnprintf(buf + pos, bufsz - pos,
  1237. "0x%.4x %16ph\n", ofs, ptr + ofs);
  1238. }
  1239. } else {
  1240. pos += scnprintf(buf + pos, bufsz - pos,
  1241. "(no data captured)\n");
  1242. }
  1243. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1244. kfree(buf);
  1245. return ret;
  1246. }
  1247. #endif
  1248. #define PRINT_MVM_REF(ref) do { \
  1249. if (mvm->refs[ref]) \
  1250. pos += scnprintf(buf + pos, bufsz - pos, \
  1251. "\t(0x%lx): %d %s\n", \
  1252. BIT(ref), mvm->refs[ref], #ref); \
  1253. } while (0)
  1254. static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
  1255. char __user *user_buf,
  1256. size_t count, loff_t *ppos)
  1257. {
  1258. struct iwl_mvm *mvm = file->private_data;
  1259. int i, pos = 0;
  1260. char buf[256];
  1261. const size_t bufsz = sizeof(buf);
  1262. u32 refs = 0;
  1263. for (i = 0; i < IWL_MVM_REF_COUNT; i++)
  1264. if (mvm->refs[i])
  1265. refs |= BIT(i);
  1266. pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
  1267. refs);
  1268. PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
  1269. PRINT_MVM_REF(IWL_MVM_REF_SCAN);
  1270. PRINT_MVM_REF(IWL_MVM_REF_ROC);
  1271. PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
  1272. PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
  1273. PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
  1274. PRINT_MVM_REF(IWL_MVM_REF_USER);
  1275. PRINT_MVM_REF(IWL_MVM_REF_TX);
  1276. PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
  1277. PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
  1278. PRINT_MVM_REF(IWL_MVM_REF_START_AP);
  1279. PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
  1280. PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
  1281. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
  1282. PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
  1283. PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
  1284. PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
  1285. PRINT_MVM_REF(IWL_MVM_REF_NMI);
  1286. PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
  1287. PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
  1288. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
  1289. PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
  1290. PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
  1291. PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
  1292. PRINT_MVM_REF(IWL_MVM_REF_RX);
  1293. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1294. }
  1295. static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
  1296. size_t count, loff_t *ppos)
  1297. {
  1298. unsigned long value;
  1299. int ret;
  1300. bool taken;
  1301. ret = kstrtoul(buf, 10, &value);
  1302. if (ret < 0)
  1303. return ret;
  1304. mutex_lock(&mvm->mutex);
  1305. taken = mvm->refs[IWL_MVM_REF_USER];
  1306. if (value == 1 && !taken)
  1307. iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
  1308. else if (value == 0 && taken)
  1309. iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
  1310. else
  1311. ret = -EINVAL;
  1312. mutex_unlock(&mvm->mutex);
  1313. if (ret < 0)
  1314. return ret;
  1315. return count;
  1316. }
  1317. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1318. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1319. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1320. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1321. #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
  1322. if (!debugfs_create_file(alias, mode, parent, mvm, \
  1323. &iwl_dbgfs_##name##_ops)) \
  1324. goto err; \
  1325. } while (0)
  1326. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
  1327. MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
  1328. static ssize_t
  1329. iwl_dbgfs_prph_reg_read(struct file *file,
  1330. char __user *user_buf,
  1331. size_t count, loff_t *ppos)
  1332. {
  1333. struct iwl_mvm *mvm = file->private_data;
  1334. int pos = 0;
  1335. char buf[32];
  1336. const size_t bufsz = sizeof(buf);
  1337. int ret;
  1338. if (!mvm->dbgfs_prph_reg_addr)
  1339. return -EINVAL;
  1340. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
  1341. if (ret)
  1342. return ret;
  1343. pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
  1344. mvm->dbgfs_prph_reg_addr,
  1345. iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
  1346. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
  1347. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1348. }
  1349. static ssize_t
  1350. iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
  1351. size_t count, loff_t *ppos)
  1352. {
  1353. u8 args;
  1354. u32 value;
  1355. int ret;
  1356. args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
  1357. /* if we only want to set the reg address - nothing more to do */
  1358. if (args == 1)
  1359. goto out;
  1360. /* otherwise, make sure we have both address and value */
  1361. if (args != 2)
  1362. return -EINVAL;
  1363. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  1364. if (ret)
  1365. return ret;
  1366. iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
  1367. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  1368. out:
  1369. return count;
  1370. }
  1371. static ssize_t
  1372. iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
  1373. size_t count, loff_t *ppos)
  1374. {
  1375. int ret;
  1376. if (!iwl_mvm_firmware_running(mvm))
  1377. return -EIO;
  1378. mutex_lock(&mvm->mutex);
  1379. ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
  1380. mutex_unlock(&mvm->mutex);
  1381. return ret ?: count;
  1382. }
  1383. MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
  1384. /* Device wide debugfs entries */
  1385. MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
  1386. MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
  1387. MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8);
  1388. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
  1389. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
  1390. MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
  1391. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
  1392. MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
  1393. MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
  1394. MVM_DEBUGFS_READ_FILE_OPS(stations);
  1395. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  1396. MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
  1397. MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
  1398. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  1399. MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
  1400. MVM_DEBUGFS_READ_FILE_OPS(fw_ver);
  1401. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
  1402. MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
  1403. MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
  1404. MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
  1405. MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
  1406. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
  1407. MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
  1408. MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
  1409. MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
  1410. MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
  1411. MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
  1412. (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
  1413. MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
  1414. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1415. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
  1416. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
  1417. #endif
  1418. #ifdef CONFIG_PM_SLEEP
  1419. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
  1420. #endif
  1421. #ifdef CONFIG_ACPI
  1422. MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile);
  1423. #endif
  1424. static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
  1425. size_t count, loff_t *ppos)
  1426. {
  1427. struct iwl_mvm *mvm = file->private_data;
  1428. struct iwl_dbg_mem_access_cmd cmd = {};
  1429. struct iwl_dbg_mem_access_rsp *rsp;
  1430. struct iwl_host_cmd hcmd = {
  1431. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1432. .data = { &cmd, },
  1433. .len = { sizeof(cmd) },
  1434. };
  1435. size_t delta;
  1436. ssize_t ret, len;
  1437. if (!iwl_mvm_firmware_running(mvm))
  1438. return -EIO;
  1439. hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
  1440. DEBUG_GROUP, 0);
  1441. cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
  1442. /* Take care of alignment of both the position and the length */
  1443. delta = *ppos & 0x3;
  1444. cmd.addr = cpu_to_le32(*ppos - delta);
  1445. cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
  1446. (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
  1447. mutex_lock(&mvm->mutex);
  1448. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1449. mutex_unlock(&mvm->mutex);
  1450. if (ret < 0)
  1451. return ret;
  1452. rsp = (void *)hcmd.resp_pkt->data;
  1453. if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
  1454. ret = -ENXIO;
  1455. goto out;
  1456. }
  1457. len = min((size_t)le32_to_cpu(rsp->len) << 2,
  1458. iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
  1459. len = min(len - delta, count);
  1460. if (len < 0) {
  1461. ret = -EFAULT;
  1462. goto out;
  1463. }
  1464. ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
  1465. *ppos += ret;
  1466. out:
  1467. iwl_free_resp(&hcmd);
  1468. return ret;
  1469. }
  1470. static ssize_t iwl_dbgfs_mem_write(struct file *file,
  1471. const char __user *user_buf, size_t count,
  1472. loff_t *ppos)
  1473. {
  1474. struct iwl_mvm *mvm = file->private_data;
  1475. struct iwl_dbg_mem_access_cmd *cmd;
  1476. struct iwl_dbg_mem_access_rsp *rsp;
  1477. struct iwl_host_cmd hcmd = {};
  1478. size_t cmd_size;
  1479. size_t data_size;
  1480. u32 op, len;
  1481. ssize_t ret;
  1482. if (!iwl_mvm_firmware_running(mvm))
  1483. return -EIO;
  1484. hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
  1485. DEBUG_GROUP, 0);
  1486. if (*ppos & 0x3 || count < 4) {
  1487. op = DEBUG_MEM_OP_WRITE_BYTES;
  1488. len = min(count, (size_t)(4 - (*ppos & 0x3)));
  1489. data_size = len;
  1490. } else {
  1491. op = DEBUG_MEM_OP_WRITE;
  1492. len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
  1493. data_size = len << 2;
  1494. }
  1495. cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
  1496. cmd = kzalloc(cmd_size, GFP_KERNEL);
  1497. if (!cmd)
  1498. return -ENOMEM;
  1499. cmd->op = cpu_to_le32(op);
  1500. cmd->len = cpu_to_le32(len);
  1501. cmd->addr = cpu_to_le32(*ppos);
  1502. if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
  1503. kfree(cmd);
  1504. return -EFAULT;
  1505. }
  1506. hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1507. hcmd.data[0] = (void *)cmd;
  1508. hcmd.len[0] = cmd_size;
  1509. mutex_lock(&mvm->mutex);
  1510. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1511. mutex_unlock(&mvm->mutex);
  1512. kfree(cmd);
  1513. if (ret < 0)
  1514. return ret;
  1515. rsp = (void *)hcmd.resp_pkt->data;
  1516. if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
  1517. ret = -ENXIO;
  1518. goto out;
  1519. }
  1520. ret = data_size;
  1521. *ppos += ret;
  1522. out:
  1523. iwl_free_resp(&hcmd);
  1524. return ret;
  1525. }
  1526. static const struct file_operations iwl_dbgfs_mem_ops = {
  1527. .read = iwl_dbgfs_mem_read,
  1528. .write = iwl_dbgfs_mem_write,
  1529. .open = simple_open,
  1530. .llseek = default_llseek,
  1531. };
  1532. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  1533. {
  1534. struct dentry *bcast_dir __maybe_unused;
  1535. char buf[100];
  1536. spin_lock_init(&mvm->drv_stats_lock);
  1537. mvm->debugfs_dir = dbgfs_dir;
  1538. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  1539. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  1540. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1541. MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
  1542. S_IWUSR | S_IRUSR);
  1543. MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
  1544. MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
  1545. MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
  1546. MVM_DEBUGFS_ADD_FILE(force_ctkill, dbgfs_dir, S_IWUSR);
  1547. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  1548. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  1549. MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
  1550. MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
  1551. S_IRUSR | S_IWUSR);
  1552. MVM_DEBUGFS_ADD_FILE(fw_ver, mvm->debugfs_dir, S_IRUSR);
  1553. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1554. MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1555. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  1556. MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
  1557. MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
  1558. MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
  1559. MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
  1560. S_IWUSR | S_IRUSR);
  1561. MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1562. MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1563. MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1564. MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
  1565. MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
  1566. MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
  1567. MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
  1568. MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
  1569. MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, S_IWUSR);
  1570. #ifdef CONFIG_ACPI
  1571. MVM_DEBUGFS_ADD_FILE(sar_geo_profile, dbgfs_dir, S_IRUSR);
  1572. #endif
  1573. if (!debugfs_create_bool("enable_scan_iteration_notif",
  1574. S_IRUSR | S_IWUSR,
  1575. mvm->debugfs_dir,
  1576. &mvm->scan_iter_notif_enabled))
  1577. goto err;
  1578. if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
  1579. mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
  1580. goto err;
  1581. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1582. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
  1583. bcast_dir = debugfs_create_dir("bcast_filtering",
  1584. mvm->debugfs_dir);
  1585. if (!bcast_dir)
  1586. goto err;
  1587. if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
  1588. bcast_dir,
  1589. &mvm->dbgfs_bcast_filtering.override))
  1590. goto err;
  1591. MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
  1592. bcast_dir, S_IWUSR | S_IRUSR);
  1593. MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
  1594. bcast_dir, S_IWUSR | S_IRUSR);
  1595. }
  1596. #endif
  1597. #ifdef CONFIG_PM_SLEEP
  1598. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1599. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  1600. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  1601. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  1602. goto err;
  1603. if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
  1604. mvm->debugfs_dir, &mvm->last_netdetect_scans))
  1605. goto err;
  1606. #endif
  1607. if (!debugfs_create_u8("ps_disabled", S_IRUSR,
  1608. mvm->debugfs_dir, &mvm->ps_disabled))
  1609. goto err;
  1610. if (!debugfs_create_blob("nvm_hw", S_IRUSR,
  1611. mvm->debugfs_dir, &mvm->nvm_hw_blob))
  1612. goto err;
  1613. if (!debugfs_create_blob("nvm_sw", S_IRUSR,
  1614. mvm->debugfs_dir, &mvm->nvm_sw_blob))
  1615. goto err;
  1616. if (!debugfs_create_blob("nvm_calib", S_IRUSR,
  1617. mvm->debugfs_dir, &mvm->nvm_calib_blob))
  1618. goto err;
  1619. if (!debugfs_create_blob("nvm_prod", S_IRUSR,
  1620. mvm->debugfs_dir, &mvm->nvm_prod_blob))
  1621. goto err;
  1622. if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
  1623. mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
  1624. goto err;
  1625. debugfs_create_file("mem", S_IRUSR | S_IWUSR, dbgfs_dir, mvm,
  1626. &iwl_dbgfs_mem_ops);
  1627. /*
  1628. * Create a symlink with mac80211. It will be removed when mac80211
  1629. * exists (before the opmode exists which removes the target.)
  1630. */
  1631. snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
  1632. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  1633. goto err;
  1634. return 0;
  1635. err:
  1636. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  1637. return -ENOMEM;
  1638. }