debugfs.c 49 KB

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