fw-dbg.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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 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 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. static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
  72. const void *data, size_t datalen)
  73. {
  74. const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
  75. ssize_t bytes_read;
  76. ssize_t bytes_read_trans;
  77. if (offset < dump_ptrs->op_mode_len) {
  78. bytes_read = min_t(ssize_t, count,
  79. dump_ptrs->op_mode_len - offset);
  80. memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
  81. bytes_read);
  82. offset += bytes_read;
  83. count -= bytes_read;
  84. if (count == 0)
  85. return bytes_read;
  86. } else {
  87. bytes_read = 0;
  88. }
  89. if (!dump_ptrs->trans_ptr)
  90. return bytes_read;
  91. offset -= dump_ptrs->op_mode_len;
  92. bytes_read_trans = min_t(ssize_t, count,
  93. dump_ptrs->trans_ptr->len - offset);
  94. memcpy(buffer + bytes_read,
  95. (u8 *)dump_ptrs->trans_ptr->data + offset,
  96. bytes_read_trans);
  97. return bytes_read + bytes_read_trans;
  98. }
  99. static void iwl_mvm_free_coredump(const void *data)
  100. {
  101. const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
  102. vfree(fw_error_dump->op_mode_ptr);
  103. vfree(fw_error_dump->trans_ptr);
  104. kfree(fw_error_dump);
  105. }
  106. #define RADIO_REG_MAX_READ 0x2ad
  107. static void iwl_mvm_read_radio_reg(struct iwl_mvm *mvm,
  108. struct iwl_fw_error_dump_data **dump_data)
  109. {
  110. u8 *pos = (void *)(*dump_data)->data;
  111. unsigned long flags;
  112. int i;
  113. if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
  114. return;
  115. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RADIO_REG);
  116. (*dump_data)->len = cpu_to_le32(RADIO_REG_MAX_READ);
  117. for (i = 0; i < RADIO_REG_MAX_READ; i++) {
  118. u32 rd_cmd = RADIO_RSP_RD_CMD;
  119. rd_cmd |= i << RADIO_RSP_ADDR_POS;
  120. iwl_write_prph_no_grab(mvm->trans, RSP_RADIO_CMD, rd_cmd);
  121. *pos = (u8)iwl_read_prph_no_grab(mvm->trans, RSP_RADIO_RDDAT);
  122. pos++;
  123. }
  124. *dump_data = iwl_fw_error_next_data(*dump_data);
  125. iwl_trans_release_nic_access(mvm->trans, &flags);
  126. }
  127. static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
  128. struct iwl_fw_error_dump_data **dump_data)
  129. {
  130. struct iwl_fw_error_dump_fifo *fifo_hdr;
  131. u32 *fifo_data;
  132. u32 fifo_len;
  133. unsigned long flags;
  134. int i, j;
  135. if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
  136. return;
  137. /* Pull RXF data from all RXFs */
  138. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
  139. /*
  140. * Keep aside the additional offset that might be needed for
  141. * next RXF
  142. */
  143. u32 offset_diff = RXF_DIFF_FROM_PREV * i;
  144. fifo_hdr = (void *)(*dump_data)->data;
  145. fifo_data = (void *)fifo_hdr->data;
  146. fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
  147. /* No need to try to read the data if the length is 0 */
  148. if (fifo_len == 0)
  149. continue;
  150. /* Add a TLV for the RXF */
  151. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
  152. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  153. fifo_hdr->fifo_num = cpu_to_le32(i);
  154. fifo_hdr->available_bytes =
  155. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  156. RXF_RD_D_SPACE +
  157. offset_diff));
  158. fifo_hdr->wr_ptr =
  159. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  160. RXF_RD_WR_PTR +
  161. offset_diff));
  162. fifo_hdr->rd_ptr =
  163. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  164. RXF_RD_RD_PTR +
  165. offset_diff));
  166. fifo_hdr->fence_ptr =
  167. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  168. RXF_RD_FENCE_PTR +
  169. offset_diff));
  170. fifo_hdr->fence_mode =
  171. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  172. RXF_SET_FENCE_MODE +
  173. offset_diff));
  174. /* Lock fence */
  175. iwl_trans_write_prph(mvm->trans,
  176. RXF_SET_FENCE_MODE + offset_diff, 0x1);
  177. /* Set fence pointer to the same place like WR pointer */
  178. iwl_trans_write_prph(mvm->trans,
  179. RXF_LD_WR2FENCE + offset_diff, 0x1);
  180. /* Set fence offset */
  181. iwl_trans_write_prph(mvm->trans,
  182. RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
  183. 0x0);
  184. /* Read FIFO */
  185. fifo_len /= sizeof(u32); /* Size in DWORDS */
  186. for (j = 0; j < fifo_len; j++)
  187. fifo_data[j] = iwl_trans_read_prph(mvm->trans,
  188. RXF_FIFO_RD_FENCE_INC +
  189. offset_diff);
  190. *dump_data = iwl_fw_error_next_data(*dump_data);
  191. }
  192. /* Pull TXF data from all TXFs */
  193. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
  194. /* Mark the number of TXF we're pulling now */
  195. iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
  196. fifo_hdr = (void *)(*dump_data)->data;
  197. fifo_data = (void *)fifo_hdr->data;
  198. fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
  199. /* No need to try to read the data if the length is 0 */
  200. if (fifo_len == 0)
  201. continue;
  202. /* Add a TLV for the FIFO */
  203. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
  204. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  205. fifo_hdr->fifo_num = cpu_to_le32(i);
  206. fifo_hdr->available_bytes =
  207. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  208. TXF_FIFO_ITEM_CNT));
  209. fifo_hdr->wr_ptr =
  210. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  211. TXF_WR_PTR));
  212. fifo_hdr->rd_ptr =
  213. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  214. TXF_RD_PTR));
  215. fifo_hdr->fence_ptr =
  216. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  217. TXF_FENCE_PTR));
  218. fifo_hdr->fence_mode =
  219. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  220. TXF_LOCK_FENCE));
  221. /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
  222. iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
  223. TXF_WR_PTR);
  224. /* Dummy-read to advance the read pointer to the head */
  225. iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
  226. /* Read FIFO */
  227. fifo_len /= sizeof(u32); /* Size in DWORDS */
  228. for (j = 0; j < fifo_len; j++)
  229. fifo_data[j] = iwl_trans_read_prph(mvm->trans,
  230. TXF_READ_MODIFY_DATA);
  231. *dump_data = iwl_fw_error_next_data(*dump_data);
  232. }
  233. iwl_trans_release_nic_access(mvm->trans, &flags);
  234. }
  235. void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
  236. {
  237. if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
  238. return;
  239. kfree(mvm->fw_dump_desc);
  240. mvm->fw_dump_desc = NULL;
  241. }
  242. #define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
  243. #define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
  244. static const struct {
  245. u32 start, end;
  246. } iwl_prph_dump_addr[] = {
  247. { .start = 0x00a00000, .end = 0x00a00000 },
  248. { .start = 0x00a0000c, .end = 0x00a00024 },
  249. { .start = 0x00a0002c, .end = 0x00a0003c },
  250. { .start = 0x00a00410, .end = 0x00a00418 },
  251. { .start = 0x00a00420, .end = 0x00a00420 },
  252. { .start = 0x00a00428, .end = 0x00a00428 },
  253. { .start = 0x00a00430, .end = 0x00a0043c },
  254. { .start = 0x00a00444, .end = 0x00a00444 },
  255. { .start = 0x00a004c0, .end = 0x00a004cc },
  256. { .start = 0x00a004d8, .end = 0x00a004d8 },
  257. { .start = 0x00a004e0, .end = 0x00a004f0 },
  258. { .start = 0x00a00840, .end = 0x00a00840 },
  259. { .start = 0x00a00850, .end = 0x00a00858 },
  260. { .start = 0x00a01004, .end = 0x00a01008 },
  261. { .start = 0x00a01010, .end = 0x00a01010 },
  262. { .start = 0x00a01018, .end = 0x00a01018 },
  263. { .start = 0x00a01024, .end = 0x00a01024 },
  264. { .start = 0x00a0102c, .end = 0x00a01034 },
  265. { .start = 0x00a0103c, .end = 0x00a01040 },
  266. { .start = 0x00a01048, .end = 0x00a01094 },
  267. { .start = 0x00a01c00, .end = 0x00a01c20 },
  268. { .start = 0x00a01c58, .end = 0x00a01c58 },
  269. { .start = 0x00a01c7c, .end = 0x00a01c7c },
  270. { .start = 0x00a01c28, .end = 0x00a01c54 },
  271. { .start = 0x00a01c5c, .end = 0x00a01c5c },
  272. { .start = 0x00a01c60, .end = 0x00a01cdc },
  273. { .start = 0x00a01ce0, .end = 0x00a01d0c },
  274. { .start = 0x00a01d18, .end = 0x00a01d20 },
  275. { .start = 0x00a01d2c, .end = 0x00a01d30 },
  276. { .start = 0x00a01d40, .end = 0x00a01d5c },
  277. { .start = 0x00a01d80, .end = 0x00a01d80 },
  278. { .start = 0x00a01d98, .end = 0x00a01d9c },
  279. { .start = 0x00a01da8, .end = 0x00a01da8 },
  280. { .start = 0x00a01db8, .end = 0x00a01df4 },
  281. { .start = 0x00a01dc0, .end = 0x00a01dfc },
  282. { .start = 0x00a01e00, .end = 0x00a01e2c },
  283. { .start = 0x00a01e40, .end = 0x00a01e60 },
  284. { .start = 0x00a01e68, .end = 0x00a01e6c },
  285. { .start = 0x00a01e74, .end = 0x00a01e74 },
  286. { .start = 0x00a01e84, .end = 0x00a01e90 },
  287. { .start = 0x00a01e9c, .end = 0x00a01ec4 },
  288. { .start = 0x00a01ed0, .end = 0x00a01ee0 },
  289. { .start = 0x00a01f00, .end = 0x00a01f1c },
  290. { .start = 0x00a01f44, .end = 0x00a01ffc },
  291. { .start = 0x00a02000, .end = 0x00a02048 },
  292. { .start = 0x00a02068, .end = 0x00a020f0 },
  293. { .start = 0x00a02100, .end = 0x00a02118 },
  294. { .start = 0x00a02140, .end = 0x00a0214c },
  295. { .start = 0x00a02168, .end = 0x00a0218c },
  296. { .start = 0x00a021c0, .end = 0x00a021c0 },
  297. { .start = 0x00a02400, .end = 0x00a02410 },
  298. { .start = 0x00a02418, .end = 0x00a02420 },
  299. { .start = 0x00a02428, .end = 0x00a0242c },
  300. { .start = 0x00a02434, .end = 0x00a02434 },
  301. { .start = 0x00a02440, .end = 0x00a02460 },
  302. { .start = 0x00a02468, .end = 0x00a024b0 },
  303. { .start = 0x00a024c8, .end = 0x00a024cc },
  304. { .start = 0x00a02500, .end = 0x00a02504 },
  305. { .start = 0x00a0250c, .end = 0x00a02510 },
  306. { .start = 0x00a02540, .end = 0x00a02554 },
  307. { .start = 0x00a02580, .end = 0x00a025f4 },
  308. { .start = 0x00a02600, .end = 0x00a0260c },
  309. { .start = 0x00a02648, .end = 0x00a02650 },
  310. { .start = 0x00a02680, .end = 0x00a02680 },
  311. { .start = 0x00a026c0, .end = 0x00a026d0 },
  312. { .start = 0x00a02700, .end = 0x00a0270c },
  313. { .start = 0x00a02804, .end = 0x00a02804 },
  314. { .start = 0x00a02818, .end = 0x00a0281c },
  315. { .start = 0x00a02c00, .end = 0x00a02db4 },
  316. { .start = 0x00a02df4, .end = 0x00a02fb0 },
  317. { .start = 0x00a03000, .end = 0x00a03014 },
  318. { .start = 0x00a0301c, .end = 0x00a0302c },
  319. { .start = 0x00a03034, .end = 0x00a03038 },
  320. { .start = 0x00a03040, .end = 0x00a03048 },
  321. { .start = 0x00a03060, .end = 0x00a03068 },
  322. { .start = 0x00a03070, .end = 0x00a03074 },
  323. { .start = 0x00a0307c, .end = 0x00a0307c },
  324. { .start = 0x00a03080, .end = 0x00a03084 },
  325. { .start = 0x00a0308c, .end = 0x00a03090 },
  326. { .start = 0x00a03098, .end = 0x00a03098 },
  327. { .start = 0x00a030a0, .end = 0x00a030a0 },
  328. { .start = 0x00a030a8, .end = 0x00a030b4 },
  329. { .start = 0x00a030bc, .end = 0x00a030bc },
  330. { .start = 0x00a030c0, .end = 0x00a0312c },
  331. { .start = 0x00a03c00, .end = 0x00a03c5c },
  332. { .start = 0x00a04400, .end = 0x00a04454 },
  333. { .start = 0x00a04460, .end = 0x00a04474 },
  334. { .start = 0x00a044c0, .end = 0x00a044ec },
  335. { .start = 0x00a04500, .end = 0x00a04504 },
  336. { .start = 0x00a04510, .end = 0x00a04538 },
  337. { .start = 0x00a04540, .end = 0x00a04548 },
  338. { .start = 0x00a04560, .end = 0x00a0457c },
  339. { .start = 0x00a04590, .end = 0x00a04598 },
  340. { .start = 0x00a045c0, .end = 0x00a045f4 },
  341. { .start = 0x00a44000, .end = 0x00a7bf80 },
  342. };
  343. static u32 iwl_dump_prph(struct iwl_trans *trans,
  344. struct iwl_fw_error_dump_data **data)
  345. {
  346. struct iwl_fw_error_dump_prph *prph;
  347. unsigned long flags;
  348. u32 prph_len = 0, i;
  349. if (!iwl_trans_grab_nic_access(trans, &flags))
  350. return 0;
  351. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr); i++) {
  352. /* The range includes both boundaries */
  353. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  354. iwl_prph_dump_addr[i].start + 4;
  355. int reg;
  356. __le32 *val;
  357. prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
  358. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
  359. (*data)->len = cpu_to_le32(sizeof(*prph) +
  360. num_bytes_in_chunk);
  361. prph = (void *)(*data)->data;
  362. prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
  363. val = (void *)prph->data;
  364. for (reg = iwl_prph_dump_addr[i].start;
  365. reg <= iwl_prph_dump_addr[i].end;
  366. reg += 4)
  367. *val++ = cpu_to_le32(iwl_read_prph_no_grab(trans,
  368. reg));
  369. *data = iwl_fw_error_next_data(*data);
  370. }
  371. iwl_trans_release_nic_access(trans, &flags);
  372. return prph_len;
  373. }
  374. void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
  375. {
  376. struct iwl_fw_error_dump_file *dump_file;
  377. struct iwl_fw_error_dump_data *dump_data;
  378. struct iwl_fw_error_dump_info *dump_info;
  379. struct iwl_fw_error_dump_mem *dump_mem;
  380. struct iwl_fw_error_dump_trigger_desc *dump_trig;
  381. struct iwl_mvm_dump_ptrs *fw_error_dump;
  382. u32 sram_len, sram_ofs;
  383. u32 file_len, fifo_data_len = 0, prph_len = 0, radio_len = 0;
  384. u32 smem_len = mvm->cfg->smem_len;
  385. u32 sram2_len = mvm->cfg->dccm2_len;
  386. bool monitor_dump_only = false;
  387. int i;
  388. if (!IWL_MVM_COLLECT_FW_ERR_DUMP &&
  389. !mvm->trans->dbg_dest_tlv)
  390. return;
  391. lockdep_assert_held(&mvm->mutex);
  392. /* there's no point in fw dump if the bus is dead */
  393. if (test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
  394. IWL_ERR(mvm, "Skip fw error dump since bus is dead\n");
  395. goto out;
  396. }
  397. if (mvm->fw_dump_trig &&
  398. mvm->fw_dump_trig->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)
  399. monitor_dump_only = true;
  400. fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
  401. if (!fw_error_dump)
  402. goto out;
  403. /* SRAM - include stack CCM if driver knows the values for it */
  404. if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
  405. const struct fw_img *img;
  406. img = &mvm->fw->img[mvm->cur_ucode];
  407. sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  408. sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  409. } else {
  410. sram_ofs = mvm->cfg->dccm_offset;
  411. sram_len = mvm->cfg->dccm_len;
  412. }
  413. /* reading RXF/TXF sizes */
  414. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  415. struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
  416. fifo_data_len = 0;
  417. /* Count RXF size */
  418. for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
  419. if (!mem_cfg->rxfifo_size[i])
  420. continue;
  421. /* Add header info */
  422. fifo_data_len += mem_cfg->rxfifo_size[i] +
  423. sizeof(*dump_data) +
  424. sizeof(struct iwl_fw_error_dump_fifo);
  425. }
  426. for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
  427. if (!mem_cfg->txfifo_size[i])
  428. continue;
  429. /* Add header info */
  430. fifo_data_len += mem_cfg->txfifo_size[i] +
  431. sizeof(*dump_data) +
  432. sizeof(struct iwl_fw_error_dump_fifo);
  433. }
  434. /* Make room for PRPH registers */
  435. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr); i++) {
  436. /* The range includes both boundaries */
  437. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  438. iwl_prph_dump_addr[i].start + 4;
  439. prph_len += sizeof(*dump_data) +
  440. sizeof(struct iwl_fw_error_dump_prph) +
  441. num_bytes_in_chunk;
  442. }
  443. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  444. radio_len = sizeof(*dump_data) + RADIO_REG_MAX_READ;
  445. }
  446. file_len = sizeof(*dump_file) +
  447. sizeof(*dump_data) * 2 +
  448. sram_len + sizeof(*dump_mem) +
  449. fifo_data_len +
  450. prph_len +
  451. radio_len +
  452. sizeof(*dump_info);
  453. /* Make room for the SMEM, if it exists */
  454. if (smem_len)
  455. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
  456. /* Make room for the secondary SRAM, if it exists */
  457. if (sram2_len)
  458. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
  459. /* Make room for fw's virtual image pages, if it exists */
  460. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size)
  461. file_len += mvm->num_of_paging_blk *
  462. (sizeof(*dump_data) +
  463. sizeof(struct iwl_fw_error_dump_paging) +
  464. PAGING_BLOCK_SIZE);
  465. /* If we only want a monitor dump, reset the file length */
  466. if (monitor_dump_only) {
  467. file_len = sizeof(*dump_file) + sizeof(*dump_data) +
  468. sizeof(*dump_info);
  469. }
  470. /*
  471. * In 8000 HW family B-step include the ICCM (which resides separately)
  472. */
  473. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  474. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP)
  475. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  476. IWL8260_ICCM_LEN;
  477. if (mvm->fw_dump_desc)
  478. file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
  479. mvm->fw_dump_desc->len;
  480. dump_file = vzalloc(file_len);
  481. if (!dump_file) {
  482. kfree(fw_error_dump);
  483. goto out;
  484. }
  485. fw_error_dump->op_mode_ptr = dump_file;
  486. dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
  487. dump_data = (void *)dump_file->data;
  488. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
  489. dump_data->len = cpu_to_le32(sizeof(*dump_info));
  490. dump_info = (void *)dump_data->data;
  491. dump_info->device_family =
  492. mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
  493. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
  494. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
  495. dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
  496. memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
  497. sizeof(dump_info->fw_human_readable));
  498. strncpy(dump_info->dev_human_readable, mvm->cfg->name,
  499. sizeof(dump_info->dev_human_readable));
  500. strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
  501. sizeof(dump_info->bus_human_readable));
  502. dump_data = iwl_fw_error_next_data(dump_data);
  503. /* We only dump the FIFOs if the FW is in error state */
  504. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  505. iwl_mvm_dump_fifos(mvm, &dump_data);
  506. if (radio_len)
  507. iwl_mvm_read_radio_reg(mvm, &dump_data);
  508. }
  509. if (mvm->fw_dump_desc) {
  510. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
  511. dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
  512. mvm->fw_dump_desc->len);
  513. dump_trig = (void *)dump_data->data;
  514. memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
  515. sizeof(*dump_trig) + mvm->fw_dump_desc->len);
  516. dump_data = iwl_fw_error_next_data(dump_data);
  517. }
  518. /* In case we only want monitor dump, skip to dump trasport data */
  519. if (monitor_dump_only)
  520. goto dump_trans_data;
  521. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  522. dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
  523. dump_mem = (void *)dump_data->data;
  524. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  525. dump_mem->offset = cpu_to_le32(sram_ofs);
  526. iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
  527. sram_len);
  528. if (smem_len) {
  529. dump_data = iwl_fw_error_next_data(dump_data);
  530. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  531. dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
  532. dump_mem = (void *)dump_data->data;
  533. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
  534. dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
  535. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
  536. dump_mem->data, smem_len);
  537. }
  538. if (sram2_len) {
  539. dump_data = iwl_fw_error_next_data(dump_data);
  540. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  541. dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
  542. dump_mem = (void *)dump_data->data;
  543. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  544. dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
  545. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
  546. dump_mem->data, sram2_len);
  547. }
  548. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  549. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP) {
  550. dump_data = iwl_fw_error_next_data(dump_data);
  551. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  552. dump_data->len = cpu_to_le32(IWL8260_ICCM_LEN +
  553. sizeof(*dump_mem));
  554. dump_mem = (void *)dump_data->data;
  555. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  556. dump_mem->offset = cpu_to_le32(IWL8260_ICCM_OFFSET);
  557. iwl_trans_read_mem_bytes(mvm->trans, IWL8260_ICCM_OFFSET,
  558. dump_mem->data, IWL8260_ICCM_LEN);
  559. }
  560. /* Dump fw's virtual image */
  561. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size) {
  562. for (i = 1; i < mvm->num_of_paging_blk + 1; i++) {
  563. struct iwl_fw_error_dump_paging *paging;
  564. struct page *pages =
  565. mvm->fw_paging_db[i].fw_paging_block;
  566. dump_data = iwl_fw_error_next_data(dump_data);
  567. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
  568. dump_data->len = cpu_to_le32(sizeof(*paging) +
  569. PAGING_BLOCK_SIZE);
  570. paging = (void *)dump_data->data;
  571. paging->index = cpu_to_le32(i);
  572. memcpy(paging->data, page_address(pages),
  573. PAGING_BLOCK_SIZE);
  574. }
  575. }
  576. dump_data = iwl_fw_error_next_data(dump_data);
  577. if (prph_len)
  578. iwl_dump_prph(mvm->trans, &dump_data);
  579. dump_trans_data:
  580. fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans,
  581. mvm->fw_dump_trig);
  582. fw_error_dump->op_mode_len = file_len;
  583. if (fw_error_dump->trans_ptr)
  584. file_len += fw_error_dump->trans_ptr->len;
  585. dump_file->file_len = cpu_to_le32(file_len);
  586. dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
  587. GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
  588. out:
  589. iwl_mvm_free_fw_dump_desc(mvm);
  590. mvm->fw_dump_trig = NULL;
  591. clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
  592. }
  593. const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
  594. .trig_desc = {
  595. .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
  596. },
  597. };
  598. int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
  599. const struct iwl_mvm_dump_desc *desc,
  600. const struct iwl_fw_dbg_trigger_tlv *trigger)
  601. {
  602. unsigned int delay = 0;
  603. if (trigger)
  604. delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
  605. if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
  606. return -EBUSY;
  607. if (WARN_ON(mvm->fw_dump_desc))
  608. iwl_mvm_free_fw_dump_desc(mvm);
  609. IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
  610. le32_to_cpu(desc->trig_desc.type));
  611. mvm->fw_dump_desc = desc;
  612. mvm->fw_dump_trig = trigger;
  613. queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
  614. return 0;
  615. }
  616. int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
  617. const char *str, size_t len,
  618. const struct iwl_fw_dbg_trigger_tlv *trigger)
  619. {
  620. struct iwl_mvm_dump_desc *desc;
  621. desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
  622. if (!desc)
  623. return -ENOMEM;
  624. desc->len = len;
  625. desc->trig_desc.type = cpu_to_le32(trig);
  626. memcpy(desc->trig_desc.data, str, len);
  627. return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
  628. }
  629. int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
  630. struct iwl_fw_dbg_trigger_tlv *trigger,
  631. const char *fmt, ...)
  632. {
  633. u16 occurrences = le16_to_cpu(trigger->occurrences);
  634. int ret, len = 0;
  635. char buf[64];
  636. if (!occurrences)
  637. return 0;
  638. if (fmt) {
  639. va_list ap;
  640. buf[sizeof(buf) - 1] = '\0';
  641. va_start(ap, fmt);
  642. vsnprintf(buf, sizeof(buf), fmt, ap);
  643. va_end(ap);
  644. /* check for truncation */
  645. if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
  646. buf[sizeof(buf) - 1] = '\0';
  647. len = strlen(buf) + 1;
  648. }
  649. ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
  650. trigger);
  651. if (ret)
  652. return ret;
  653. trigger->occurrences = cpu_to_le16(occurrences - 1);
  654. return 0;
  655. }
  656. static inline void iwl_mvm_restart_early_start(struct iwl_mvm *mvm)
  657. {
  658. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  659. iwl_clear_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  660. else
  661. iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 1);
  662. }
  663. int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
  664. {
  665. u8 *ptr;
  666. int ret;
  667. int i;
  668. if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
  669. "Invalid configuration %d\n", conf_id))
  670. return -EINVAL;
  671. /* EARLY START - firmware's configuration is hard coded */
  672. if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
  673. !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
  674. conf_id == FW_DBG_START_FROM_ALIVE) {
  675. iwl_mvm_restart_early_start(mvm);
  676. return 0;
  677. }
  678. if (!mvm->fw->dbg_conf_tlv[conf_id])
  679. return -EINVAL;
  680. if (mvm->fw_dbg_conf != FW_DBG_INVALID)
  681. IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
  682. mvm->fw_dbg_conf);
  683. /* Send all HCMDs for configuring the FW debug */
  684. ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
  685. for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
  686. struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
  687. ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
  688. le16_to_cpu(cmd->len), cmd->data);
  689. if (ret)
  690. return ret;
  691. ptr += sizeof(*cmd);
  692. ptr += le16_to_cpu(cmd->len);
  693. }
  694. mvm->fw_dbg_conf = conf_id;
  695. return ret;
  696. }