fw-dbg.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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) 2008 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program;
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <linuxwifi@intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  34. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  35. * Copyright(c) 2015 - 2016 Intel Deutschland 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/devcoredump.h>
  66. #include "fw-dbg.h"
  67. #include "iwl-io.h"
  68. #include "mvm.h"
  69. #include "iwl-prph.h"
  70. #include "iwl-csr.h"
  71. #define RADIO_REG_MAX_READ 0x2ad
  72. static void iwl_mvm_read_radio_reg(struct iwl_mvm *mvm,
  73. struct iwl_fw_error_dump_data **dump_data)
  74. {
  75. u8 *pos = (void *)(*dump_data)->data;
  76. unsigned long flags;
  77. int i;
  78. if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
  79. return;
  80. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RADIO_REG);
  81. (*dump_data)->len = cpu_to_le32(RADIO_REG_MAX_READ);
  82. for (i = 0; i < RADIO_REG_MAX_READ; i++) {
  83. u32 rd_cmd = RADIO_RSP_RD_CMD;
  84. rd_cmd |= i << RADIO_RSP_ADDR_POS;
  85. iwl_write_prph_no_grab(mvm->trans, RSP_RADIO_CMD, rd_cmd);
  86. *pos = (u8)iwl_read_prph_no_grab(mvm->trans, RSP_RADIO_RDDAT);
  87. pos++;
  88. }
  89. *dump_data = iwl_fw_error_next_data(*dump_data);
  90. iwl_trans_release_nic_access(mvm->trans, &flags);
  91. }
  92. static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
  93. struct iwl_fw_error_dump_data **dump_data)
  94. {
  95. struct iwl_fw_error_dump_fifo *fifo_hdr;
  96. u32 *fifo_data;
  97. u32 fifo_len;
  98. unsigned long flags;
  99. int i, j;
  100. if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
  101. return;
  102. /* Pull RXF data from all RXFs */
  103. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
  104. /*
  105. * Keep aside the additional offset that might be needed for
  106. * next RXF
  107. */
  108. u32 offset_diff = RXF_DIFF_FROM_PREV * i;
  109. fifo_hdr = (void *)(*dump_data)->data;
  110. fifo_data = (void *)fifo_hdr->data;
  111. fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
  112. /* No need to try to read the data if the length is 0 */
  113. if (fifo_len == 0)
  114. continue;
  115. /* Add a TLV for the RXF */
  116. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
  117. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  118. fifo_hdr->fifo_num = cpu_to_le32(i);
  119. fifo_hdr->available_bytes =
  120. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  121. RXF_RD_D_SPACE +
  122. offset_diff));
  123. fifo_hdr->wr_ptr =
  124. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  125. RXF_RD_WR_PTR +
  126. offset_diff));
  127. fifo_hdr->rd_ptr =
  128. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  129. RXF_RD_RD_PTR +
  130. offset_diff));
  131. fifo_hdr->fence_ptr =
  132. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  133. RXF_RD_FENCE_PTR +
  134. offset_diff));
  135. fifo_hdr->fence_mode =
  136. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  137. RXF_SET_FENCE_MODE +
  138. offset_diff));
  139. /* Lock fence */
  140. iwl_trans_write_prph(mvm->trans,
  141. RXF_SET_FENCE_MODE + offset_diff, 0x1);
  142. /* Set fence pointer to the same place like WR pointer */
  143. iwl_trans_write_prph(mvm->trans,
  144. RXF_LD_WR2FENCE + offset_diff, 0x1);
  145. /* Set fence offset */
  146. iwl_trans_write_prph(mvm->trans,
  147. RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
  148. 0x0);
  149. /* Read FIFO */
  150. fifo_len /= sizeof(u32); /* Size in DWORDS */
  151. for (j = 0; j < fifo_len; j++)
  152. fifo_data[j] = iwl_trans_read_prph(mvm->trans,
  153. RXF_FIFO_RD_FENCE_INC +
  154. offset_diff);
  155. *dump_data = iwl_fw_error_next_data(*dump_data);
  156. }
  157. /* Pull TXF data from all TXFs */
  158. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
  159. /* Mark the number of TXF we're pulling now */
  160. iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
  161. fifo_hdr = (void *)(*dump_data)->data;
  162. fifo_data = (void *)fifo_hdr->data;
  163. fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
  164. /* No need to try to read the data if the length is 0 */
  165. if (fifo_len == 0)
  166. continue;
  167. /* Add a TLV for the FIFO */
  168. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
  169. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  170. fifo_hdr->fifo_num = cpu_to_le32(i);
  171. fifo_hdr->available_bytes =
  172. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  173. TXF_FIFO_ITEM_CNT));
  174. fifo_hdr->wr_ptr =
  175. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  176. TXF_WR_PTR));
  177. fifo_hdr->rd_ptr =
  178. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  179. TXF_RD_PTR));
  180. fifo_hdr->fence_ptr =
  181. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  182. TXF_FENCE_PTR));
  183. fifo_hdr->fence_mode =
  184. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  185. TXF_LOCK_FENCE));
  186. /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
  187. iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
  188. TXF_WR_PTR);
  189. /* Dummy-read to advance the read pointer to the head */
  190. iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
  191. /* Read FIFO */
  192. fifo_len /= sizeof(u32); /* Size in DWORDS */
  193. for (j = 0; j < fifo_len; j++)
  194. fifo_data[j] = iwl_trans_read_prph(mvm->trans,
  195. TXF_READ_MODIFY_DATA);
  196. *dump_data = iwl_fw_error_next_data(*dump_data);
  197. }
  198. if (fw_has_capa(&mvm->fw->ucode_capa,
  199. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  200. /* Pull UMAC internal TXF data from all TXFs */
  201. for (i = 0;
  202. i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size);
  203. i++) {
  204. fifo_hdr = (void *)(*dump_data)->data;
  205. fifo_data = (void *)fifo_hdr->data;
  206. fifo_len = mvm->shared_mem_cfg.internal_txfifo_size[i];
  207. /* No need to try to read the data if the length is 0 */
  208. if (fifo_len == 0)
  209. continue;
  210. /* Add a TLV for the internal FIFOs */
  211. (*dump_data)->type =
  212. cpu_to_le32(IWL_FW_ERROR_DUMP_INTERNAL_TXF);
  213. (*dump_data)->len =
  214. cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  215. fifo_hdr->fifo_num = cpu_to_le32(i);
  216. /* Mark the number of TXF we're pulling now */
  217. iwl_trans_write_prph(mvm->trans, TXF_CPU2_NUM, i +
  218. ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size));
  219. fifo_hdr->available_bytes =
  220. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  221. TXF_CPU2_FIFO_ITEM_CNT));
  222. fifo_hdr->wr_ptr =
  223. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  224. TXF_CPU2_WR_PTR));
  225. fifo_hdr->rd_ptr =
  226. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  227. TXF_CPU2_RD_PTR));
  228. fifo_hdr->fence_ptr =
  229. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  230. TXF_CPU2_FENCE_PTR));
  231. fifo_hdr->fence_mode =
  232. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  233. TXF_CPU2_LOCK_FENCE));
  234. /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */
  235. iwl_trans_write_prph(mvm->trans,
  236. TXF_CPU2_READ_MODIFY_ADDR,
  237. TXF_CPU2_WR_PTR);
  238. /* Dummy-read to advance the read pointer to head */
  239. iwl_trans_read_prph(mvm->trans,
  240. TXF_CPU2_READ_MODIFY_DATA);
  241. /* Read FIFO */
  242. fifo_len /= sizeof(u32); /* Size in DWORDS */
  243. for (j = 0; j < fifo_len; j++)
  244. fifo_data[j] =
  245. iwl_trans_read_prph(mvm->trans,
  246. TXF_CPU2_READ_MODIFY_DATA);
  247. *dump_data = iwl_fw_error_next_data(*dump_data);
  248. }
  249. }
  250. iwl_trans_release_nic_access(mvm->trans, &flags);
  251. }
  252. void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
  253. {
  254. if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
  255. return;
  256. kfree(mvm->fw_dump_desc);
  257. mvm->fw_dump_desc = NULL;
  258. }
  259. #define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
  260. #define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
  261. struct iwl_prph_range {
  262. u32 start, end;
  263. };
  264. static const struct iwl_prph_range iwl_prph_dump_addr_comm[] = {
  265. { .start = 0x00a00000, .end = 0x00a00000 },
  266. { .start = 0x00a0000c, .end = 0x00a00024 },
  267. { .start = 0x00a0002c, .end = 0x00a0003c },
  268. { .start = 0x00a00410, .end = 0x00a00418 },
  269. { .start = 0x00a00420, .end = 0x00a00420 },
  270. { .start = 0x00a00428, .end = 0x00a00428 },
  271. { .start = 0x00a00430, .end = 0x00a0043c },
  272. { .start = 0x00a00444, .end = 0x00a00444 },
  273. { .start = 0x00a004c0, .end = 0x00a004cc },
  274. { .start = 0x00a004d8, .end = 0x00a004d8 },
  275. { .start = 0x00a004e0, .end = 0x00a004f0 },
  276. { .start = 0x00a00840, .end = 0x00a00840 },
  277. { .start = 0x00a00850, .end = 0x00a00858 },
  278. { .start = 0x00a01004, .end = 0x00a01008 },
  279. { .start = 0x00a01010, .end = 0x00a01010 },
  280. { .start = 0x00a01018, .end = 0x00a01018 },
  281. { .start = 0x00a01024, .end = 0x00a01024 },
  282. { .start = 0x00a0102c, .end = 0x00a01034 },
  283. { .start = 0x00a0103c, .end = 0x00a01040 },
  284. { .start = 0x00a01048, .end = 0x00a01094 },
  285. { .start = 0x00a01c00, .end = 0x00a01c20 },
  286. { .start = 0x00a01c58, .end = 0x00a01c58 },
  287. { .start = 0x00a01c7c, .end = 0x00a01c7c },
  288. { .start = 0x00a01c28, .end = 0x00a01c54 },
  289. { .start = 0x00a01c5c, .end = 0x00a01c5c },
  290. { .start = 0x00a01c60, .end = 0x00a01cdc },
  291. { .start = 0x00a01ce0, .end = 0x00a01d0c },
  292. { .start = 0x00a01d18, .end = 0x00a01d20 },
  293. { .start = 0x00a01d2c, .end = 0x00a01d30 },
  294. { .start = 0x00a01d40, .end = 0x00a01d5c },
  295. { .start = 0x00a01d80, .end = 0x00a01d80 },
  296. { .start = 0x00a01d98, .end = 0x00a01d9c },
  297. { .start = 0x00a01da8, .end = 0x00a01da8 },
  298. { .start = 0x00a01db8, .end = 0x00a01df4 },
  299. { .start = 0x00a01dc0, .end = 0x00a01dfc },
  300. { .start = 0x00a01e00, .end = 0x00a01e2c },
  301. { .start = 0x00a01e40, .end = 0x00a01e60 },
  302. { .start = 0x00a01e68, .end = 0x00a01e6c },
  303. { .start = 0x00a01e74, .end = 0x00a01e74 },
  304. { .start = 0x00a01e84, .end = 0x00a01e90 },
  305. { .start = 0x00a01e9c, .end = 0x00a01ec4 },
  306. { .start = 0x00a01ed0, .end = 0x00a01ee0 },
  307. { .start = 0x00a01f00, .end = 0x00a01f1c },
  308. { .start = 0x00a01f44, .end = 0x00a01ffc },
  309. { .start = 0x00a02000, .end = 0x00a02048 },
  310. { .start = 0x00a02068, .end = 0x00a020f0 },
  311. { .start = 0x00a02100, .end = 0x00a02118 },
  312. { .start = 0x00a02140, .end = 0x00a0214c },
  313. { .start = 0x00a02168, .end = 0x00a0218c },
  314. { .start = 0x00a021c0, .end = 0x00a021c0 },
  315. { .start = 0x00a02400, .end = 0x00a02410 },
  316. { .start = 0x00a02418, .end = 0x00a02420 },
  317. { .start = 0x00a02428, .end = 0x00a0242c },
  318. { .start = 0x00a02434, .end = 0x00a02434 },
  319. { .start = 0x00a02440, .end = 0x00a02460 },
  320. { .start = 0x00a02468, .end = 0x00a024b0 },
  321. { .start = 0x00a024c8, .end = 0x00a024cc },
  322. { .start = 0x00a02500, .end = 0x00a02504 },
  323. { .start = 0x00a0250c, .end = 0x00a02510 },
  324. { .start = 0x00a02540, .end = 0x00a02554 },
  325. { .start = 0x00a02580, .end = 0x00a025f4 },
  326. { .start = 0x00a02600, .end = 0x00a0260c },
  327. { .start = 0x00a02648, .end = 0x00a02650 },
  328. { .start = 0x00a02680, .end = 0x00a02680 },
  329. { .start = 0x00a026c0, .end = 0x00a026d0 },
  330. { .start = 0x00a02700, .end = 0x00a0270c },
  331. { .start = 0x00a02804, .end = 0x00a02804 },
  332. { .start = 0x00a02818, .end = 0x00a0281c },
  333. { .start = 0x00a02c00, .end = 0x00a02db4 },
  334. { .start = 0x00a02df4, .end = 0x00a02fb0 },
  335. { .start = 0x00a03000, .end = 0x00a03014 },
  336. { .start = 0x00a0301c, .end = 0x00a0302c },
  337. { .start = 0x00a03034, .end = 0x00a03038 },
  338. { .start = 0x00a03040, .end = 0x00a03048 },
  339. { .start = 0x00a03060, .end = 0x00a03068 },
  340. { .start = 0x00a03070, .end = 0x00a03074 },
  341. { .start = 0x00a0307c, .end = 0x00a0307c },
  342. { .start = 0x00a03080, .end = 0x00a03084 },
  343. { .start = 0x00a0308c, .end = 0x00a03090 },
  344. { .start = 0x00a03098, .end = 0x00a03098 },
  345. { .start = 0x00a030a0, .end = 0x00a030a0 },
  346. { .start = 0x00a030a8, .end = 0x00a030b4 },
  347. { .start = 0x00a030bc, .end = 0x00a030bc },
  348. { .start = 0x00a030c0, .end = 0x00a0312c },
  349. { .start = 0x00a03c00, .end = 0x00a03c5c },
  350. { .start = 0x00a04400, .end = 0x00a04454 },
  351. { .start = 0x00a04460, .end = 0x00a04474 },
  352. { .start = 0x00a044c0, .end = 0x00a044ec },
  353. { .start = 0x00a04500, .end = 0x00a04504 },
  354. { .start = 0x00a04510, .end = 0x00a04538 },
  355. { .start = 0x00a04540, .end = 0x00a04548 },
  356. { .start = 0x00a04560, .end = 0x00a0457c },
  357. { .start = 0x00a04590, .end = 0x00a04598 },
  358. { .start = 0x00a045c0, .end = 0x00a045f4 },
  359. };
  360. static const struct iwl_prph_range iwl_prph_dump_addr_9000[] = {
  361. { .start = 0x00a05c00, .end = 0x00a05c18 },
  362. { .start = 0x00a05400, .end = 0x00a056e8 },
  363. { .start = 0x00a08000, .end = 0x00a098bc },
  364. { .start = 0x00a02400, .end = 0x00a02758 },
  365. };
  366. static u32 iwl_dump_prph(struct iwl_trans *trans,
  367. struct iwl_fw_error_dump_data **data,
  368. const struct iwl_prph_range *iwl_prph_dump_addr,
  369. u32 range_len)
  370. {
  371. struct iwl_fw_error_dump_prph *prph;
  372. unsigned long flags;
  373. u32 prph_len = 0, i;
  374. if (!iwl_trans_grab_nic_access(trans, &flags))
  375. return 0;
  376. for (i = 0; i < range_len; i++) {
  377. /* The range includes both boundaries */
  378. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  379. iwl_prph_dump_addr[i].start + 4;
  380. int reg;
  381. __le32 *val;
  382. prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
  383. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
  384. (*data)->len = cpu_to_le32(sizeof(*prph) +
  385. num_bytes_in_chunk);
  386. prph = (void *)(*data)->data;
  387. prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
  388. val = (void *)prph->data;
  389. for (reg = iwl_prph_dump_addr[i].start;
  390. reg <= iwl_prph_dump_addr[i].end;
  391. reg += 4)
  392. *val++ = cpu_to_le32(iwl_read_prph_no_grab(trans,
  393. reg));
  394. *data = iwl_fw_error_next_data(*data);
  395. }
  396. iwl_trans_release_nic_access(trans, &flags);
  397. return prph_len;
  398. }
  399. /*
  400. * alloc_sgtable - allocates scallerlist table in the given size,
  401. * fills it with pages and returns it
  402. * @size: the size (in bytes) of the table
  403. */
  404. static struct scatterlist *alloc_sgtable(int size)
  405. {
  406. int alloc_size, nents, i;
  407. struct page *new_page;
  408. struct scatterlist *iter;
  409. struct scatterlist *table;
  410. nents = DIV_ROUND_UP(size, PAGE_SIZE);
  411. table = kcalloc(nents, sizeof(*table), GFP_KERNEL);
  412. if (!table)
  413. return NULL;
  414. sg_init_table(table, nents);
  415. iter = table;
  416. for_each_sg(table, iter, sg_nents(table), i) {
  417. new_page = alloc_page(GFP_KERNEL);
  418. if (!new_page) {
  419. /* release all previous allocated pages in the table */
  420. iter = table;
  421. for_each_sg(table, iter, sg_nents(table), i) {
  422. new_page = sg_page(iter);
  423. if (new_page)
  424. __free_page(new_page);
  425. }
  426. return NULL;
  427. }
  428. alloc_size = min_t(int, size, PAGE_SIZE);
  429. size -= PAGE_SIZE;
  430. sg_set_page(iter, new_page, alloc_size, 0);
  431. }
  432. return table;
  433. }
  434. void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
  435. {
  436. struct iwl_fw_error_dump_file *dump_file;
  437. struct iwl_fw_error_dump_data *dump_data;
  438. struct iwl_fw_error_dump_info *dump_info;
  439. struct iwl_fw_error_dump_mem *dump_mem;
  440. struct iwl_fw_error_dump_trigger_desc *dump_trig;
  441. struct iwl_mvm_dump_ptrs *fw_error_dump;
  442. struct scatterlist *sg_dump_data;
  443. u32 sram_len, sram_ofs;
  444. struct iwl_fw_dbg_mem_seg_tlv * const *fw_dbg_mem =
  445. mvm->fw->dbg_mem_tlv;
  446. u32 file_len, fifo_data_len = 0, prph_len = 0, radio_len = 0;
  447. u32 smem_len = mvm->fw->dbg_dynamic_mem ? 0 : mvm->cfg->smem_len;
  448. u32 sram2_len = mvm->fw->dbg_dynamic_mem ? 0 : mvm->cfg->dccm2_len;
  449. bool monitor_dump_only = false;
  450. int i;
  451. if (!IWL_MVM_COLLECT_FW_ERR_DUMP &&
  452. !mvm->trans->dbg_dest_tlv)
  453. return;
  454. lockdep_assert_held(&mvm->mutex);
  455. /* there's no point in fw dump if the bus is dead */
  456. if (test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
  457. IWL_ERR(mvm, "Skip fw error dump since bus is dead\n");
  458. goto out;
  459. }
  460. if (mvm->fw_dump_trig &&
  461. mvm->fw_dump_trig->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)
  462. monitor_dump_only = true;
  463. fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
  464. if (!fw_error_dump)
  465. goto out;
  466. /* SRAM - include stack CCM if driver knows the values for it */
  467. if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
  468. const struct fw_img *img;
  469. img = &mvm->fw->img[mvm->cur_ucode];
  470. sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  471. sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  472. } else {
  473. sram_ofs = mvm->cfg->dccm_offset;
  474. sram_len = mvm->cfg->dccm_len;
  475. }
  476. /* reading RXF/TXF sizes */
  477. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  478. struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
  479. fifo_data_len = 0;
  480. /* Count RXF size */
  481. for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
  482. if (!mem_cfg->rxfifo_size[i])
  483. continue;
  484. /* Add header info */
  485. fifo_data_len += mem_cfg->rxfifo_size[i] +
  486. sizeof(*dump_data) +
  487. sizeof(struct iwl_fw_error_dump_fifo);
  488. }
  489. for (i = 0; i < mem_cfg->num_txfifo_entries; i++) {
  490. if (!mem_cfg->txfifo_size[i])
  491. continue;
  492. /* Add header info */
  493. fifo_data_len += mem_cfg->txfifo_size[i] +
  494. sizeof(*dump_data) +
  495. sizeof(struct iwl_fw_error_dump_fifo);
  496. }
  497. if (fw_has_capa(&mvm->fw->ucode_capa,
  498. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  499. for (i = 0;
  500. i < ARRAY_SIZE(mem_cfg->internal_txfifo_size);
  501. i++) {
  502. if (!mem_cfg->internal_txfifo_size[i])
  503. continue;
  504. /* Add header info */
  505. fifo_data_len +=
  506. mem_cfg->internal_txfifo_size[i] +
  507. sizeof(*dump_data) +
  508. sizeof(struct iwl_fw_error_dump_fifo);
  509. }
  510. }
  511. /* Make room for PRPH registers */
  512. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr_comm); i++) {
  513. /* The range includes both boundaries */
  514. int num_bytes_in_chunk =
  515. iwl_prph_dump_addr_comm[i].end -
  516. iwl_prph_dump_addr_comm[i].start + 4;
  517. prph_len += sizeof(*dump_data) +
  518. sizeof(struct iwl_fw_error_dump_prph) +
  519. num_bytes_in_chunk;
  520. }
  521. if (mvm->cfg->mq_rx_supported) {
  522. for (i = 0; i <
  523. ARRAY_SIZE(iwl_prph_dump_addr_9000); i++) {
  524. /* The range includes both boundaries */
  525. int num_bytes_in_chunk =
  526. iwl_prph_dump_addr_9000[i].end -
  527. iwl_prph_dump_addr_9000[i].start + 4;
  528. prph_len += sizeof(*dump_data) +
  529. sizeof(struct iwl_fw_error_dump_prph) +
  530. num_bytes_in_chunk;
  531. }
  532. }
  533. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  534. radio_len = sizeof(*dump_data) + RADIO_REG_MAX_READ;
  535. }
  536. file_len = sizeof(*dump_file) +
  537. sizeof(*dump_data) * 2 +
  538. fifo_data_len +
  539. prph_len +
  540. radio_len +
  541. sizeof(*dump_info);
  542. /* Make room for the SMEM, if it exists */
  543. if (smem_len)
  544. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
  545. /* Make room for the secondary SRAM, if it exists */
  546. if (sram2_len)
  547. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
  548. /* Make room for MEM segments */
  549. for (i = 0; i < ARRAY_SIZE(mvm->fw->dbg_mem_tlv); i++) {
  550. if (fw_dbg_mem[i])
  551. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  552. le32_to_cpu(fw_dbg_mem[i]->len);
  553. }
  554. /* Make room for fw's virtual image pages, if it exists */
  555. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
  556. mvm->fw_paging_db[0].fw_paging_block)
  557. file_len += mvm->num_of_paging_blk *
  558. (sizeof(*dump_data) +
  559. sizeof(struct iwl_fw_error_dump_paging) +
  560. PAGING_BLOCK_SIZE);
  561. /* If we only want a monitor dump, reset the file length */
  562. if (monitor_dump_only) {
  563. file_len = sizeof(*dump_file) + sizeof(*dump_data) +
  564. sizeof(*dump_info);
  565. }
  566. /*
  567. * In 8000 HW family B-step include the ICCM (which resides separately)
  568. */
  569. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  570. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP)
  571. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  572. IWL8260_ICCM_LEN;
  573. if (mvm->fw_dump_desc)
  574. file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
  575. mvm->fw_dump_desc->len;
  576. if (!mvm->fw->dbg_dynamic_mem)
  577. file_len += sram_len + sizeof(*dump_mem);
  578. dump_file = vzalloc(file_len);
  579. if (!dump_file) {
  580. kfree(fw_error_dump);
  581. goto out;
  582. }
  583. fw_error_dump->op_mode_ptr = dump_file;
  584. dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
  585. dump_data = (void *)dump_file->data;
  586. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
  587. dump_data->len = cpu_to_le32(sizeof(*dump_info));
  588. dump_info = (void *)dump_data->data;
  589. dump_info->device_family =
  590. mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
  591. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
  592. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
  593. dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
  594. memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
  595. sizeof(dump_info->fw_human_readable));
  596. strncpy(dump_info->dev_human_readable, mvm->cfg->name,
  597. sizeof(dump_info->dev_human_readable));
  598. strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
  599. sizeof(dump_info->bus_human_readable));
  600. dump_data = iwl_fw_error_next_data(dump_data);
  601. /* We only dump the FIFOs if the FW is in error state */
  602. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  603. iwl_mvm_dump_fifos(mvm, &dump_data);
  604. if (radio_len)
  605. iwl_mvm_read_radio_reg(mvm, &dump_data);
  606. }
  607. if (mvm->fw_dump_desc) {
  608. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
  609. dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
  610. mvm->fw_dump_desc->len);
  611. dump_trig = (void *)dump_data->data;
  612. memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
  613. sizeof(*dump_trig) + mvm->fw_dump_desc->len);
  614. dump_data = iwl_fw_error_next_data(dump_data);
  615. }
  616. /* In case we only want monitor dump, skip to dump trasport data */
  617. if (monitor_dump_only)
  618. goto dump_trans_data;
  619. if (!mvm->fw->dbg_dynamic_mem) {
  620. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  621. dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
  622. dump_mem = (void *)dump_data->data;
  623. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  624. dump_mem->offset = cpu_to_le32(sram_ofs);
  625. iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
  626. sram_len);
  627. dump_data = iwl_fw_error_next_data(dump_data);
  628. }
  629. for (i = 0; i < ARRAY_SIZE(mvm->fw->dbg_mem_tlv); i++) {
  630. if (fw_dbg_mem[i]) {
  631. u32 len = le32_to_cpu(fw_dbg_mem[i]->len);
  632. u32 ofs = le32_to_cpu(fw_dbg_mem[i]->ofs);
  633. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  634. dump_data->len = cpu_to_le32(len +
  635. sizeof(*dump_mem));
  636. dump_mem = (void *)dump_data->data;
  637. dump_mem->type = fw_dbg_mem[i]->data_type;
  638. dump_mem->offset = cpu_to_le32(ofs);
  639. iwl_trans_read_mem_bytes(mvm->trans, ofs,
  640. dump_mem->data,
  641. len);
  642. dump_data = iwl_fw_error_next_data(dump_data);
  643. }
  644. }
  645. if (smem_len) {
  646. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  647. dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
  648. dump_mem = (void *)dump_data->data;
  649. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
  650. dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
  651. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
  652. dump_mem->data, smem_len);
  653. dump_data = iwl_fw_error_next_data(dump_data);
  654. }
  655. if (sram2_len) {
  656. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  657. dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
  658. dump_mem = (void *)dump_data->data;
  659. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  660. dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
  661. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
  662. dump_mem->data, sram2_len);
  663. dump_data = iwl_fw_error_next_data(dump_data);
  664. }
  665. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  666. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP) {
  667. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  668. dump_data->len = cpu_to_le32(IWL8260_ICCM_LEN +
  669. sizeof(*dump_mem));
  670. dump_mem = (void *)dump_data->data;
  671. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  672. dump_mem->offset = cpu_to_le32(IWL8260_ICCM_OFFSET);
  673. iwl_trans_read_mem_bytes(mvm->trans, IWL8260_ICCM_OFFSET,
  674. dump_mem->data, IWL8260_ICCM_LEN);
  675. dump_data = iwl_fw_error_next_data(dump_data);
  676. }
  677. /* Dump fw's virtual image */
  678. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
  679. mvm->fw_paging_db[0].fw_paging_block) {
  680. for (i = 1; i < mvm->num_of_paging_blk + 1; i++) {
  681. struct iwl_fw_error_dump_paging *paging;
  682. struct page *pages =
  683. mvm->fw_paging_db[i].fw_paging_block;
  684. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
  685. dump_data->len = cpu_to_le32(sizeof(*paging) +
  686. PAGING_BLOCK_SIZE);
  687. paging = (void *)dump_data->data;
  688. paging->index = cpu_to_le32(i);
  689. memcpy(paging->data, page_address(pages),
  690. PAGING_BLOCK_SIZE);
  691. dump_data = iwl_fw_error_next_data(dump_data);
  692. }
  693. }
  694. if (prph_len) {
  695. iwl_dump_prph(mvm->trans, &dump_data,
  696. iwl_prph_dump_addr_comm,
  697. ARRAY_SIZE(iwl_prph_dump_addr_comm));
  698. if (mvm->cfg->mq_rx_supported)
  699. iwl_dump_prph(mvm->trans, &dump_data,
  700. iwl_prph_dump_addr_9000,
  701. ARRAY_SIZE(iwl_prph_dump_addr_9000));
  702. }
  703. dump_trans_data:
  704. fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans,
  705. mvm->fw_dump_trig);
  706. fw_error_dump->op_mode_len = file_len;
  707. if (fw_error_dump->trans_ptr)
  708. file_len += fw_error_dump->trans_ptr->len;
  709. dump_file->file_len = cpu_to_le32(file_len);
  710. sg_dump_data = alloc_sgtable(file_len);
  711. if (sg_dump_data) {
  712. sg_pcopy_from_buffer(sg_dump_data,
  713. sg_nents(sg_dump_data),
  714. fw_error_dump->op_mode_ptr,
  715. fw_error_dump->op_mode_len, 0);
  716. sg_pcopy_from_buffer(sg_dump_data,
  717. sg_nents(sg_dump_data),
  718. fw_error_dump->trans_ptr->data,
  719. fw_error_dump->trans_ptr->len,
  720. fw_error_dump->op_mode_len);
  721. dev_coredumpsg(mvm->trans->dev, sg_dump_data, file_len,
  722. GFP_KERNEL);
  723. }
  724. vfree(fw_error_dump->op_mode_ptr);
  725. vfree(fw_error_dump->trans_ptr);
  726. kfree(fw_error_dump);
  727. out:
  728. iwl_mvm_free_fw_dump_desc(mvm);
  729. mvm->fw_dump_trig = NULL;
  730. clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
  731. }
  732. const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
  733. .trig_desc = {
  734. .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
  735. },
  736. };
  737. int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
  738. const struct iwl_mvm_dump_desc *desc,
  739. const struct iwl_fw_dbg_trigger_tlv *trigger)
  740. {
  741. unsigned int delay = 0;
  742. if (trigger)
  743. delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
  744. if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
  745. return -EBUSY;
  746. if (WARN_ON(mvm->fw_dump_desc))
  747. iwl_mvm_free_fw_dump_desc(mvm);
  748. IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
  749. le32_to_cpu(desc->trig_desc.type));
  750. mvm->fw_dump_desc = desc;
  751. mvm->fw_dump_trig = trigger;
  752. queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
  753. return 0;
  754. }
  755. int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
  756. const char *str, size_t len,
  757. const struct iwl_fw_dbg_trigger_tlv *trigger)
  758. {
  759. struct iwl_mvm_dump_desc *desc;
  760. desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
  761. if (!desc)
  762. return -ENOMEM;
  763. desc->len = len;
  764. desc->trig_desc.type = cpu_to_le32(trig);
  765. memcpy(desc->trig_desc.data, str, len);
  766. return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
  767. }
  768. int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
  769. struct iwl_fw_dbg_trigger_tlv *trigger,
  770. const char *fmt, ...)
  771. {
  772. u16 occurrences = le16_to_cpu(trigger->occurrences);
  773. int ret, len = 0;
  774. char buf[64];
  775. if (!occurrences)
  776. return 0;
  777. if (fmt) {
  778. va_list ap;
  779. buf[sizeof(buf) - 1] = '\0';
  780. va_start(ap, fmt);
  781. vsnprintf(buf, sizeof(buf), fmt, ap);
  782. va_end(ap);
  783. /* check for truncation */
  784. if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
  785. buf[sizeof(buf) - 1] = '\0';
  786. len = strlen(buf) + 1;
  787. }
  788. ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
  789. trigger);
  790. if (ret)
  791. return ret;
  792. trigger->occurrences = cpu_to_le16(occurrences - 1);
  793. return 0;
  794. }
  795. static inline void iwl_mvm_restart_early_start(struct iwl_mvm *mvm)
  796. {
  797. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  798. iwl_clear_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  799. else
  800. iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 1);
  801. }
  802. int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
  803. {
  804. u8 *ptr;
  805. int ret;
  806. int i;
  807. if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
  808. "Invalid configuration %d\n", conf_id))
  809. return -EINVAL;
  810. /* EARLY START - firmware's configuration is hard coded */
  811. if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
  812. !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
  813. conf_id == FW_DBG_START_FROM_ALIVE) {
  814. iwl_mvm_restart_early_start(mvm);
  815. return 0;
  816. }
  817. if (!mvm->fw->dbg_conf_tlv[conf_id])
  818. return -EINVAL;
  819. if (mvm->fw_dbg_conf != FW_DBG_INVALID)
  820. IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
  821. mvm->fw_dbg_conf);
  822. /* Send all HCMDs for configuring the FW debug */
  823. ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
  824. for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
  825. struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
  826. ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
  827. le16_to_cpu(cmd->len), cmd->data);
  828. if (ret)
  829. return ret;
  830. ptr += sizeof(*cmd);
  831. ptr += le16_to_cpu(cmd->len);
  832. }
  833. mvm->fw_dbg_conf = conf_id;
  834. return 0;
  835. }