fw-dbg.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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. static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
  72. 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(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. if (fw_has_capa(&mvm->fw->ucode_capa,
  234. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  235. /* Pull UMAC internal TXF data from all TXFs */
  236. for (i = 0;
  237. i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size);
  238. i++) {
  239. fifo_hdr = (void *)(*dump_data)->data;
  240. fifo_data = (void *)fifo_hdr->data;
  241. fifo_len = mvm->shared_mem_cfg.internal_txfifo_size[i];
  242. /* No need to try to read the data if the length is 0 */
  243. if (fifo_len == 0)
  244. continue;
  245. /* Add a TLV for the internal FIFOs */
  246. (*dump_data)->type =
  247. cpu_to_le32(IWL_FW_ERROR_DUMP_INTERNAL_TXF);
  248. (*dump_data)->len =
  249. cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  250. fifo_hdr->fifo_num = cpu_to_le32(i);
  251. /* Mark the number of TXF we're pulling now */
  252. iwl_trans_write_prph(mvm->trans, TXF_CPU2_NUM, i +
  253. ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size));
  254. fifo_hdr->available_bytes =
  255. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  256. TXF_CPU2_FIFO_ITEM_CNT));
  257. fifo_hdr->wr_ptr =
  258. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  259. TXF_CPU2_WR_PTR));
  260. fifo_hdr->rd_ptr =
  261. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  262. TXF_CPU2_RD_PTR));
  263. fifo_hdr->fence_ptr =
  264. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  265. TXF_CPU2_FENCE_PTR));
  266. fifo_hdr->fence_mode =
  267. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  268. TXF_CPU2_LOCK_FENCE));
  269. /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */
  270. iwl_trans_write_prph(mvm->trans,
  271. TXF_CPU2_READ_MODIFY_ADDR,
  272. TXF_CPU2_WR_PTR);
  273. /* Dummy-read to advance the read pointer to head */
  274. iwl_trans_read_prph(mvm->trans,
  275. TXF_CPU2_READ_MODIFY_DATA);
  276. /* Read FIFO */
  277. fifo_len /= sizeof(u32); /* Size in DWORDS */
  278. for (j = 0; j < fifo_len; j++)
  279. fifo_data[j] =
  280. iwl_trans_read_prph(mvm->trans,
  281. TXF_CPU2_READ_MODIFY_DATA);
  282. *dump_data = iwl_fw_error_next_data(*dump_data);
  283. }
  284. }
  285. iwl_trans_release_nic_access(mvm->trans, &flags);
  286. }
  287. void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
  288. {
  289. if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
  290. return;
  291. kfree(mvm->fw_dump_desc);
  292. mvm->fw_dump_desc = NULL;
  293. }
  294. #define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
  295. #define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
  296. struct iwl_prph_range {
  297. u32 start, end;
  298. };
  299. static const struct iwl_prph_range iwl_prph_dump_addr_comm[] = {
  300. { .start = 0x00a00000, .end = 0x00a00000 },
  301. { .start = 0x00a0000c, .end = 0x00a00024 },
  302. { .start = 0x00a0002c, .end = 0x00a0003c },
  303. { .start = 0x00a00410, .end = 0x00a00418 },
  304. { .start = 0x00a00420, .end = 0x00a00420 },
  305. { .start = 0x00a00428, .end = 0x00a00428 },
  306. { .start = 0x00a00430, .end = 0x00a0043c },
  307. { .start = 0x00a00444, .end = 0x00a00444 },
  308. { .start = 0x00a004c0, .end = 0x00a004cc },
  309. { .start = 0x00a004d8, .end = 0x00a004d8 },
  310. { .start = 0x00a004e0, .end = 0x00a004f0 },
  311. { .start = 0x00a00840, .end = 0x00a00840 },
  312. { .start = 0x00a00850, .end = 0x00a00858 },
  313. { .start = 0x00a01004, .end = 0x00a01008 },
  314. { .start = 0x00a01010, .end = 0x00a01010 },
  315. { .start = 0x00a01018, .end = 0x00a01018 },
  316. { .start = 0x00a01024, .end = 0x00a01024 },
  317. { .start = 0x00a0102c, .end = 0x00a01034 },
  318. { .start = 0x00a0103c, .end = 0x00a01040 },
  319. { .start = 0x00a01048, .end = 0x00a01094 },
  320. { .start = 0x00a01c00, .end = 0x00a01c20 },
  321. { .start = 0x00a01c58, .end = 0x00a01c58 },
  322. { .start = 0x00a01c7c, .end = 0x00a01c7c },
  323. { .start = 0x00a01c28, .end = 0x00a01c54 },
  324. { .start = 0x00a01c5c, .end = 0x00a01c5c },
  325. { .start = 0x00a01c60, .end = 0x00a01cdc },
  326. { .start = 0x00a01ce0, .end = 0x00a01d0c },
  327. { .start = 0x00a01d18, .end = 0x00a01d20 },
  328. { .start = 0x00a01d2c, .end = 0x00a01d30 },
  329. { .start = 0x00a01d40, .end = 0x00a01d5c },
  330. { .start = 0x00a01d80, .end = 0x00a01d80 },
  331. { .start = 0x00a01d98, .end = 0x00a01d9c },
  332. { .start = 0x00a01da8, .end = 0x00a01da8 },
  333. { .start = 0x00a01db8, .end = 0x00a01df4 },
  334. { .start = 0x00a01dc0, .end = 0x00a01dfc },
  335. { .start = 0x00a01e00, .end = 0x00a01e2c },
  336. { .start = 0x00a01e40, .end = 0x00a01e60 },
  337. { .start = 0x00a01e68, .end = 0x00a01e6c },
  338. { .start = 0x00a01e74, .end = 0x00a01e74 },
  339. { .start = 0x00a01e84, .end = 0x00a01e90 },
  340. { .start = 0x00a01e9c, .end = 0x00a01ec4 },
  341. { .start = 0x00a01ed0, .end = 0x00a01ee0 },
  342. { .start = 0x00a01f00, .end = 0x00a01f1c },
  343. { .start = 0x00a01f44, .end = 0x00a01ffc },
  344. { .start = 0x00a02000, .end = 0x00a02048 },
  345. { .start = 0x00a02068, .end = 0x00a020f0 },
  346. { .start = 0x00a02100, .end = 0x00a02118 },
  347. { .start = 0x00a02140, .end = 0x00a0214c },
  348. { .start = 0x00a02168, .end = 0x00a0218c },
  349. { .start = 0x00a021c0, .end = 0x00a021c0 },
  350. { .start = 0x00a02400, .end = 0x00a02410 },
  351. { .start = 0x00a02418, .end = 0x00a02420 },
  352. { .start = 0x00a02428, .end = 0x00a0242c },
  353. { .start = 0x00a02434, .end = 0x00a02434 },
  354. { .start = 0x00a02440, .end = 0x00a02460 },
  355. { .start = 0x00a02468, .end = 0x00a024b0 },
  356. { .start = 0x00a024c8, .end = 0x00a024cc },
  357. { .start = 0x00a02500, .end = 0x00a02504 },
  358. { .start = 0x00a0250c, .end = 0x00a02510 },
  359. { .start = 0x00a02540, .end = 0x00a02554 },
  360. { .start = 0x00a02580, .end = 0x00a025f4 },
  361. { .start = 0x00a02600, .end = 0x00a0260c },
  362. { .start = 0x00a02648, .end = 0x00a02650 },
  363. { .start = 0x00a02680, .end = 0x00a02680 },
  364. { .start = 0x00a026c0, .end = 0x00a026d0 },
  365. { .start = 0x00a02700, .end = 0x00a0270c },
  366. { .start = 0x00a02804, .end = 0x00a02804 },
  367. { .start = 0x00a02818, .end = 0x00a0281c },
  368. { .start = 0x00a02c00, .end = 0x00a02db4 },
  369. { .start = 0x00a02df4, .end = 0x00a02fb0 },
  370. { .start = 0x00a03000, .end = 0x00a03014 },
  371. { .start = 0x00a0301c, .end = 0x00a0302c },
  372. { .start = 0x00a03034, .end = 0x00a03038 },
  373. { .start = 0x00a03040, .end = 0x00a03048 },
  374. { .start = 0x00a03060, .end = 0x00a03068 },
  375. { .start = 0x00a03070, .end = 0x00a03074 },
  376. { .start = 0x00a0307c, .end = 0x00a0307c },
  377. { .start = 0x00a03080, .end = 0x00a03084 },
  378. { .start = 0x00a0308c, .end = 0x00a03090 },
  379. { .start = 0x00a03098, .end = 0x00a03098 },
  380. { .start = 0x00a030a0, .end = 0x00a030a0 },
  381. { .start = 0x00a030a8, .end = 0x00a030b4 },
  382. { .start = 0x00a030bc, .end = 0x00a030bc },
  383. { .start = 0x00a030c0, .end = 0x00a0312c },
  384. { .start = 0x00a03c00, .end = 0x00a03c5c },
  385. { .start = 0x00a04400, .end = 0x00a04454 },
  386. { .start = 0x00a04460, .end = 0x00a04474 },
  387. { .start = 0x00a044c0, .end = 0x00a044ec },
  388. { .start = 0x00a04500, .end = 0x00a04504 },
  389. { .start = 0x00a04510, .end = 0x00a04538 },
  390. { .start = 0x00a04540, .end = 0x00a04548 },
  391. { .start = 0x00a04560, .end = 0x00a0457c },
  392. { .start = 0x00a04590, .end = 0x00a04598 },
  393. { .start = 0x00a045c0, .end = 0x00a045f4 },
  394. { .start = 0x00a44000, .end = 0x00a7bf80 },
  395. };
  396. static const struct iwl_prph_range iwl_prph_dump_addr_9000[] = {
  397. { .start = 0x00a05c00, .end = 0x00a05c18 },
  398. { .start = 0x00a05400, .end = 0x00a056e8 },
  399. { .start = 0x00a08000, .end = 0x00a098bc },
  400. { .start = 0x00adfc00, .end = 0x00adfd1c },
  401. { .start = 0x00a02400, .end = 0x00a02758 },
  402. };
  403. static u32 iwl_dump_prph(struct iwl_trans *trans,
  404. struct iwl_fw_error_dump_data **data,
  405. const struct iwl_prph_range *iwl_prph_dump_addr,
  406. u32 range_len)
  407. {
  408. struct iwl_fw_error_dump_prph *prph;
  409. unsigned long flags;
  410. u32 prph_len = 0, i;
  411. if (!iwl_trans_grab_nic_access(trans, &flags))
  412. return 0;
  413. for (i = 0; i < range_len; i++) {
  414. /* The range includes both boundaries */
  415. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  416. iwl_prph_dump_addr[i].start + 4;
  417. int reg;
  418. __le32 *val;
  419. prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
  420. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
  421. (*data)->len = cpu_to_le32(sizeof(*prph) +
  422. num_bytes_in_chunk);
  423. prph = (void *)(*data)->data;
  424. prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
  425. val = (void *)prph->data;
  426. for (reg = iwl_prph_dump_addr[i].start;
  427. reg <= iwl_prph_dump_addr[i].end;
  428. reg += 4)
  429. *val++ = cpu_to_le32(iwl_read_prph_no_grab(trans,
  430. reg));
  431. *data = iwl_fw_error_next_data(*data);
  432. }
  433. iwl_trans_release_nic_access(trans, &flags);
  434. return prph_len;
  435. }
  436. void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
  437. {
  438. struct iwl_fw_error_dump_file *dump_file;
  439. struct iwl_fw_error_dump_data *dump_data;
  440. struct iwl_fw_error_dump_info *dump_info;
  441. struct iwl_fw_error_dump_mem *dump_mem;
  442. struct iwl_fw_error_dump_trigger_desc *dump_trig;
  443. struct iwl_mvm_dump_ptrs *fw_error_dump;
  444. u32 sram_len, sram_ofs;
  445. struct iwl_fw_dbg_mem_seg_tlv * const *fw_dbg_mem =
  446. mvm->fw->dbg_mem_tlv;
  447. u32 file_len, fifo_data_len = 0, prph_len = 0, radio_len = 0;
  448. u32 smem_len = mvm->fw->dbg_dynamic_mem ? 0 : mvm->cfg->smem_len;
  449. u32 sram2_len = mvm->fw->dbg_dynamic_mem ? 0 : mvm->cfg->dccm2_len;
  450. bool monitor_dump_only = false;
  451. int i;
  452. if (!IWL_MVM_COLLECT_FW_ERR_DUMP &&
  453. !mvm->trans->dbg_dest_tlv)
  454. return;
  455. lockdep_assert_held(&mvm->mutex);
  456. /* there's no point in fw dump if the bus is dead */
  457. if (test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
  458. IWL_ERR(mvm, "Skip fw error dump since bus is dead\n");
  459. goto out;
  460. }
  461. if (mvm->fw_dump_trig &&
  462. mvm->fw_dump_trig->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)
  463. monitor_dump_only = true;
  464. fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
  465. if (!fw_error_dump)
  466. goto out;
  467. /* SRAM - include stack CCM if driver knows the values for it */
  468. if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
  469. const struct fw_img *img;
  470. img = &mvm->fw->img[mvm->cur_ucode];
  471. sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  472. sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  473. } else {
  474. sram_ofs = mvm->cfg->dccm_offset;
  475. sram_len = mvm->cfg->dccm_len;
  476. }
  477. /* reading RXF/TXF sizes */
  478. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  479. struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
  480. fifo_data_len = 0;
  481. /* Count RXF size */
  482. for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
  483. if (!mem_cfg->rxfifo_size[i])
  484. continue;
  485. /* Add header info */
  486. fifo_data_len += mem_cfg->rxfifo_size[i] +
  487. sizeof(*dump_data) +
  488. sizeof(struct iwl_fw_error_dump_fifo);
  489. }
  490. for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
  491. if (!mem_cfg->txfifo_size[i])
  492. continue;
  493. /* Add header info */
  494. fifo_data_len += mem_cfg->txfifo_size[i] +
  495. sizeof(*dump_data) +
  496. sizeof(struct iwl_fw_error_dump_fifo);
  497. }
  498. if (fw_has_capa(&mvm->fw->ucode_capa,
  499. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  500. for (i = 0;
  501. i < ARRAY_SIZE(mem_cfg->internal_txfifo_size);
  502. i++) {
  503. if (!mem_cfg->internal_txfifo_size[i])
  504. continue;
  505. /* Add header info */
  506. fifo_data_len +=
  507. mem_cfg->internal_txfifo_size[i] +
  508. sizeof(*dump_data) +
  509. sizeof(struct iwl_fw_error_dump_fifo);
  510. }
  511. }
  512. /* Make room for PRPH registers */
  513. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr_comm); i++) {
  514. /* The range includes both boundaries */
  515. int num_bytes_in_chunk =
  516. iwl_prph_dump_addr_comm[i].end -
  517. iwl_prph_dump_addr_comm[i].start + 4;
  518. prph_len += sizeof(*dump_data) +
  519. sizeof(struct iwl_fw_error_dump_prph) +
  520. num_bytes_in_chunk;
  521. }
  522. if (mvm->cfg->mq_rx_supported) {
  523. for (i = 0; i <
  524. ARRAY_SIZE(iwl_prph_dump_addr_9000); i++) {
  525. /* The range includes both boundaries */
  526. int num_bytes_in_chunk =
  527. iwl_prph_dump_addr_9000[i].end -
  528. iwl_prph_dump_addr_9000[i].start + 4;
  529. prph_len += sizeof(*dump_data) +
  530. sizeof(struct iwl_fw_error_dump_prph) +
  531. num_bytes_in_chunk;
  532. }
  533. }
  534. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  535. radio_len = sizeof(*dump_data) + RADIO_REG_MAX_READ;
  536. }
  537. file_len = sizeof(*dump_file) +
  538. sizeof(*dump_data) * 2 +
  539. fifo_data_len +
  540. prph_len +
  541. radio_len +
  542. sizeof(*dump_info);
  543. /* Make room for the SMEM, if it exists */
  544. if (smem_len)
  545. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
  546. /* Make room for the secondary SRAM, if it exists */
  547. if (sram2_len)
  548. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
  549. /* Make room for MEM segments */
  550. for (i = 0; i < ARRAY_SIZE(mvm->fw->dbg_mem_tlv); i++) {
  551. if (fw_dbg_mem[i])
  552. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  553. le32_to_cpu(fw_dbg_mem[i]->len);
  554. }
  555. /* Make room for fw's virtual image pages, if it exists */
  556. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
  557. mvm->fw_paging_db[0].fw_paging_block)
  558. file_len += mvm->num_of_paging_blk *
  559. (sizeof(*dump_data) +
  560. sizeof(struct iwl_fw_error_dump_paging) +
  561. PAGING_BLOCK_SIZE);
  562. /* If we only want a monitor dump, reset the file length */
  563. if (monitor_dump_only) {
  564. file_len = sizeof(*dump_file) + sizeof(*dump_data) +
  565. sizeof(*dump_info);
  566. }
  567. /*
  568. * In 8000 HW family B-step include the ICCM (which resides separately)
  569. */
  570. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  571. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP)
  572. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  573. IWL8260_ICCM_LEN;
  574. if (mvm->fw_dump_desc)
  575. file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
  576. mvm->fw_dump_desc->len;
  577. if (!mvm->fw->dbg_dynamic_mem)
  578. file_len += sram_len + sizeof(*dump_mem);
  579. dump_file = vzalloc(file_len);
  580. if (!dump_file) {
  581. kfree(fw_error_dump);
  582. goto out;
  583. }
  584. fw_error_dump->op_mode_ptr = dump_file;
  585. dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
  586. dump_data = (void *)dump_file->data;
  587. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
  588. dump_data->len = cpu_to_le32(sizeof(*dump_info));
  589. dump_info = (void *)dump_data->data;
  590. dump_info->device_family =
  591. mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
  592. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
  593. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
  594. dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
  595. memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
  596. sizeof(dump_info->fw_human_readable));
  597. strncpy(dump_info->dev_human_readable, mvm->cfg->name,
  598. sizeof(dump_info->dev_human_readable));
  599. strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
  600. sizeof(dump_info->bus_human_readable));
  601. dump_data = iwl_fw_error_next_data(dump_data);
  602. /* We only dump the FIFOs if the FW is in error state */
  603. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  604. iwl_mvm_dump_fifos(mvm, &dump_data);
  605. if (radio_len)
  606. iwl_mvm_read_radio_reg(mvm, &dump_data);
  607. }
  608. if (mvm->fw_dump_desc) {
  609. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
  610. dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
  611. mvm->fw_dump_desc->len);
  612. dump_trig = (void *)dump_data->data;
  613. memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
  614. sizeof(*dump_trig) + mvm->fw_dump_desc->len);
  615. dump_data = iwl_fw_error_next_data(dump_data);
  616. }
  617. /* In case we only want monitor dump, skip to dump trasport data */
  618. if (monitor_dump_only)
  619. goto dump_trans_data;
  620. if (!mvm->fw->dbg_dynamic_mem) {
  621. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  622. dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
  623. dump_mem = (void *)dump_data->data;
  624. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  625. dump_mem->offset = cpu_to_le32(sram_ofs);
  626. iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
  627. sram_len);
  628. dump_data = iwl_fw_error_next_data(dump_data);
  629. }
  630. for (i = 0; i < ARRAY_SIZE(mvm->fw->dbg_mem_tlv); i++) {
  631. if (fw_dbg_mem[i]) {
  632. u32 len = le32_to_cpu(fw_dbg_mem[i]->len);
  633. u32 ofs = le32_to_cpu(fw_dbg_mem[i]->ofs);
  634. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  635. dump_data->len = cpu_to_le32(len +
  636. sizeof(*dump_mem));
  637. dump_mem = (void *)dump_data->data;
  638. dump_mem->type = fw_dbg_mem[i]->data_type;
  639. dump_mem->offset = cpu_to_le32(ofs);
  640. iwl_trans_read_mem_bytes(mvm->trans, ofs,
  641. dump_mem->data,
  642. len);
  643. dump_data = iwl_fw_error_next_data(dump_data);
  644. }
  645. }
  646. if (smem_len) {
  647. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  648. dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
  649. dump_mem = (void *)dump_data->data;
  650. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
  651. dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
  652. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
  653. dump_mem->data, smem_len);
  654. dump_data = iwl_fw_error_next_data(dump_data);
  655. }
  656. if (sram2_len) {
  657. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  658. dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
  659. dump_mem = (void *)dump_data->data;
  660. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  661. dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
  662. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
  663. dump_mem->data, sram2_len);
  664. dump_data = iwl_fw_error_next_data(dump_data);
  665. }
  666. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  667. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP) {
  668. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  669. dump_data->len = cpu_to_le32(IWL8260_ICCM_LEN +
  670. sizeof(*dump_mem));
  671. dump_mem = (void *)dump_data->data;
  672. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  673. dump_mem->offset = cpu_to_le32(IWL8260_ICCM_OFFSET);
  674. iwl_trans_read_mem_bytes(mvm->trans, IWL8260_ICCM_OFFSET,
  675. dump_mem->data, IWL8260_ICCM_LEN);
  676. dump_data = iwl_fw_error_next_data(dump_data);
  677. }
  678. /* Dump fw's virtual image */
  679. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
  680. mvm->fw_paging_db[0].fw_paging_block) {
  681. for (i = 1; i < mvm->num_of_paging_blk + 1; i++) {
  682. struct iwl_fw_error_dump_paging *paging;
  683. struct page *pages =
  684. mvm->fw_paging_db[i].fw_paging_block;
  685. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
  686. dump_data->len = cpu_to_le32(sizeof(*paging) +
  687. PAGING_BLOCK_SIZE);
  688. paging = (void *)dump_data->data;
  689. paging->index = cpu_to_le32(i);
  690. memcpy(paging->data, page_address(pages),
  691. PAGING_BLOCK_SIZE);
  692. dump_data = iwl_fw_error_next_data(dump_data);
  693. }
  694. }
  695. if (prph_len) {
  696. iwl_dump_prph(mvm->trans, &dump_data,
  697. iwl_prph_dump_addr_comm,
  698. ARRAY_SIZE(iwl_prph_dump_addr_comm));
  699. if (mvm->cfg->mq_rx_supported)
  700. iwl_dump_prph(mvm->trans, &dump_data,
  701. iwl_prph_dump_addr_9000,
  702. ARRAY_SIZE(iwl_prph_dump_addr_9000));
  703. }
  704. dump_trans_data:
  705. fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans,
  706. mvm->fw_dump_trig);
  707. fw_error_dump->op_mode_len = file_len;
  708. if (fw_error_dump->trans_ptr)
  709. file_len += fw_error_dump->trans_ptr->len;
  710. dump_file->file_len = cpu_to_le32(file_len);
  711. dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
  712. GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
  713. out:
  714. iwl_mvm_free_fw_dump_desc(mvm);
  715. mvm->fw_dump_trig = NULL;
  716. clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
  717. }
  718. const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
  719. .trig_desc = {
  720. .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
  721. },
  722. };
  723. int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
  724. const struct iwl_mvm_dump_desc *desc,
  725. const struct iwl_fw_dbg_trigger_tlv *trigger)
  726. {
  727. unsigned int delay = 0;
  728. if (trigger)
  729. delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
  730. if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
  731. return -EBUSY;
  732. if (WARN_ON(mvm->fw_dump_desc))
  733. iwl_mvm_free_fw_dump_desc(mvm);
  734. IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
  735. le32_to_cpu(desc->trig_desc.type));
  736. mvm->fw_dump_desc = desc;
  737. mvm->fw_dump_trig = trigger;
  738. queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
  739. return 0;
  740. }
  741. int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
  742. const char *str, size_t len,
  743. const struct iwl_fw_dbg_trigger_tlv *trigger)
  744. {
  745. struct iwl_mvm_dump_desc *desc;
  746. desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
  747. if (!desc)
  748. return -ENOMEM;
  749. desc->len = len;
  750. desc->trig_desc.type = cpu_to_le32(trig);
  751. memcpy(desc->trig_desc.data, str, len);
  752. return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
  753. }
  754. int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
  755. struct iwl_fw_dbg_trigger_tlv *trigger,
  756. const char *fmt, ...)
  757. {
  758. u16 occurrences = le16_to_cpu(trigger->occurrences);
  759. int ret, len = 0;
  760. char buf[64];
  761. if (!occurrences)
  762. return 0;
  763. if (fmt) {
  764. va_list ap;
  765. buf[sizeof(buf) - 1] = '\0';
  766. va_start(ap, fmt);
  767. vsnprintf(buf, sizeof(buf), fmt, ap);
  768. va_end(ap);
  769. /* check for truncation */
  770. if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
  771. buf[sizeof(buf) - 1] = '\0';
  772. len = strlen(buf) + 1;
  773. }
  774. ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
  775. trigger);
  776. if (ret)
  777. return ret;
  778. trigger->occurrences = cpu_to_le16(occurrences - 1);
  779. return 0;
  780. }
  781. static inline void iwl_mvm_restart_early_start(struct iwl_mvm *mvm)
  782. {
  783. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  784. iwl_clear_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  785. else
  786. iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 1);
  787. }
  788. int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
  789. {
  790. u8 *ptr;
  791. int ret;
  792. int i;
  793. if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
  794. "Invalid configuration %d\n", conf_id))
  795. return -EINVAL;
  796. /* EARLY START - firmware's configuration is hard coded */
  797. if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
  798. !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
  799. conf_id == FW_DBG_START_FROM_ALIVE) {
  800. iwl_mvm_restart_early_start(mvm);
  801. return 0;
  802. }
  803. if (!mvm->fw->dbg_conf_tlv[conf_id])
  804. return -EINVAL;
  805. if (mvm->fw_dbg_conf != FW_DBG_INVALID)
  806. IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
  807. mvm->fw_dbg_conf);
  808. /* Send all HCMDs for configuring the FW debug */
  809. ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
  810. for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
  811. struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
  812. ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
  813. le16_to_cpu(cmd->len), cmd->data);
  814. if (ret)
  815. return ret;
  816. ptr += sizeof(*cmd);
  817. ptr += le16_to_cpu(cmd->len);
  818. }
  819. mvm->fw_dbg_conf = conf_id;
  820. return ret;
  821. }