debugfs.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  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 - 2014 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 - 2014 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 (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  412. struct iwl_bt_coex_profile_notif_old *notif =
  413. &mvm->last_bt_notif_old;
  414. pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
  415. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  416. notif->bt_ci_compliance);
  417. pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
  418. le32_to_cpu(notif->primary_ch_lut));
  419. pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
  420. le32_to_cpu(notif->secondary_ch_lut));
  421. pos += scnprintf(buf+pos,
  422. bufsz-pos, "bt_activity_grading = %d\n",
  423. le32_to_cpu(notif->bt_activity_grading));
  424. pos += scnprintf(buf+pos, bufsz-pos,
  425. "antenna isolation = %d CORUN LUT index = %d\n",
  426. mvm->last_ant_isol, mvm->last_corun_lut);
  427. } else {
  428. struct iwl_bt_coex_profile_notif *notif =
  429. &mvm->last_bt_notif;
  430. pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
  431. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  432. notif->bt_ci_compliance);
  433. pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
  434. le32_to_cpu(notif->primary_ch_lut));
  435. pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
  436. le32_to_cpu(notif->secondary_ch_lut));
  437. pos += scnprintf(buf+pos,
  438. bufsz-pos, "bt_activity_grading = %d\n",
  439. le32_to_cpu(notif->bt_activity_grading));
  440. pos += scnprintf(buf+pos, bufsz-pos,
  441. "antenna isolation = %d CORUN LUT index = %d\n",
  442. mvm->last_ant_isol, mvm->last_corun_lut);
  443. }
  444. mutex_unlock(&mvm->mutex);
  445. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  446. kfree(buf);
  447. return ret;
  448. }
  449. #undef BT_MBOX_PRINT
  450. static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
  451. size_t count, loff_t *ppos)
  452. {
  453. struct iwl_mvm *mvm = file->private_data;
  454. char buf[256];
  455. int bufsz = sizeof(buf);
  456. int pos = 0;
  457. mutex_lock(&mvm->mutex);
  458. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  459. struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
  460. pos += scnprintf(buf+pos, bufsz-pos,
  461. "Channel inhibition CMD\n");
  462. pos += scnprintf(buf+pos, bufsz-pos,
  463. "\tPrimary Channel Bitmap 0x%016llx\n",
  464. le64_to_cpu(cmd->bt_primary_ci));
  465. pos += scnprintf(buf+pos, bufsz-pos,
  466. "\tSecondary Channel Bitmap 0x%016llx\n",
  467. le64_to_cpu(cmd->bt_secondary_ci));
  468. pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
  469. pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
  470. iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[0]]);
  471. pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
  472. iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[0]]);
  473. } else {
  474. struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
  475. pos += scnprintf(buf+pos, bufsz-pos,
  476. "Channel inhibition CMD\n");
  477. pos += scnprintf(buf+pos, bufsz-pos,
  478. "\tPrimary Channel Bitmap 0x%016llx\n",
  479. le64_to_cpu(cmd->bt_primary_ci));
  480. pos += scnprintf(buf+pos, bufsz-pos,
  481. "\tSecondary Channel Bitmap 0x%016llx\n",
  482. le64_to_cpu(cmd->bt_secondary_ci));
  483. pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
  484. pos += scnprintf(buf+pos, bufsz-pos,
  485. "\tPrimary: ACK Kill Mask 0x%08x\n",
  486. iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[0]]);
  487. pos += scnprintf(buf+pos, bufsz-pos,
  488. "\tPrimary: CTS Kill Mask 0x%08x\n",
  489. iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[0]]);
  490. pos += scnprintf(buf+pos, bufsz-pos,
  491. "\tSecondary: ACK Kill Mask 0x%08x\n",
  492. iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[1]]);
  493. pos += scnprintf(buf+pos, bufsz-pos,
  494. "\tSecondary: CTS Kill Mask 0x%08x\n",
  495. iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[1]]);
  496. }
  497. mutex_unlock(&mvm->mutex);
  498. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  499. }
  500. static ssize_t
  501. iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
  502. size_t count, loff_t *ppos)
  503. {
  504. u32 bt_tx_prio;
  505. if (sscanf(buf, "%u", &bt_tx_prio) != 1)
  506. return -EINVAL;
  507. if (bt_tx_prio > 4)
  508. return -EINVAL;
  509. mvm->bt_tx_prio = bt_tx_prio;
  510. return count;
  511. }
  512. static ssize_t
  513. iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
  514. size_t count, loff_t *ppos)
  515. {
  516. static const char * const modes_str[BT_FORCE_ANT_MAX] = {
  517. [BT_FORCE_ANT_DIS] = "dis",
  518. [BT_FORCE_ANT_AUTO] = "auto",
  519. [BT_FORCE_ANT_BT] = "bt",
  520. [BT_FORCE_ANT_WIFI] = "wifi",
  521. };
  522. int ret, bt_force_ant_mode;
  523. for (bt_force_ant_mode = 0;
  524. bt_force_ant_mode < ARRAY_SIZE(modes_str);
  525. bt_force_ant_mode++) {
  526. if (!strcmp(buf, modes_str[bt_force_ant_mode]))
  527. break;
  528. }
  529. if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
  530. return -EINVAL;
  531. ret = 0;
  532. mutex_lock(&mvm->mutex);
  533. if (mvm->bt_force_ant_mode == bt_force_ant_mode)
  534. goto out;
  535. mvm->bt_force_ant_mode = bt_force_ant_mode;
  536. IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
  537. modes_str[mvm->bt_force_ant_mode]);
  538. ret = iwl_send_bt_init_conf(mvm);
  539. out:
  540. mutex_unlock(&mvm->mutex);
  541. return ret ?: count;
  542. }
  543. #define PRINT_STATS_LE32(_str, _val) \
  544. pos += scnprintf(buf + pos, bufsz - pos, \
  545. fmt_table, _str, \
  546. le32_to_cpu(_val))
  547. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  548. char __user *user_buf, size_t count,
  549. loff_t *ppos)
  550. {
  551. struct iwl_mvm *mvm = file->private_data;
  552. static const char *fmt_table = "\t%-30s %10u\n";
  553. static const char *fmt_header = "%-32s\n";
  554. int pos = 0;
  555. char *buf;
  556. int ret;
  557. /* 43 is the size of each data line, 33 is the size of each header */
  558. size_t bufsz =
  559. ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
  560. (4 * 33) + 1;
  561. struct mvm_statistics_rx_phy *ofdm;
  562. struct mvm_statistics_rx_phy *cck;
  563. struct mvm_statistics_rx_non_phy *general;
  564. struct mvm_statistics_rx_ht_phy *ht;
  565. buf = kzalloc(bufsz, GFP_KERNEL);
  566. if (!buf)
  567. return -ENOMEM;
  568. mutex_lock(&mvm->mutex);
  569. ofdm = &mvm->rx_stats.ofdm;
  570. cck = &mvm->rx_stats.cck;
  571. general = &mvm->rx_stats.general;
  572. ht = &mvm->rx_stats.ofdm_ht;
  573. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  574. "Statistics_Rx - OFDM");
  575. PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
  576. PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
  577. PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
  578. PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
  579. PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
  580. PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
  581. PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
  582. PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
  583. PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
  584. PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
  585. PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
  586. PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
  587. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  588. ofdm->rxe_frame_limit_overrun);
  589. PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
  590. PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
  591. PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
  592. PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
  593. PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
  594. PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
  595. PRINT_STATS_LE32("reserved", ofdm->reserved);
  596. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  597. "Statistics_Rx - CCK");
  598. PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
  599. PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
  600. PRINT_STATS_LE32("plcp_err", cck->plcp_err);
  601. PRINT_STATS_LE32("crc32_err", cck->crc32_err);
  602. PRINT_STATS_LE32("overrun_err", cck->overrun_err);
  603. PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
  604. PRINT_STATS_LE32("crc32_good", cck->crc32_good);
  605. PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
  606. PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
  607. PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
  608. PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
  609. PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
  610. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  611. cck->rxe_frame_limit_overrun);
  612. PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
  613. PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
  614. PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
  615. PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
  616. PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
  617. PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
  618. PRINT_STATS_LE32("reserved", cck->reserved);
  619. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  620. "Statistics_Rx - GENERAL");
  621. PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
  622. PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
  623. PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
  624. PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
  625. PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
  626. PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
  627. PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
  628. PRINT_STATS_LE32("adc_rx_saturation_time",
  629. general->adc_rx_saturation_time);
  630. PRINT_STATS_LE32("ina_detection_search_time",
  631. general->ina_detection_search_time);
  632. PRINT_STATS_LE32("beacon_silence_rssi_a",
  633. general->beacon_silence_rssi_a);
  634. PRINT_STATS_LE32("beacon_silence_rssi_b",
  635. general->beacon_silence_rssi_b);
  636. PRINT_STATS_LE32("beacon_silence_rssi_c",
  637. general->beacon_silence_rssi_c);
  638. PRINT_STATS_LE32("interference_data_flag",
  639. general->interference_data_flag);
  640. PRINT_STATS_LE32("channel_load", general->channel_load);
  641. PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
  642. PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
  643. PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
  644. PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
  645. PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
  646. PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
  647. PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
  648. PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
  649. PRINT_STATS_LE32("mac_id", general->mac_id);
  650. PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
  651. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  652. "Statistics_Rx - HT");
  653. PRINT_STATS_LE32("plcp_err", ht->plcp_err);
  654. PRINT_STATS_LE32("overrun_err", ht->overrun_err);
  655. PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
  656. PRINT_STATS_LE32("crc32_good", ht->crc32_good);
  657. PRINT_STATS_LE32("crc32_err", ht->crc32_err);
  658. PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
  659. PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
  660. PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
  661. PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
  662. PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
  663. mutex_unlock(&mvm->mutex);
  664. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  665. kfree(buf);
  666. return ret;
  667. }
  668. #undef PRINT_STAT_LE32
  669. static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
  670. char __user *user_buf, size_t count,
  671. loff_t *ppos,
  672. struct iwl_mvm_frame_stats *stats)
  673. {
  674. char *buff, *pos, *endpos;
  675. int idx, i;
  676. int ret;
  677. static const size_t bufsz = 1024;
  678. buff = kmalloc(bufsz, GFP_KERNEL);
  679. if (!buff)
  680. return -ENOMEM;
  681. spin_lock_bh(&mvm->drv_stats_lock);
  682. pos = buff;
  683. endpos = pos + bufsz;
  684. pos += scnprintf(pos, endpos - pos,
  685. "Legacy/HT/VHT\t:\t%d/%d/%d\n",
  686. stats->legacy_frames,
  687. stats->ht_frames,
  688. stats->vht_frames);
  689. pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
  690. stats->bw_20_frames,
  691. stats->bw_40_frames,
  692. stats->bw_80_frames);
  693. pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
  694. stats->ngi_frames,
  695. stats->sgi_frames);
  696. pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
  697. stats->siso_frames,
  698. stats->mimo2_frames);
  699. pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
  700. stats->fail_frames,
  701. stats->success_frames);
  702. pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
  703. stats->agg_frames);
  704. pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
  705. stats->ampdu_count);
  706. pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
  707. stats->ampdu_count > 0 ?
  708. (stats->agg_frames / stats->ampdu_count) : 0);
  709. pos += scnprintf(pos, endpos - pos, "Last Rates\n");
  710. idx = stats->last_frame_idx - 1;
  711. for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
  712. idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
  713. if (stats->last_rates[idx] == 0)
  714. continue;
  715. pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
  716. (int)(ARRAY_SIZE(stats->last_rates) - i));
  717. pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
  718. }
  719. spin_unlock_bh(&mvm->drv_stats_lock);
  720. ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
  721. kfree(buff);
  722. return ret;
  723. }
  724. static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
  725. char __user *user_buf, size_t count,
  726. loff_t *ppos)
  727. {
  728. struct iwl_mvm *mvm = file->private_data;
  729. return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
  730. &mvm->drv_rx_stats);
  731. }
  732. static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
  733. size_t count, loff_t *ppos)
  734. {
  735. int ret;
  736. mutex_lock(&mvm->mutex);
  737. /* allow one more restart that we're provoking here */
  738. if (mvm->restart_fw >= 0)
  739. mvm->restart_fw++;
  740. /* take the return value to make compiler happy - it will fail anyway */
  741. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
  742. mutex_unlock(&mvm->mutex);
  743. return count;
  744. }
  745. static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
  746. size_t count, loff_t *ppos)
  747. {
  748. int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
  749. if (ret)
  750. return ret;
  751. iwl_force_nmi(mvm->trans);
  752. iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
  753. return count;
  754. }
  755. static ssize_t
  756. iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
  757. char __user *user_buf,
  758. size_t count, loff_t *ppos)
  759. {
  760. struct iwl_mvm *mvm = file->private_data;
  761. int pos = 0;
  762. char buf[32];
  763. const size_t bufsz = sizeof(buf);
  764. /* print which antennas were set for the scan command by the user */
  765. pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
  766. if (mvm->scan_rx_ant & ANT_A)
  767. pos += scnprintf(buf + pos, bufsz - pos, "A");
  768. if (mvm->scan_rx_ant & ANT_B)
  769. pos += scnprintf(buf + pos, bufsz - pos, "B");
  770. if (mvm->scan_rx_ant & ANT_C)
  771. pos += scnprintf(buf + pos, bufsz - pos, "C");
  772. pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
  773. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  774. }
  775. static ssize_t
  776. iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
  777. size_t count, loff_t *ppos)
  778. {
  779. u8 scan_rx_ant;
  780. if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
  781. return -EINVAL;
  782. if (scan_rx_ant > ANT_ABC)
  783. return -EINVAL;
  784. if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
  785. return -EINVAL;
  786. if (mvm->scan_rx_ant != scan_rx_ant) {
  787. mvm->scan_rx_ant = scan_rx_ant;
  788. if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
  789. iwl_mvm_config_scan(mvm);
  790. }
  791. return count;
  792. }
  793. #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
  794. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  795. static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
  796. char __user *user_buf,
  797. size_t count, loff_t *ppos)
  798. {
  799. struct iwl_mvm *mvm = file->private_data;
  800. struct iwl_bcast_filter_cmd cmd;
  801. const struct iwl_fw_bcast_filter *filter;
  802. char *buf;
  803. int bufsz = 1024;
  804. int i, j, pos = 0;
  805. ssize_t ret;
  806. buf = kzalloc(bufsz, GFP_KERNEL);
  807. if (!buf)
  808. return -ENOMEM;
  809. mutex_lock(&mvm->mutex);
  810. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  811. ADD_TEXT("None\n");
  812. mutex_unlock(&mvm->mutex);
  813. goto out;
  814. }
  815. mutex_unlock(&mvm->mutex);
  816. for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
  817. filter = &cmd.filters[i];
  818. ADD_TEXT("Filter [%d]:\n", i);
  819. ADD_TEXT("\tDiscard=%d\n", filter->discard);
  820. ADD_TEXT("\tFrame Type: %s\n",
  821. filter->frame_type ? "IPv4" : "Generic");
  822. for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
  823. const struct iwl_fw_bcast_filter_attr *attr;
  824. attr = &filter->attrs[j];
  825. if (!attr->mask)
  826. break;
  827. ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
  828. j, attr->offset,
  829. attr->offset_type ? "IP End" :
  830. "Payload Start",
  831. be32_to_cpu(attr->mask),
  832. be32_to_cpu(attr->val),
  833. le16_to_cpu(attr->reserved1));
  834. }
  835. }
  836. out:
  837. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  838. kfree(buf);
  839. return ret;
  840. }
  841. static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
  842. size_t count, loff_t *ppos)
  843. {
  844. int pos, next_pos;
  845. struct iwl_fw_bcast_filter filter = {};
  846. struct iwl_bcast_filter_cmd cmd;
  847. u32 filter_id, attr_id, mask, value;
  848. int err = 0;
  849. if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
  850. &filter.frame_type, &pos) != 3)
  851. return -EINVAL;
  852. if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
  853. filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
  854. return -EINVAL;
  855. for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
  856. attr_id++) {
  857. struct iwl_fw_bcast_filter_attr *attr =
  858. &filter.attrs[attr_id];
  859. if (pos >= count)
  860. break;
  861. if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
  862. &attr->offset, &attr->offset_type,
  863. &mask, &value, &next_pos) != 4)
  864. return -EINVAL;
  865. attr->mask = cpu_to_be32(mask);
  866. attr->val = cpu_to_be32(value);
  867. if (mask)
  868. filter.num_attrs++;
  869. pos += next_pos;
  870. }
  871. mutex_lock(&mvm->mutex);
  872. memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
  873. &filter, sizeof(filter));
  874. /* send updated bcast filtering configuration */
  875. if (mvm->dbgfs_bcast_filtering.override &&
  876. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  877. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  878. sizeof(cmd), &cmd);
  879. mutex_unlock(&mvm->mutex);
  880. return err ?: count;
  881. }
  882. static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
  883. char __user *user_buf,
  884. size_t count, loff_t *ppos)
  885. {
  886. struct iwl_mvm *mvm = file->private_data;
  887. struct iwl_bcast_filter_cmd cmd;
  888. char *buf;
  889. int bufsz = 1024;
  890. int i, pos = 0;
  891. ssize_t ret;
  892. buf = kzalloc(bufsz, GFP_KERNEL);
  893. if (!buf)
  894. return -ENOMEM;
  895. mutex_lock(&mvm->mutex);
  896. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  897. ADD_TEXT("None\n");
  898. mutex_unlock(&mvm->mutex);
  899. goto out;
  900. }
  901. mutex_unlock(&mvm->mutex);
  902. for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
  903. const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
  904. ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
  905. i, mac->default_discard, mac->attached_filters);
  906. }
  907. out:
  908. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  909. kfree(buf);
  910. return ret;
  911. }
  912. static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
  913. char *buf, size_t count,
  914. loff_t *ppos)
  915. {
  916. struct iwl_bcast_filter_cmd cmd;
  917. struct iwl_fw_bcast_mac mac = {};
  918. u32 mac_id, attached_filters;
  919. int err = 0;
  920. if (!mvm->bcast_filters)
  921. return -ENOENT;
  922. if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
  923. &attached_filters) != 3)
  924. return -EINVAL;
  925. if (mac_id >= ARRAY_SIZE(cmd.macs) ||
  926. mac.default_discard > 1 ||
  927. attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
  928. return -EINVAL;
  929. mac.attached_filters = cpu_to_le16(attached_filters);
  930. mutex_lock(&mvm->mutex);
  931. memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
  932. &mac, sizeof(mac));
  933. /* send updated bcast filtering configuration */
  934. if (mvm->dbgfs_bcast_filtering.override &&
  935. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  936. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  937. sizeof(cmd), &cmd);
  938. mutex_unlock(&mvm->mutex);
  939. return err ?: count;
  940. }
  941. #endif
  942. #ifdef CONFIG_PM_SLEEP
  943. static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
  944. size_t count, loff_t *ppos)
  945. {
  946. int store;
  947. if (sscanf(buf, "%d", &store) != 1)
  948. return -EINVAL;
  949. mvm->store_d3_resume_sram = store;
  950. return count;
  951. }
  952. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  953. size_t count, loff_t *ppos)
  954. {
  955. struct iwl_mvm *mvm = file->private_data;
  956. const struct fw_img *img;
  957. int ofs, len, pos = 0;
  958. size_t bufsz, ret;
  959. char *buf;
  960. u8 *ptr = mvm->d3_resume_sram;
  961. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  962. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  963. bufsz = len * 4 + 256;
  964. buf = kzalloc(bufsz, GFP_KERNEL);
  965. if (!buf)
  966. return -ENOMEM;
  967. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  968. mvm->store_d3_resume_sram ? "en" : "dis");
  969. if (ptr) {
  970. for (ofs = 0; ofs < len; ofs += 16) {
  971. pos += scnprintf(buf + pos, bufsz - pos,
  972. "0x%.4x ", ofs);
  973. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  974. bufsz - pos, false);
  975. pos += strlen(buf + pos);
  976. if (bufsz - pos > 0)
  977. buf[pos++] = '\n';
  978. }
  979. } else {
  980. pos += scnprintf(buf + pos, bufsz - pos,
  981. "(no data captured)\n");
  982. }
  983. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  984. kfree(buf);
  985. return ret;
  986. }
  987. #define MAX_NUM_ND_MATCHSETS 10
  988. static ssize_t iwl_dbgfs_netdetect_write(struct iwl_mvm *mvm, char *buf,
  989. size_t count, loff_t *ppos)
  990. {
  991. const char *seps = ",\n";
  992. char *buf_ptr = buf;
  993. char *value_str = NULL;
  994. int ret, i;
  995. /* TODO: don't free if write is being called several times in one go */
  996. if (mvm->nd_config) {
  997. kfree(mvm->nd_config->match_sets);
  998. kfree(mvm->nd_config);
  999. mvm->nd_config = NULL;
  1000. }
  1001. mvm->nd_config = kzalloc(sizeof(*mvm->nd_config) +
  1002. (11 * sizeof(struct ieee80211_channel *)),
  1003. GFP_KERNEL);
  1004. if (!mvm->nd_config) {
  1005. ret = -ENOMEM;
  1006. goto out_free;
  1007. }
  1008. mvm->nd_config->n_channels = 11;
  1009. mvm->nd_config->scan_width = NL80211_BSS_CHAN_WIDTH_20;
  1010. mvm->nd_config->interval = 5;
  1011. mvm->nd_config->min_rssi_thold = -80;
  1012. for (i = 0; i < mvm->nd_config->n_channels; i++)
  1013. mvm->nd_config->channels[i] = &mvm->nvm_data->channels[i];
  1014. mvm->nd_config->match_sets =
  1015. kcalloc(MAX_NUM_ND_MATCHSETS,
  1016. sizeof(*mvm->nd_config->match_sets),
  1017. GFP_KERNEL);
  1018. if (!mvm->nd_config->match_sets) {
  1019. ret = -ENOMEM;
  1020. goto out_free;
  1021. }
  1022. while ((value_str = strsep(&buf_ptr, seps)) &&
  1023. strlen(value_str)) {
  1024. struct cfg80211_match_set *set;
  1025. if (mvm->nd_config->n_match_sets >= MAX_NUM_ND_MATCHSETS) {
  1026. ret = -EINVAL;
  1027. goto out_free;
  1028. }
  1029. set = &mvm->nd_config->match_sets[mvm->nd_config->n_match_sets];
  1030. set->ssid.ssid_len = strlen(value_str);
  1031. if (set->ssid.ssid_len > IEEE80211_MAX_SSID_LEN) {
  1032. ret = -EINVAL;
  1033. goto out_free;
  1034. }
  1035. memcpy(set->ssid.ssid, value_str, set->ssid.ssid_len);
  1036. mvm->nd_config->n_match_sets++;
  1037. }
  1038. ret = count;
  1039. if (mvm->nd_config->n_match_sets)
  1040. goto out;
  1041. out_free:
  1042. if (mvm->nd_config)
  1043. kfree(mvm->nd_config->match_sets);
  1044. kfree(mvm->nd_config);
  1045. mvm->nd_config = NULL;
  1046. out:
  1047. return ret;
  1048. }
  1049. static ssize_t
  1050. iwl_dbgfs_netdetect_read(struct file *file, char __user *user_buf,
  1051. size_t count, loff_t *ppos)
  1052. {
  1053. struct iwl_mvm *mvm = file->private_data;
  1054. size_t bufsz, ret;
  1055. char *buf;
  1056. int i, n_match_sets, pos = 0;
  1057. n_match_sets = mvm->nd_config ? mvm->nd_config->n_match_sets : 0;
  1058. bufsz = n_match_sets * (IEEE80211_MAX_SSID_LEN + 1) + 1;
  1059. buf = kzalloc(bufsz, GFP_KERNEL);
  1060. if (!buf)
  1061. return -ENOMEM;
  1062. for (i = 0; i < n_match_sets; i++) {
  1063. if (pos +
  1064. mvm->nd_config->match_sets[i].ssid.ssid_len + 2 > bufsz) {
  1065. ret = -EIO;
  1066. goto out;
  1067. }
  1068. memcpy(buf + pos, mvm->nd_config->match_sets[i].ssid.ssid,
  1069. mvm->nd_config->match_sets[i].ssid.ssid_len);
  1070. pos += mvm->nd_config->match_sets[i].ssid.ssid_len;
  1071. buf[pos++] = '\n';
  1072. }
  1073. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1074. out:
  1075. kfree(buf);
  1076. return ret;
  1077. }
  1078. #endif
  1079. #define PRINT_MVM_REF(ref) do { \
  1080. if (mvm->refs[ref]) \
  1081. pos += scnprintf(buf + pos, bufsz - pos, \
  1082. "\t(0x%lx): %d %s\n", \
  1083. BIT(ref), mvm->refs[ref], #ref); \
  1084. } while (0)
  1085. static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
  1086. char __user *user_buf,
  1087. size_t count, loff_t *ppos)
  1088. {
  1089. struct iwl_mvm *mvm = file->private_data;
  1090. int i, pos = 0;
  1091. char buf[256];
  1092. const size_t bufsz = sizeof(buf);
  1093. u32 refs = 0;
  1094. for (i = 0; i < IWL_MVM_REF_COUNT; i++)
  1095. if (mvm->refs[i])
  1096. refs |= BIT(i);
  1097. pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
  1098. refs);
  1099. PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
  1100. PRINT_MVM_REF(IWL_MVM_REF_SCAN);
  1101. PRINT_MVM_REF(IWL_MVM_REF_ROC);
  1102. PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
  1103. PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
  1104. PRINT_MVM_REF(IWL_MVM_REF_USER);
  1105. PRINT_MVM_REF(IWL_MVM_REF_TX);
  1106. PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
  1107. PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
  1108. PRINT_MVM_REF(IWL_MVM_REF_START_AP);
  1109. PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
  1110. PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
  1111. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
  1112. PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
  1113. PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
  1114. PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
  1115. PRINT_MVM_REF(IWL_MVM_REF_NMI);
  1116. PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
  1117. PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
  1118. PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
  1119. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1120. }
  1121. static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
  1122. size_t count, loff_t *ppos)
  1123. {
  1124. unsigned long value;
  1125. int ret;
  1126. bool taken;
  1127. ret = kstrtoul(buf, 10, &value);
  1128. if (ret < 0)
  1129. return ret;
  1130. mutex_lock(&mvm->mutex);
  1131. taken = mvm->refs[IWL_MVM_REF_USER];
  1132. if (value == 1 && !taken)
  1133. iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
  1134. else if (value == 0 && taken)
  1135. iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
  1136. else
  1137. ret = -EINVAL;
  1138. mutex_unlock(&mvm->mutex);
  1139. if (ret < 0)
  1140. return ret;
  1141. return count;
  1142. }
  1143. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  1144. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1145. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  1146. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  1147. #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
  1148. if (!debugfs_create_file(alias, mode, parent, mvm, \
  1149. &iwl_dbgfs_##name##_ops)) \
  1150. goto err; \
  1151. } while (0)
  1152. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
  1153. MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
  1154. static ssize_t
  1155. iwl_dbgfs_prph_reg_read(struct file *file,
  1156. char __user *user_buf,
  1157. size_t count, loff_t *ppos)
  1158. {
  1159. struct iwl_mvm *mvm = file->private_data;
  1160. int pos = 0;
  1161. char buf[32];
  1162. const size_t bufsz = sizeof(buf);
  1163. int ret;
  1164. if (!mvm->dbgfs_prph_reg_addr)
  1165. return -EINVAL;
  1166. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
  1167. if (ret)
  1168. return ret;
  1169. pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
  1170. mvm->dbgfs_prph_reg_addr,
  1171. iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
  1172. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
  1173. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1174. }
  1175. static ssize_t
  1176. iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
  1177. size_t count, loff_t *ppos)
  1178. {
  1179. u8 args;
  1180. u32 value;
  1181. int ret;
  1182. args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
  1183. /* if we only want to set the reg address - nothing more to do */
  1184. if (args == 1)
  1185. goto out;
  1186. /* otherwise, make sure we have both address and value */
  1187. if (args != 2)
  1188. return -EINVAL;
  1189. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
  1190. if (ret)
  1191. return ret;
  1192. iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
  1193. iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
  1194. out:
  1195. return count;
  1196. }
  1197. MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
  1198. /* Device wide debugfs entries */
  1199. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
  1200. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
  1201. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
  1202. MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
  1203. MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
  1204. MVM_DEBUGFS_READ_FILE_OPS(stations);
  1205. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  1206. MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
  1207. MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
  1208. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  1209. MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
  1210. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
  1211. MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
  1212. MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
  1213. MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
  1214. MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
  1215. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
  1216. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1217. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
  1218. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
  1219. #endif
  1220. #ifdef CONFIG_PM_SLEEP
  1221. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
  1222. MVM_DEBUGFS_READ_WRITE_FILE_OPS(netdetect, 384);
  1223. #endif
  1224. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  1225. {
  1226. struct dentry *bcast_dir __maybe_unused;
  1227. char buf[100];
  1228. spin_lock_init(&mvm->drv_stats_lock);
  1229. mvm->debugfs_dir = dbgfs_dir;
  1230. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  1231. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  1232. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1233. MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
  1234. S_IWUSR | S_IRUSR);
  1235. MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
  1236. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  1237. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  1238. MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
  1239. MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
  1240. S_IRUSR | S_IWUSR);
  1241. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1242. MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
  1243. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  1244. MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
  1245. MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
  1246. MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
  1247. MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
  1248. S_IWUSR | S_IRUSR);
  1249. MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  1250. MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1251. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1252. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
  1253. bcast_dir = debugfs_create_dir("bcast_filtering",
  1254. mvm->debugfs_dir);
  1255. if (!bcast_dir)
  1256. goto err;
  1257. if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
  1258. bcast_dir,
  1259. &mvm->dbgfs_bcast_filtering.override))
  1260. goto err;
  1261. MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
  1262. bcast_dir, S_IWUSR | S_IRUSR);
  1263. MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
  1264. bcast_dir, S_IWUSR | S_IRUSR);
  1265. }
  1266. #endif
  1267. #ifdef CONFIG_PM_SLEEP
  1268. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1269. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  1270. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  1271. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  1272. goto err;
  1273. MVM_DEBUGFS_ADD_FILE(netdetect, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  1274. #endif
  1275. if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR | S_IWUSR,
  1276. mvm->debugfs_dir,
  1277. &mvm->low_latency_agg_frame_limit))
  1278. goto err;
  1279. if (!debugfs_create_u8("ps_disabled", S_IRUSR,
  1280. mvm->debugfs_dir, &mvm->ps_disabled))
  1281. goto err;
  1282. if (!debugfs_create_blob("nvm_hw", S_IRUSR,
  1283. mvm->debugfs_dir, &mvm->nvm_hw_blob))
  1284. goto err;
  1285. if (!debugfs_create_blob("nvm_sw", S_IRUSR,
  1286. mvm->debugfs_dir, &mvm->nvm_sw_blob))
  1287. goto err;
  1288. if (!debugfs_create_blob("nvm_calib", S_IRUSR,
  1289. mvm->debugfs_dir, &mvm->nvm_calib_blob))
  1290. goto err;
  1291. if (!debugfs_create_blob("nvm_prod", S_IRUSR,
  1292. mvm->debugfs_dir, &mvm->nvm_prod_blob))
  1293. goto err;
  1294. /*
  1295. * Create a symlink with mac80211. It will be removed when mac80211
  1296. * exists (before the opmode exists which removes the target.)
  1297. */
  1298. snprintf(buf, 100, "../../%s/%s",
  1299. dbgfs_dir->d_parent->d_parent->d_name.name,
  1300. dbgfs_dir->d_parent->d_name.name);
  1301. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  1302. goto err;
  1303. return 0;
  1304. err:
  1305. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  1306. return -ENOMEM;
  1307. }