debugfs.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/vmalloc.h>
  66. #include "mvm.h"
  67. #include "sta.h"
  68. #include "iwl-io.h"
  69. #include "debugfs.h"
  70. #include "iwl-fw-error-dump.h"
  71. static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
  72. size_t count, loff_t *ppos)
  73. {
  74. int ret;
  75. u32 scd_q_msk;
  76. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  77. return -EIO;
  78. if (sscanf(buf, "%x", &scd_q_msk) != 1)
  79. return -EINVAL;
  80. IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
  81. mutex_lock(&mvm->mutex);
  82. ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
  83. mutex_unlock(&mvm->mutex);
  84. return ret;
  85. }
  86. static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
  87. size_t count, loff_t *ppos)
  88. {
  89. struct iwl_mvm_sta *mvmsta;
  90. int sta_id, drain, ret;
  91. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  92. return -EIO;
  93. if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
  94. return -EINVAL;
  95. if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
  96. return -EINVAL;
  97. if (drain < 0 || drain > 1)
  98. return -EINVAL;
  99. mutex_lock(&mvm->mutex);
  100. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  101. if (!mvmsta)
  102. ret = -ENOENT;
  103. else
  104. ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
  105. mutex_unlock(&mvm->mutex);
  106. return ret;
  107. }
  108. static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
  109. size_t count, loff_t *ppos)
  110. {
  111. struct iwl_mvm *mvm = file->private_data;
  112. const struct fw_img *img;
  113. unsigned int ofs, len;
  114. size_t ret;
  115. u8 *ptr;
  116. if (!mvm->ucode_loaded)
  117. return -EINVAL;
  118. /* default is to dump the entire data segment */
  119. img = &mvm->fw->img[mvm->cur_ucode];
  120. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  121. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  122. if (mvm->dbgfs_sram_len) {
  123. ofs = mvm->dbgfs_sram_offset;
  124. len = mvm->dbgfs_sram_len;
  125. }
  126. ptr = kzalloc(len, GFP_KERNEL);
  127. if (!ptr)
  128. return -ENOMEM;
  129. iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
  130. ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
  131. kfree(ptr);
  132. return ret;
  133. }
  134. static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
  135. size_t count, loff_t *ppos)
  136. {
  137. const struct fw_img *img;
  138. u32 offset, len;
  139. u32 img_offset, img_len;
  140. if (!mvm->ucode_loaded)
  141. return -EINVAL;
  142. img = &mvm->fw->img[mvm->cur_ucode];
  143. img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
  144. img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  145. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  146. if ((offset & 0x3) || (len & 0x3))
  147. return -EINVAL;
  148. if (offset + len > img_offset + img_len)
  149. return -EINVAL;
  150. mvm->dbgfs_sram_offset = offset;
  151. mvm->dbgfs_sram_len = len;
  152. } else {
  153. mvm->dbgfs_sram_offset = 0;
  154. mvm->dbgfs_sram_len = 0;
  155. }
  156. return count;
  157. }
  158. static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
  159. char __user *user_buf,
  160. size_t count, loff_t *ppos)
  161. {
  162. struct iwl_mvm *mvm = file->private_data;
  163. char buf[16];
  164. int pos;
  165. if (!mvm->temperature_test)
  166. pos = scnprintf(buf , sizeof(buf), "disabled\n");
  167. else
  168. pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
  169. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  170. }
  171. /*
  172. * Set NIC Temperature
  173. * Cause the driver to ignore the actual NIC temperature reported by the FW
  174. * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
  175. * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
  176. * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
  177. */
  178. static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
  179. char *buf, size_t count,
  180. loff_t *ppos)
  181. {
  182. int temperature;
  183. if (!mvm->ucode_loaded && !mvm->temperature_test)
  184. return -EIO;
  185. if (kstrtoint(buf, 10, &temperature))
  186. return -EINVAL;
  187. /* not a legal temperature */
  188. if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
  189. temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
  190. temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
  191. return -EINVAL;
  192. mutex_lock(&mvm->mutex);
  193. if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
  194. if (!mvm->temperature_test)
  195. goto out;
  196. mvm->temperature_test = false;
  197. /* Since we can't read the temp while awake, just set
  198. * it to zero until we get the next RX stats from the
  199. * firmware.
  200. */
  201. mvm->temperature = 0;
  202. } else {
  203. mvm->temperature_test = true;
  204. mvm->temperature = temperature;
  205. }
  206. IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
  207. mvm->temperature_test ? "En" : "Dis" ,
  208. mvm->temperature);
  209. /* handle the temperature change */
  210. iwl_mvm_tt_handler(mvm);
  211. out:
  212. mutex_unlock(&mvm->mutex);
  213. return count;
  214. }
  215. static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
  216. char __user *user_buf,
  217. size_t count, loff_t *ppos)
  218. {
  219. struct iwl_mvm *mvm = file->private_data;
  220. char buf[16];
  221. int pos, temp;
  222. if (!mvm->ucode_loaded)
  223. return -EIO;
  224. mutex_lock(&mvm->mutex);
  225. temp = iwl_mvm_get_temp(mvm);
  226. mutex_unlock(&mvm->mutex);
  227. if (temp < 0)
  228. return temp;
  229. pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
  230. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  231. }
  232. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  233. size_t count, loff_t *ppos)
  234. {
  235. struct iwl_mvm *mvm = file->private_data;
  236. struct ieee80211_sta *sta;
  237. char buf[400];
  238. int i, pos = 0, bufsz = sizeof(buf);
  239. mutex_lock(&mvm->mutex);
  240. for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
  241. pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
  242. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  243. lockdep_is_held(&mvm->mutex));
  244. if (!sta)
  245. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  246. else if (IS_ERR(sta))
  247. pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
  248. PTR_ERR(sta));
  249. else
  250. pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
  251. sta->addr);
  252. }
  253. mutex_unlock(&mvm->mutex);
  254. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  255. }
  256. static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
  257. char __user *user_buf,
  258. size_t count, loff_t *ppos)
  259. {
  260. struct iwl_mvm *mvm = file->private_data;
  261. char buf[64];
  262. int bufsz = sizeof(buf);
  263. int pos = 0;
  264. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
  265. mvm->disable_power_off);
  266. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
  267. mvm->disable_power_off_d3);
  268. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  269. }
  270. static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. int ret, val;
  274. if (!mvm->ucode_loaded)
  275. return -EIO;
  276. if (!strncmp("disable_power_off_d0=", buf, 21)) {
  277. if (sscanf(buf + 21, "%d", &val) != 1)
  278. return -EINVAL;
  279. mvm->disable_power_off = val;
  280. } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
  281. if (sscanf(buf + 21, "%d", &val) != 1)
  282. return -EINVAL;
  283. mvm->disable_power_off_d3 = val;
  284. } else {
  285. return -EINVAL;
  286. }
  287. mutex_lock(&mvm->mutex);
  288. ret = iwl_mvm_power_update_device(mvm);
  289. mutex_unlock(&mvm->mutex);
  290. return ret ?: count;
  291. }
  292. #define BT_MBOX_MSG(_notif, _num, _field) \
  293. ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
  294. >> BT_MBOX##_num##_##_field##_POS)
  295. #define BT_MBOX_PRINT(_num, _field, _end) \
  296. pos += scnprintf(buf + pos, bufsz - pos, \
  297. "\t%s: %d%s", \
  298. #_field, \
  299. BT_MBOX_MSG(notif, _num, _field), \
  300. true ? "\n" : ", ");
  301. static
  302. int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
  303. int pos, int bufsz)
  304. {
  305. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  306. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  307. BT_MBOX_PRINT(0, LE_PROF1, false);
  308. BT_MBOX_PRINT(0, LE_PROF2, false);
  309. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  310. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  311. BT_MBOX_PRINT(0, INBAND_S, false);
  312. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  313. BT_MBOX_PRINT(0, LE_SCAN, false);
  314. BT_MBOX_PRINT(0, LE_ADV, false);
  315. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  316. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  317. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  318. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  319. BT_MBOX_PRINT(1, IP_SR, false);
  320. BT_MBOX_PRINT(1, LE_MSTR, false);
  321. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  322. BT_MBOX_PRINT(1, MSG_TYPE, false);
  323. BT_MBOX_PRINT(1, SSN, true);
  324. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  325. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  326. BT_MBOX_PRINT(2, PAG, false);
  327. BT_MBOX_PRINT(2, INQUIRY, false);
  328. BT_MBOX_PRINT(2, CONN, false);
  329. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  330. BT_MBOX_PRINT(2, DISC, false);
  331. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  332. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  333. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  334. BT_MBOX_PRINT(2, SCO_DURATION, true);
  335. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  336. BT_MBOX_PRINT(3, SCO_STATE, false);
  337. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  338. BT_MBOX_PRINT(3, A2DP_STATE, false);
  339. BT_MBOX_PRINT(3, ACL_STATE, false);
  340. BT_MBOX_PRINT(3, MSTR_STATE, false);
  341. BT_MBOX_PRINT(3, OBX_STATE, false);
  342. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  343. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  344. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  345. BT_MBOX_PRINT(3, INBAND_P, false);
  346. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  347. BT_MBOX_PRINT(3, SSN_2, false);
  348. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  349. return pos;
  350. }
  351. static
  352. int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
  353. char *buf, int pos, int bufsz)
  354. {
  355. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  356. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  357. BT_MBOX_PRINT(0, LE_PROF1, false);
  358. BT_MBOX_PRINT(0, LE_PROF2, false);
  359. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  360. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  361. BT_MBOX_PRINT(0, INBAND_S, false);
  362. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  363. BT_MBOX_PRINT(0, LE_SCAN, false);
  364. BT_MBOX_PRINT(0, LE_ADV, false);
  365. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  366. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  367. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  368. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  369. BT_MBOX_PRINT(1, IP_SR, false);
  370. BT_MBOX_PRINT(1, LE_MSTR, false);
  371. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  372. BT_MBOX_PRINT(1, MSG_TYPE, false);
  373. BT_MBOX_PRINT(1, SSN, true);
  374. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  375. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  376. BT_MBOX_PRINT(2, PAG, false);
  377. BT_MBOX_PRINT(2, INQUIRY, false);
  378. BT_MBOX_PRINT(2, CONN, false);
  379. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  380. BT_MBOX_PRINT(2, DISC, false);
  381. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  382. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  383. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  384. BT_MBOX_PRINT(2, SCO_DURATION, true);
  385. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  386. BT_MBOX_PRINT(3, SCO_STATE, false);
  387. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  388. BT_MBOX_PRINT(3, A2DP_STATE, false);
  389. BT_MBOX_PRINT(3, ACL_STATE, false);
  390. BT_MBOX_PRINT(3, MSTR_STATE, false);
  391. BT_MBOX_PRINT(3, OBX_STATE, false);
  392. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  393. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  394. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  395. BT_MBOX_PRINT(3, INBAND_P, false);
  396. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  397. BT_MBOX_PRINT(3, SSN_2, false);
  398. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  399. return pos;
  400. }
  401. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  402. size_t count, loff_t *ppos)
  403. {
  404. struct iwl_mvm *mvm = file->private_data;
  405. char *buf;
  406. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  407. buf = kmalloc(bufsz, GFP_KERNEL);
  408. if (!buf)
  409. return -ENOMEM;
  410. mutex_lock(&mvm->mutex);
  411. if (!fw_has_api(&mvm->fw->ucode_capa,
  412. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  413. struct iwl_bt_coex_profile_notif_old *notif =
  414. &mvm->last_bt_notif_old;
  415. pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
  416. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  417. notif->bt_ci_compliance);
  418. pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
  419. le32_to_cpu(notif->primary_ch_lut));
  420. pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
  421. le32_to_cpu(notif->secondary_ch_lut));
  422. pos += scnprintf(buf+pos,
  423. bufsz-pos, "bt_activity_grading = %d\n",
  424. le32_to_cpu(notif->bt_activity_grading));
  425. pos += scnprintf(buf+pos, bufsz-pos,
  426. "antenna isolation = %d CORUN LUT index = %d\n",
  427. mvm->last_ant_isol, mvm->last_corun_lut);
  428. } else {
  429. struct iwl_bt_coex_profile_notif *notif =
  430. &mvm->last_bt_notif;
  431. pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
  432. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  433. notif->bt_ci_compliance);
  434. pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
  435. le32_to_cpu(notif->primary_ch_lut));
  436. pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
  437. le32_to_cpu(notif->secondary_ch_lut));
  438. pos += scnprintf(buf+pos,
  439. bufsz-pos, "bt_activity_grading = %d\n",
  440. le32_to_cpu(notif->bt_activity_grading));
  441. pos += scnprintf(buf+pos, bufsz-pos,
  442. "antenna isolation = %d CORUN LUT index = %d\n",
  443. mvm->last_ant_isol, mvm->last_corun_lut);
  444. }
  445. mutex_unlock(&mvm->mutex);
  446. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  447. kfree(buf);
  448. return ret;
  449. }
  450. #undef BT_MBOX_PRINT
  451. static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
  452. size_t count, loff_t *ppos)
  453. {
  454. struct iwl_mvm *mvm = file->private_data;
  455. char buf[256];
  456. int bufsz = sizeof(buf);
  457. int pos = 0;
  458. mutex_lock(&mvm->mutex);
  459. if (!fw_has_api(&mvm->fw->ucode_capa,
  460. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  461. struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
  462. pos += scnprintf(buf+pos, bufsz-pos,
  463. "Channel inhibition CMD\n");
  464. pos += scnprintf(buf+pos, bufsz-pos,
  465. "\tPrimary Channel Bitmap 0x%016llx\n",
  466. le64_to_cpu(cmd->bt_primary_ci));
  467. pos += scnprintf(buf+pos, bufsz-pos,
  468. "\tSecondary Channel Bitmap 0x%016llx\n",
  469. le64_to_cpu(cmd->bt_secondary_ci));
  470. pos += scnprintf(buf+pos, bufsz-pos,
  471. "BT Configuration CMD - 0=default, 1=never, 2=always\n");
  472. pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill msk idx %d\n",
  473. mvm->bt_ack_kill_msk[0]);
  474. pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill msk idx %d\n",
  475. mvm->bt_cts_kill_msk[0]);
  476. } else {
  477. struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
  478. pos += scnprintf(buf+pos, bufsz-pos,
  479. "Channel inhibition CMD\n");
  480. pos += scnprintf(buf+pos, bufsz-pos,
  481. "\tPrimary Channel Bitmap 0x%016llx\n",
  482. le64_to_cpu(cmd->bt_primary_ci));
  483. pos += scnprintf(buf+pos, bufsz-pos,
  484. "\tSecondary Channel Bitmap 0x%016llx\n",
  485. le64_to_cpu(cmd->bt_secondary_ci));
  486. }
  487. mutex_unlock(&mvm->mutex);
  488. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  489. }
  490. static ssize_t
  491. iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
  492. size_t count, loff_t *ppos)
  493. {
  494. u32 bt_tx_prio;
  495. if (sscanf(buf, "%u", &bt_tx_prio) != 1)
  496. return -EINVAL;
  497. if (bt_tx_prio > 4)
  498. return -EINVAL;
  499. mvm->bt_tx_prio = bt_tx_prio;
  500. return count;
  501. }
  502. static ssize_t
  503. iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
  504. size_t count, loff_t *ppos)
  505. {
  506. static const char * const modes_str[BT_FORCE_ANT_MAX] = {
  507. [BT_FORCE_ANT_DIS] = "dis",
  508. [BT_FORCE_ANT_AUTO] = "auto",
  509. [BT_FORCE_ANT_BT] = "bt",
  510. [BT_FORCE_ANT_WIFI] = "wifi",
  511. };
  512. int ret, bt_force_ant_mode;
  513. for (bt_force_ant_mode = 0;
  514. bt_force_ant_mode < ARRAY_SIZE(modes_str);
  515. bt_force_ant_mode++) {
  516. if (!strcmp(buf, modes_str[bt_force_ant_mode]))
  517. break;
  518. }
  519. if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
  520. return -EINVAL;
  521. ret = 0;
  522. mutex_lock(&mvm->mutex);
  523. if (mvm->bt_force_ant_mode == bt_force_ant_mode)
  524. goto out;
  525. mvm->bt_force_ant_mode = bt_force_ant_mode;
  526. IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
  527. modes_str[mvm->bt_force_ant_mode]);
  528. ret = iwl_send_bt_init_conf(mvm);
  529. out:
  530. mutex_unlock(&mvm->mutex);
  531. return ret ?: count;
  532. }
  533. #define PRINT_STATS_LE32(_struct, _memb) \
  534. pos += scnprintf(buf + pos, bufsz - pos, \
  535. fmt_table, #_memb, \
  536. le32_to_cpu(_struct->_memb))
  537. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  538. char __user *user_buf, size_t count,
  539. loff_t *ppos)
  540. {
  541. struct iwl_mvm *mvm = file->private_data;
  542. static const char *fmt_table = "\t%-30s %10u\n";
  543. static const char *fmt_header = "%-32s\n";
  544. int pos = 0;
  545. char *buf;
  546. int ret;
  547. /* 43 is the size of each data line, 33 is the size of each header */
  548. size_t bufsz =
  549. ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
  550. (4 * 33) + 1;
  551. struct mvm_statistics_rx_phy *ofdm;
  552. struct mvm_statistics_rx_phy *cck;
  553. struct mvm_statistics_rx_non_phy *general;
  554. struct mvm_statistics_rx_ht_phy *ht;
  555. buf = kzalloc(bufsz, GFP_KERNEL);
  556. if (!buf)
  557. return -ENOMEM;
  558. mutex_lock(&mvm->mutex);
  559. ofdm = &mvm->rx_stats.ofdm;
  560. cck = &mvm->rx_stats.cck;
  561. general = &mvm->rx_stats.general;
  562. ht = &mvm->rx_stats.ofdm_ht;
  563. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  564. "Statistics_Rx - OFDM");
  565. PRINT_STATS_LE32(ofdm, ina_cnt);
  566. PRINT_STATS_LE32(ofdm, fina_cnt);
  567. PRINT_STATS_LE32(ofdm, plcp_err);
  568. PRINT_STATS_LE32(ofdm, crc32_err);
  569. PRINT_STATS_LE32(ofdm, overrun_err);
  570. PRINT_STATS_LE32(ofdm, early_overrun_err);
  571. PRINT_STATS_LE32(ofdm, crc32_good);
  572. PRINT_STATS_LE32(ofdm, false_alarm_cnt);
  573. PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
  574. PRINT_STATS_LE32(ofdm, sfd_timeout);
  575. PRINT_STATS_LE32(ofdm, fina_timeout);
  576. PRINT_STATS_LE32(ofdm, unresponded_rts);
  577. PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
  578. PRINT_STATS_LE32(ofdm, sent_ack_cnt);
  579. PRINT_STATS_LE32(ofdm, sent_cts_cnt);
  580. PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
  581. PRINT_STATS_LE32(ofdm, dsp_self_kill);
  582. PRINT_STATS_LE32(ofdm, mh_format_err);
  583. PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
  584. PRINT_STATS_LE32(ofdm, reserved);
  585. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  586. "Statistics_Rx - CCK");
  587. PRINT_STATS_LE32(cck, ina_cnt);
  588. PRINT_STATS_LE32(cck, fina_cnt);
  589. PRINT_STATS_LE32(cck, plcp_err);
  590. PRINT_STATS_LE32(cck, crc32_err);
  591. PRINT_STATS_LE32(cck, overrun_err);
  592. PRINT_STATS_LE32(cck, early_overrun_err);
  593. PRINT_STATS_LE32(cck, crc32_good);
  594. PRINT_STATS_LE32(cck, false_alarm_cnt);
  595. PRINT_STATS_LE32(cck, fina_sync_err_cnt);
  596. PRINT_STATS_LE32(cck, sfd_timeout);
  597. PRINT_STATS_LE32(cck, fina_timeout);
  598. PRINT_STATS_LE32(cck, unresponded_rts);
  599. PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
  600. PRINT_STATS_LE32(cck, sent_ack_cnt);
  601. PRINT_STATS_LE32(cck, sent_cts_cnt);
  602. PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
  603. PRINT_STATS_LE32(cck, dsp_self_kill);
  604. PRINT_STATS_LE32(cck, mh_format_err);
  605. PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
  606. PRINT_STATS_LE32(cck, reserved);
  607. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  608. "Statistics_Rx - GENERAL");
  609. PRINT_STATS_LE32(general, bogus_cts);
  610. PRINT_STATS_LE32(general, bogus_ack);
  611. PRINT_STATS_LE32(general, non_bssid_frames);
  612. PRINT_STATS_LE32(general, filtered_frames);
  613. PRINT_STATS_LE32(general, non_channel_beacons);
  614. PRINT_STATS_LE32(general, channel_beacons);
  615. PRINT_STATS_LE32(general, num_missed_bcon);
  616. PRINT_STATS_LE32(general, adc_rx_saturation_time);
  617. PRINT_STATS_LE32(general, ina_detection_search_time);
  618. PRINT_STATS_LE32(general, beacon_silence_rssi_a);
  619. PRINT_STATS_LE32(general, beacon_silence_rssi_b);
  620. PRINT_STATS_LE32(general, beacon_silence_rssi_c);
  621. PRINT_STATS_LE32(general, interference_data_flag);
  622. PRINT_STATS_LE32(general, channel_load);
  623. PRINT_STATS_LE32(general, dsp_false_alarms);
  624. PRINT_STATS_LE32(general, beacon_rssi_a);
  625. PRINT_STATS_LE32(general, beacon_rssi_b);
  626. PRINT_STATS_LE32(general, beacon_rssi_c);
  627. PRINT_STATS_LE32(general, beacon_energy_a);
  628. PRINT_STATS_LE32(general, beacon_energy_b);
  629. PRINT_STATS_LE32(general, beacon_energy_c);
  630. PRINT_STATS_LE32(general, num_bt_kills);
  631. PRINT_STATS_LE32(general, mac_id);
  632. PRINT_STATS_LE32(general, directed_data_mpdu);
  633. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  634. "Statistics_Rx - HT");
  635. PRINT_STATS_LE32(ht, plcp_err);
  636. PRINT_STATS_LE32(ht, overrun_err);
  637. PRINT_STATS_LE32(ht, early_overrun_err);
  638. PRINT_STATS_LE32(ht, crc32_good);
  639. PRINT_STATS_LE32(ht, crc32_err);
  640. PRINT_STATS_LE32(ht, mh_format_err);
  641. PRINT_STATS_LE32(ht, agg_crc32_good);
  642. PRINT_STATS_LE32(ht, agg_mpdu_cnt);
  643. PRINT_STATS_LE32(ht, agg_cnt);
  644. PRINT_STATS_LE32(ht, unsupport_mcs);
  645. mutex_unlock(&mvm->mutex);
  646. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  647. kfree(buf);
  648. return ret;
  649. }
  650. #undef PRINT_STAT_LE32
  651. static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
  652. char __user *user_buf, size_t count,
  653. loff_t *ppos,
  654. struct iwl_mvm_frame_stats *stats)
  655. {
  656. char *buff, *pos, *endpos;
  657. int idx, i;
  658. int ret;
  659. static const size_t bufsz = 1024;
  660. buff = kmalloc(bufsz, GFP_KERNEL);
  661. if (!buff)
  662. return -ENOMEM;
  663. spin_lock_bh(&mvm->drv_stats_lock);
  664. pos = buff;
  665. endpos = pos + bufsz;
  666. pos += scnprintf(pos, endpos - pos,
  667. "Legacy/HT/VHT\t:\t%d/%d/%d\n",
  668. stats->legacy_frames,
  669. stats->ht_frames,
  670. stats->vht_frames);
  671. pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
  672. stats->bw_20_frames,
  673. stats->bw_40_frames,
  674. stats->bw_80_frames);
  675. pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
  676. stats->ngi_frames,
  677. stats->sgi_frames);
  678. pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
  679. stats->siso_frames,
  680. stats->mimo2_frames);
  681. pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
  682. stats->fail_frames,
  683. stats->success_frames);
  684. pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
  685. stats->agg_frames);
  686. pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
  687. stats->ampdu_count);
  688. pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
  689. stats->ampdu_count > 0 ?
  690. (stats->agg_frames / stats->ampdu_count) : 0);
  691. pos += scnprintf(pos, endpos - pos, "Last Rates\n");
  692. idx = stats->last_frame_idx - 1;
  693. for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
  694. idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
  695. if (stats->last_rates[idx] == 0)
  696. continue;
  697. pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
  698. (int)(ARRAY_SIZE(stats->last_rates) - i));
  699. pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
  700. }
  701. spin_unlock_bh(&mvm->drv_stats_lock);
  702. ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
  703. kfree(buff);
  704. return ret;
  705. }
  706. static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
  707. char __user *user_buf, size_t count,
  708. loff_t *ppos)
  709. {
  710. struct iwl_mvm *mvm = file->private_data;
  711. return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
  712. &mvm->drv_rx_stats);
  713. }
  714. static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
  715. size_t count, loff_t *ppos)
  716. {
  717. int ret;
  718. mutex_lock(&mvm->mutex);
  719. /* allow one more restart that we're provoking here */
  720. if (mvm->restart_fw >= 0)
  721. mvm->restart_fw++;
  722. /* take the return value to make compiler happy - it will fail anyway */
  723. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
  724. mutex_unlock(&mvm->mutex);
  725. return count;
  726. }
  727. static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
  728. size_t count, loff_t *ppos)
  729. {
  730. int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
  731. if (ret)
  732. return ret;
  733. iwl_force_nmi(mvm->trans);
  734. iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
  735. return count;
  736. }
  737. static ssize_t
  738. iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
  739. char __user *user_buf,
  740. size_t count, loff_t *ppos)
  741. {
  742. struct iwl_mvm *mvm = file->private_data;
  743. int pos = 0;
  744. char buf[32];
  745. const size_t bufsz = sizeof(buf);
  746. /* print which antennas were set for the scan command by the user */
  747. pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
  748. if (mvm->scan_rx_ant & ANT_A)
  749. pos += scnprintf(buf + pos, bufsz - pos, "A");
  750. if (mvm->scan_rx_ant & ANT_B)
  751. pos += scnprintf(buf + pos, bufsz - pos, "B");
  752. if (mvm->scan_rx_ant & ANT_C)
  753. pos += scnprintf(buf + pos, bufsz - pos, "C");
  754. pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
  755. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  756. }
  757. static ssize_t
  758. iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
  759. size_t count, loff_t *ppos)
  760. {
  761. u8 scan_rx_ant;
  762. if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
  763. return -EINVAL;
  764. if (scan_rx_ant > ANT_ABC)
  765. return -EINVAL;
  766. if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
  767. return -EINVAL;
  768. if (mvm->scan_rx_ant != scan_rx_ant) {
  769. mvm->scan_rx_ant = scan_rx_ant;
  770. if (fw_has_capa(&mvm->fw->ucode_capa,
  771. IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  772. iwl_mvm_config_scan(mvm);
  773. }
  774. return count;
  775. }
  776. static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
  777. char __user *user_buf,
  778. size_t count, loff_t *ppos)
  779. {
  780. struct iwl_mvm *mvm = file->private_data;
  781. int conf;
  782. char buf[8];
  783. const size_t bufsz = sizeof(buf);
  784. int pos = 0;
  785. mutex_lock(&mvm->mutex);
  786. conf = mvm->fw_dbg_conf;
  787. mutex_unlock(&mvm->mutex);
  788. pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
  789. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  790. }
  791. static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
  792. char *buf, size_t count,
  793. loff_t *ppos)
  794. {
  795. int ret, conf_id;
  796. ret = kstrtoint(buf, 0, &conf_id);
  797. if (ret)
  798. return ret;
  799. if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
  800. return -EINVAL;
  801. mutex_lock(&mvm->mutex);
  802. ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
  803. mutex_unlock(&mvm->mutex);
  804. return ret ?: count;
  805. }
  806. static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
  807. char *buf, size_t count,
  808. loff_t *ppos)
  809. {
  810. int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  811. if (ret)
  812. return ret;
  813. iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, NULL, 0, 0);
  814. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  815. return count;
  816. }
  817. #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
  818. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  819. static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
  820. char __user *user_buf,
  821. size_t count, loff_t *ppos)
  822. {
  823. struct iwl_mvm *mvm = file->private_data;
  824. struct iwl_bcast_filter_cmd cmd;
  825. const struct iwl_fw_bcast_filter *filter;
  826. char *buf;
  827. int bufsz = 1024;
  828. int i, j, pos = 0;
  829. ssize_t ret;
  830. buf = kzalloc(bufsz, GFP_KERNEL);
  831. if (!buf)
  832. return -ENOMEM;
  833. mutex_lock(&mvm->mutex);
  834. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  835. ADD_TEXT("None\n");
  836. mutex_unlock(&mvm->mutex);
  837. goto out;
  838. }
  839. mutex_unlock(&mvm->mutex);
  840. for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
  841. filter = &cmd.filters[i];
  842. ADD_TEXT("Filter [%d]:\n", i);
  843. ADD_TEXT("\tDiscard=%d\n", filter->discard);
  844. ADD_TEXT("\tFrame Type: %s\n",
  845. filter->frame_type ? "IPv4" : "Generic");
  846. for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
  847. const struct iwl_fw_bcast_filter_attr *attr;
  848. attr = &filter->attrs[j];
  849. if (!attr->mask)
  850. break;
  851. ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
  852. j, attr->offset,
  853. attr->offset_type ? "IP End" :
  854. "Payload Start",
  855. be32_to_cpu(attr->mask),
  856. be32_to_cpu(attr->val),
  857. le16_to_cpu(attr->reserved1));
  858. }
  859. }
  860. out:
  861. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  862. kfree(buf);
  863. return ret;
  864. }
  865. static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
  866. size_t count, loff_t *ppos)
  867. {
  868. int pos, next_pos;
  869. struct iwl_fw_bcast_filter filter = {};
  870. struct iwl_bcast_filter_cmd cmd;
  871. u32 filter_id, attr_id, mask, value;
  872. int err = 0;
  873. if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
  874. &filter.frame_type, &pos) != 3)
  875. return -EINVAL;
  876. if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
  877. filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
  878. return -EINVAL;
  879. for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
  880. attr_id++) {
  881. struct iwl_fw_bcast_filter_attr *attr =
  882. &filter.attrs[attr_id];
  883. if (pos >= count)
  884. break;
  885. if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
  886. &attr->offset, &attr->offset_type,
  887. &mask, &value, &next_pos) != 4)
  888. return -EINVAL;
  889. attr->mask = cpu_to_be32(mask);
  890. attr->val = cpu_to_be32(value);
  891. if (mask)
  892. filter.num_attrs++;
  893. pos += next_pos;
  894. }
  895. mutex_lock(&mvm->mutex);
  896. memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
  897. &filter, sizeof(filter));
  898. /* send updated bcast filtering configuration */
  899. if (mvm->dbgfs_bcast_filtering.override &&
  900. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  901. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  902. sizeof(cmd), &cmd);
  903. mutex_unlock(&mvm->mutex);
  904. return err ?: count;
  905. }
  906. static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
  907. char __user *user_buf,
  908. size_t count, loff_t *ppos)
  909. {
  910. struct iwl_mvm *mvm = file->private_data;
  911. struct iwl_bcast_filter_cmd cmd;
  912. char *buf;
  913. int bufsz = 1024;
  914. int i, pos = 0;
  915. ssize_t ret;
  916. buf = kzalloc(bufsz, GFP_KERNEL);
  917. if (!buf)
  918. return -ENOMEM;
  919. mutex_lock(&mvm->mutex);
  920. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  921. ADD_TEXT("None\n");
  922. mutex_unlock(&mvm->mutex);
  923. goto out;
  924. }
  925. mutex_unlock(&mvm->mutex);
  926. for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
  927. const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
  928. ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
  929. i, mac->default_discard, mac->attached_filters);
  930. }
  931. out:
  932. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  933. kfree(buf);
  934. return ret;
  935. }
  936. static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
  937. char *buf, size_t count,
  938. loff_t *ppos)
  939. {
  940. struct iwl_bcast_filter_cmd cmd;
  941. struct iwl_fw_bcast_mac mac = {};
  942. u32 mac_id, attached_filters;
  943. int err = 0;
  944. if (!mvm->bcast_filters)
  945. return -ENOENT;
  946. if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
  947. &attached_filters) != 3)
  948. return -EINVAL;
  949. if (mac_id >= ARRAY_SIZE(cmd.macs) ||
  950. mac.default_discard > 1 ||
  951. attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
  952. return -EINVAL;
  953. mac.attached_filters = cpu_to_le16(attached_filters);
  954. mutex_lock(&mvm->mutex);
  955. memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
  956. &mac, sizeof(mac));
  957. /* send updated bcast filtering configuration */
  958. if (mvm->dbgfs_bcast_filtering.override &&
  959. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  960. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  961. sizeof(cmd), &cmd);
  962. mutex_unlock(&mvm->mutex);
  963. return err ?: count;
  964. }
  965. #endif
  966. #ifdef CONFIG_PM_SLEEP
  967. static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
  968. size_t count, loff_t *ppos)
  969. {
  970. int store;
  971. if (sscanf(buf, "%d", &store) != 1)
  972. return -EINVAL;
  973. mvm->store_d3_resume_sram = store;
  974. return count;
  975. }
  976. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  977. size_t count, loff_t *ppos)
  978. {
  979. struct iwl_mvm *mvm = file->private_data;
  980. const struct fw_img *img;
  981. int ofs, len, pos = 0;
  982. size_t bufsz, ret;
  983. char *buf;
  984. u8 *ptr = mvm->d3_resume_sram;
  985. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  986. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  987. bufsz = len * 4 + 256;
  988. buf = kzalloc(bufsz, GFP_KERNEL);
  989. if (!buf)
  990. return -ENOMEM;
  991. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  992. mvm->store_d3_resume_sram ? "en" : "dis");
  993. if (ptr) {
  994. for (ofs = 0; ofs < len; ofs += 16) {
  995. pos += scnprintf(buf + pos, bufsz - pos,
  996. "0x%.4x ", ofs);
  997. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  998. bufsz - pos, false);
  999. pos += strlen(buf + pos);
  1000. if (bufsz - pos > 0)
  1001. buf[pos++] = '\n';
  1002. }
  1003. } else {
  1004. pos += scnprintf(buf + pos, bufsz - pos,
  1005. "(no data captured)\n");
  1006. }
  1007. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1008. kfree(buf);
  1009. return ret;
  1010. }
  1011. #define MAX_NUM_ND_MATCHSETS 10
  1012. static ssize_t iwl_dbgfs_netdetect_write(struct iwl_mvm *mvm, char *buf,
  1013. size_t count, loff_t *ppos)
  1014. {
  1015. const char *seps = ",\n";
  1016. char *buf_ptr = buf;
  1017. char *value_str = NULL;
  1018. int ret, i;
  1019. /* TODO: don't free if write is being called several times in one go */
  1020. if (mvm->nd_config) {
  1021. kfree(mvm->nd_config->match_sets);
  1022. kfree(mvm->nd_config);
  1023. mvm->nd_config = NULL;
  1024. }
  1025. mvm->nd_config = kzalloc(sizeof(*mvm->nd_config) +
  1026. (11 * sizeof(struct ieee80211_channel *)),
  1027. GFP_KERNEL);
  1028. if (!mvm->nd_config) {
  1029. ret = -ENOMEM;
  1030. goto out_free;
  1031. }
  1032. mvm->nd_config->n_channels = 11;
  1033. mvm->nd_config->scan_width = NL80211_BSS_CHAN_WIDTH_20;
  1034. mvm->nd_config->interval = 5;
  1035. mvm->nd_config->min_rssi_thold = -80;
  1036. for (i = 0; i < mvm->nd_config->n_channels; i++)
  1037. mvm->nd_config->channels[i] = &mvm->nvm_data->channels[i];
  1038. mvm->nd_config->match_sets =
  1039. kcalloc(MAX_NUM_ND_MATCHSETS,
  1040. sizeof(*mvm->nd_config->match_sets),
  1041. GFP_KERNEL);
  1042. if (!mvm->nd_config->match_sets) {
  1043. ret = -ENOMEM;
  1044. goto out_free;
  1045. }
  1046. while ((value_str = strsep(&buf_ptr, seps)) &&
  1047. strlen(value_str)) {
  1048. struct cfg80211_match_set *set;
  1049. if (mvm->nd_config->n_match_sets >= MAX_NUM_ND_MATCHSETS) {
  1050. ret = -EINVAL;
  1051. goto out_free;
  1052. }
  1053. set = &mvm->nd_config->match_sets[mvm->nd_config->n_match_sets];
  1054. set->ssid.ssid_len = strlen(value_str);
  1055. if (set->ssid.ssid_len > IEEE80211_MAX_SSID_LEN) {
  1056. ret = -EINVAL;
  1057. goto out_free;
  1058. }
  1059. memcpy(set->ssid.ssid, value_str, set->ssid.ssid_len);
  1060. mvm->nd_config->n_match_sets++;
  1061. }
  1062. ret = count;
  1063. if (mvm->nd_config->n_match_sets)
  1064. goto out;
  1065. out_free:
  1066. if (mvm->nd_config)
  1067. kfree(mvm->nd_config->match_sets);
  1068. kfree(mvm->nd_config);
  1069. mvm->nd_config = NULL;
  1070. out:
  1071. return ret;
  1072. }
  1073. static ssize_t
  1074. iwl_dbgfs_netdetect_read(struct file *file, char __user *user_buf,
  1075. size_t count, loff_t *ppos)
  1076. {
  1077. struct iwl_mvm *mvm = file->private_data;
  1078. size_t bufsz, ret;
  1079. char *buf;
  1080. int i, n_match_sets, pos = 0;
  1081. n_match_sets = mvm->nd_config ? mvm->nd_config->n_match_sets : 0;
  1082. bufsz = n_match_sets * (IEEE80211_MAX_SSID_LEN + 1) + 1;
  1083. buf = kzalloc(bufsz, GFP_KERNEL);
  1084. if (!buf)
  1085. return -ENOMEM;
  1086. for (i = 0; i < n_match_sets; i++) {
  1087. if (pos +
  1088. mvm->nd_config->match_sets[i].ssid.ssid_len + 2 > bufsz) {
  1089. ret = -EIO;
  1090. goto out;
  1091. }
  1092. memcpy(buf + pos, mvm->nd_config->match_sets[i].ssid.ssid,
  1093. mvm->nd_config->match_sets[i].ssid.ssid_len);
  1094. pos += mvm->nd_config->match_sets[i].ssid.ssid_len;
  1095. buf[pos++] = '\n';
  1096. }
  1097. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1098. out:
  1099. kfree(buf);
  1100. return ret;
  1101. }
  1102. #endif
  1103. #define PRINT_MVM_REF(ref) do { \
  1104. if (mvm->refs[ref]) \
  1105. pos += scnprintf(buf + pos, bufsz - pos, \
  1106. "\t(0x%lx): %d %s\n", \
  1107. BIT(ref), mvm->refs[ref], #ref); \
  1108. } while (0)
  1109. static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
  1110. char __user *user_buf,
  1111. size_t count, loff_t *ppos)
  1112. {
  1113. struct iwl_mvm *mvm = file->private_data;
  1114. int i, pos = 0;
  1115. char buf[256];
  1116. const size_t bufsz = sizeof(buf);
  1117. u32 refs = 0;
  1118. for (i = 0; i < IWL_MVM_REF_COUNT; i++)
  1119. if (mvm->refs[i])
  1120. refs |= BIT(i);
  1121. pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
  1122. refs);
  1123. PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
  1124. PRINT_MVM_REF(IWL_MVM_REF_SCAN);
  1125. PRINT_MVM_REF(IWL_MVM_REF_ROC);
  1126. PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
  1127. PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
  1128. PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
  1129. PRINT_MVM_REF(IWL_MVM_REF_USER);
  1130. PRINT_MVM_REF(IWL_MVM_REF_TX);
  1131. PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
  1132. PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
  1133. PRINT_MVM_REF(IWL_MVM_REF_START_AP);
  1134. PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
  1135. PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
  1136. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
  1137. PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
  1138. PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
  1139. PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
  1140. PRINT_MVM_REF(IWL_MVM_REF_NMI);
  1141. PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
  1142. PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
  1143. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
  1144. PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
  1145. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1146. }
  1147. static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
  1148. size_t count, loff_t *ppos)
  1149. {
  1150. unsigned long value;
  1151. int ret;
  1152. bool taken;
  1153. ret = kstrtoul(buf, 10, &value);
  1154. if (ret < 0)
  1155. return ret;
  1156. mutex_lock(&mvm->mutex);
  1157. taken = mvm->refs[IWL_MVM_REF_USER];
  1158. if (value == 1 && !taken)
  1159. iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
  1160. else if (value == 0 && taken)
  1161. iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
  1162. else
  1163. ret = -EINVAL;
  1164. mutex_unlock(&mvm->mutex);
  1165. if (ret < 0)
  1166. return ret;
  1167. return count;
  1168. }
  1169. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1170. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1171. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1172. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1173. #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
  1174. if (!debugfs_create_file(alias, mode, parent, mvm, \
  1175. &iwl_dbgfs_##name##_ops)) \
  1176. goto err; \
  1177. } while (0)
  1178. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
  1179. MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
  1180. static ssize_t
  1181. iwl_dbgfs_prph_reg_read(struct file *file,
  1182. char __user *user_buf,
  1183. size_t count, loff_t *ppos)
  1184. {
  1185. struct iwl_mvm *mvm = file->private_data;
  1186. int pos = 0;
  1187. char buf[32];
  1188. const size_t bufsz = sizeof(buf);
  1189. int ret;
  1190. if (!mvm->dbgfs_prph_reg_addr)
  1191. return -EINVAL;
  1192. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
  1193. if (ret)
  1194. return ret;
  1195. pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
  1196. mvm->dbgfs_prph_reg_addr,
  1197. iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
  1198. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
  1199. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1200. }
  1201. static ssize_t
  1202. iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
  1203. size_t count, loff_t *ppos)
  1204. {
  1205. u8 args;
  1206. u32 value;
  1207. int ret;
  1208. args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
  1209. /* if we only want to set the reg address - nothing more to do */
  1210. if (args == 1)
  1211. goto out;
  1212. /* otherwise, make sure we have both address and value */
  1213. if (args != 2)
  1214. return -EINVAL;
  1215. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  1216. if (ret)
  1217. return ret;
  1218. iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
  1219. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  1220. out:
  1221. return count;
  1222. }
  1223. MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
  1224. /* Device wide debugfs entries */
  1225. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
  1226. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
  1227. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
  1228. MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
  1229. MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
  1230. MVM_DEBUGFS_READ_FILE_OPS(stations);
  1231. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  1232. MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
  1233. MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
  1234. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  1235. MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
  1236. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
  1237. MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
  1238. MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
  1239. MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
  1240. MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
  1241. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
  1242. MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
  1243. MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 8);
  1244. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1245. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
  1246. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
  1247. #endif
  1248. #ifdef CONFIG_PM_SLEEP
  1249. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
  1250. MVM_DEBUGFS_READ_WRITE_FILE_OPS(netdetect, 384);
  1251. #endif
  1252. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  1253. {
  1254. struct dentry *bcast_dir __maybe_unused;
  1255. char buf[100];
  1256. spin_lock_init(&mvm->drv_stats_lock);
  1257. mvm->debugfs_dir = dbgfs_dir;
  1258. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  1259. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  1260. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1261. MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
  1262. S_IWUSR | S_IRUSR);
  1263. MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
  1264. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  1265. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  1266. MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
  1267. MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
  1268. S_IRUSR | S_IWUSR);
  1269. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1270. MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1271. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  1272. MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
  1273. MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
  1274. MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
  1275. MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
  1276. S_IWUSR | S_IRUSR);
  1277. MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1278. MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1279. MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1280. MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
  1281. if (!debugfs_create_bool("enable_scan_iteration_notif",
  1282. S_IRUSR | S_IWUSR,
  1283. mvm->debugfs_dir,
  1284. &mvm->scan_iter_notif_enabled))
  1285. goto err;
  1286. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1287. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
  1288. bcast_dir = debugfs_create_dir("bcast_filtering",
  1289. mvm->debugfs_dir);
  1290. if (!bcast_dir)
  1291. goto err;
  1292. if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
  1293. bcast_dir,
  1294. &mvm->dbgfs_bcast_filtering.override))
  1295. goto err;
  1296. MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
  1297. bcast_dir, S_IWUSR | S_IRUSR);
  1298. MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
  1299. bcast_dir, S_IWUSR | S_IRUSR);
  1300. }
  1301. #endif
  1302. #ifdef CONFIG_PM_SLEEP
  1303. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1304. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  1305. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  1306. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  1307. goto err;
  1308. if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
  1309. mvm->debugfs_dir, &mvm->last_netdetect_scans))
  1310. goto err;
  1311. MVM_DEBUGFS_ADD_FILE(netdetect, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1312. #endif
  1313. if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR | S_IWUSR,
  1314. mvm->debugfs_dir,
  1315. &mvm->low_latency_agg_frame_limit))
  1316. goto err;
  1317. if (!debugfs_create_u8("ps_disabled", S_IRUSR,
  1318. mvm->debugfs_dir, &mvm->ps_disabled))
  1319. goto err;
  1320. if (!debugfs_create_blob("nvm_hw", S_IRUSR,
  1321. mvm->debugfs_dir, &mvm->nvm_hw_blob))
  1322. goto err;
  1323. if (!debugfs_create_blob("nvm_sw", S_IRUSR,
  1324. mvm->debugfs_dir, &mvm->nvm_sw_blob))
  1325. goto err;
  1326. if (!debugfs_create_blob("nvm_calib", S_IRUSR,
  1327. mvm->debugfs_dir, &mvm->nvm_calib_blob))
  1328. goto err;
  1329. if (!debugfs_create_blob("nvm_prod", S_IRUSR,
  1330. mvm->debugfs_dir, &mvm->nvm_prod_blob))
  1331. goto err;
  1332. /*
  1333. * Create a symlink with mac80211. It will be removed when mac80211
  1334. * exists (before the opmode exists which removes the target.)
  1335. */
  1336. snprintf(buf, 100, "../../%s/%s",
  1337. dbgfs_dir->d_parent->d_parent->d_name.name,
  1338. dbgfs_dir->d_parent->d_name.name);
  1339. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  1340. goto err;
  1341. return 0;
  1342. err:
  1343. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  1344. return -ENOMEM;
  1345. }