fw-dbg.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  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. fifo_hdr->available_bytes =
  254. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  255. TXF_CPU2_FIFO_ITEM_CNT));
  256. fifo_hdr->wr_ptr =
  257. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  258. TXF_CPU2_WR_PTR));
  259. fifo_hdr->rd_ptr =
  260. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  261. TXF_CPU2_RD_PTR));
  262. fifo_hdr->fence_ptr =
  263. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  264. TXF_CPU2_FENCE_PTR));
  265. fifo_hdr->fence_mode =
  266. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  267. TXF_CPU2_LOCK_FENCE));
  268. /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */
  269. iwl_trans_write_prph(mvm->trans,
  270. TXF_CPU2_READ_MODIFY_ADDR,
  271. TXF_CPU2_WR_PTR);
  272. /* Dummy-read to advance the read pointer to head */
  273. iwl_trans_read_prph(mvm->trans,
  274. TXF_CPU2_READ_MODIFY_DATA);
  275. /* Read FIFO */
  276. fifo_len /= sizeof(u32); /* Size in DWORDS */
  277. for (j = 0; j < fifo_len; j++)
  278. fifo_data[j] =
  279. iwl_trans_read_prph(mvm->trans,
  280. TXF_CPU2_READ_MODIFY_DATA);
  281. *dump_data = iwl_fw_error_next_data(*dump_data);
  282. }
  283. }
  284. iwl_trans_release_nic_access(mvm->trans, &flags);
  285. }
  286. void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
  287. {
  288. if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
  289. return;
  290. kfree(mvm->fw_dump_desc);
  291. mvm->fw_dump_desc = NULL;
  292. }
  293. #define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
  294. #define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
  295. struct iwl_prph_range {
  296. u32 start, end;
  297. };
  298. static const struct iwl_prph_range iwl_prph_dump_addr_comm[] = {
  299. { .start = 0x00a00000, .end = 0x00a00000 },
  300. { .start = 0x00a0000c, .end = 0x00a00024 },
  301. { .start = 0x00a0002c, .end = 0x00a0003c },
  302. { .start = 0x00a00410, .end = 0x00a00418 },
  303. { .start = 0x00a00420, .end = 0x00a00420 },
  304. { .start = 0x00a00428, .end = 0x00a00428 },
  305. { .start = 0x00a00430, .end = 0x00a0043c },
  306. { .start = 0x00a00444, .end = 0x00a00444 },
  307. { .start = 0x00a004c0, .end = 0x00a004cc },
  308. { .start = 0x00a004d8, .end = 0x00a004d8 },
  309. { .start = 0x00a004e0, .end = 0x00a004f0 },
  310. { .start = 0x00a00840, .end = 0x00a00840 },
  311. { .start = 0x00a00850, .end = 0x00a00858 },
  312. { .start = 0x00a01004, .end = 0x00a01008 },
  313. { .start = 0x00a01010, .end = 0x00a01010 },
  314. { .start = 0x00a01018, .end = 0x00a01018 },
  315. { .start = 0x00a01024, .end = 0x00a01024 },
  316. { .start = 0x00a0102c, .end = 0x00a01034 },
  317. { .start = 0x00a0103c, .end = 0x00a01040 },
  318. { .start = 0x00a01048, .end = 0x00a01094 },
  319. { .start = 0x00a01c00, .end = 0x00a01c20 },
  320. { .start = 0x00a01c58, .end = 0x00a01c58 },
  321. { .start = 0x00a01c7c, .end = 0x00a01c7c },
  322. { .start = 0x00a01c28, .end = 0x00a01c54 },
  323. { .start = 0x00a01c5c, .end = 0x00a01c5c },
  324. { .start = 0x00a01c60, .end = 0x00a01cdc },
  325. { .start = 0x00a01ce0, .end = 0x00a01d0c },
  326. { .start = 0x00a01d18, .end = 0x00a01d20 },
  327. { .start = 0x00a01d2c, .end = 0x00a01d30 },
  328. { .start = 0x00a01d40, .end = 0x00a01d5c },
  329. { .start = 0x00a01d80, .end = 0x00a01d80 },
  330. { .start = 0x00a01d98, .end = 0x00a01d9c },
  331. { .start = 0x00a01da8, .end = 0x00a01da8 },
  332. { .start = 0x00a01db8, .end = 0x00a01df4 },
  333. { .start = 0x00a01dc0, .end = 0x00a01dfc },
  334. { .start = 0x00a01e00, .end = 0x00a01e2c },
  335. { .start = 0x00a01e40, .end = 0x00a01e60 },
  336. { .start = 0x00a01e68, .end = 0x00a01e6c },
  337. { .start = 0x00a01e74, .end = 0x00a01e74 },
  338. { .start = 0x00a01e84, .end = 0x00a01e90 },
  339. { .start = 0x00a01e9c, .end = 0x00a01ec4 },
  340. { .start = 0x00a01ed0, .end = 0x00a01ee0 },
  341. { .start = 0x00a01f00, .end = 0x00a01f1c },
  342. { .start = 0x00a01f44, .end = 0x00a01ffc },
  343. { .start = 0x00a02000, .end = 0x00a02048 },
  344. { .start = 0x00a02068, .end = 0x00a020f0 },
  345. { .start = 0x00a02100, .end = 0x00a02118 },
  346. { .start = 0x00a02140, .end = 0x00a0214c },
  347. { .start = 0x00a02168, .end = 0x00a0218c },
  348. { .start = 0x00a021c0, .end = 0x00a021c0 },
  349. { .start = 0x00a02400, .end = 0x00a02410 },
  350. { .start = 0x00a02418, .end = 0x00a02420 },
  351. { .start = 0x00a02428, .end = 0x00a0242c },
  352. { .start = 0x00a02434, .end = 0x00a02434 },
  353. { .start = 0x00a02440, .end = 0x00a02460 },
  354. { .start = 0x00a02468, .end = 0x00a024b0 },
  355. { .start = 0x00a024c8, .end = 0x00a024cc },
  356. { .start = 0x00a02500, .end = 0x00a02504 },
  357. { .start = 0x00a0250c, .end = 0x00a02510 },
  358. { .start = 0x00a02540, .end = 0x00a02554 },
  359. { .start = 0x00a02580, .end = 0x00a025f4 },
  360. { .start = 0x00a02600, .end = 0x00a0260c },
  361. { .start = 0x00a02648, .end = 0x00a02650 },
  362. { .start = 0x00a02680, .end = 0x00a02680 },
  363. { .start = 0x00a026c0, .end = 0x00a026d0 },
  364. { .start = 0x00a02700, .end = 0x00a0270c },
  365. { .start = 0x00a02804, .end = 0x00a02804 },
  366. { .start = 0x00a02818, .end = 0x00a0281c },
  367. { .start = 0x00a02c00, .end = 0x00a02db4 },
  368. { .start = 0x00a02df4, .end = 0x00a02fb0 },
  369. { .start = 0x00a03000, .end = 0x00a03014 },
  370. { .start = 0x00a0301c, .end = 0x00a0302c },
  371. { .start = 0x00a03034, .end = 0x00a03038 },
  372. { .start = 0x00a03040, .end = 0x00a03048 },
  373. { .start = 0x00a03060, .end = 0x00a03068 },
  374. { .start = 0x00a03070, .end = 0x00a03074 },
  375. { .start = 0x00a0307c, .end = 0x00a0307c },
  376. { .start = 0x00a03080, .end = 0x00a03084 },
  377. { .start = 0x00a0308c, .end = 0x00a03090 },
  378. { .start = 0x00a03098, .end = 0x00a03098 },
  379. { .start = 0x00a030a0, .end = 0x00a030a0 },
  380. { .start = 0x00a030a8, .end = 0x00a030b4 },
  381. { .start = 0x00a030bc, .end = 0x00a030bc },
  382. { .start = 0x00a030c0, .end = 0x00a0312c },
  383. { .start = 0x00a03c00, .end = 0x00a03c5c },
  384. { .start = 0x00a04400, .end = 0x00a04454 },
  385. { .start = 0x00a04460, .end = 0x00a04474 },
  386. { .start = 0x00a044c0, .end = 0x00a044ec },
  387. { .start = 0x00a04500, .end = 0x00a04504 },
  388. { .start = 0x00a04510, .end = 0x00a04538 },
  389. { .start = 0x00a04540, .end = 0x00a04548 },
  390. { .start = 0x00a04560, .end = 0x00a0457c },
  391. { .start = 0x00a04590, .end = 0x00a04598 },
  392. { .start = 0x00a045c0, .end = 0x00a045f4 },
  393. { .start = 0x00a44000, .end = 0x00a7bf80 },
  394. };
  395. static const struct iwl_prph_range iwl_prph_dump_addr_9000[] = {
  396. { .start = 0x00a05c00, .end = 0x00a05c18 },
  397. { .start = 0x00a05400, .end = 0x00a056e8 },
  398. { .start = 0x00a08000, .end = 0x00a098bc },
  399. { .start = 0x00adfc00, .end = 0x00adfd1c },
  400. { .start = 0x00a02400, .end = 0x00a02758 },
  401. };
  402. static u32 iwl_dump_prph(struct iwl_trans *trans,
  403. struct iwl_fw_error_dump_data **data,
  404. const struct iwl_prph_range *iwl_prph_dump_addr,
  405. u32 range_len)
  406. {
  407. struct iwl_fw_error_dump_prph *prph;
  408. unsigned long flags;
  409. u32 prph_len = 0, i;
  410. if (!iwl_trans_grab_nic_access(trans, &flags))
  411. return 0;
  412. for (i = 0; i < range_len; i++) {
  413. /* The range includes both boundaries */
  414. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  415. iwl_prph_dump_addr[i].start + 4;
  416. int reg;
  417. __le32 *val;
  418. prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
  419. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
  420. (*data)->len = cpu_to_le32(sizeof(*prph) +
  421. num_bytes_in_chunk);
  422. prph = (void *)(*data)->data;
  423. prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
  424. val = (void *)prph->data;
  425. for (reg = iwl_prph_dump_addr[i].start;
  426. reg <= iwl_prph_dump_addr[i].end;
  427. reg += 4)
  428. *val++ = cpu_to_le32(iwl_read_prph_no_grab(trans,
  429. reg));
  430. *data = iwl_fw_error_next_data(*data);
  431. }
  432. iwl_trans_release_nic_access(trans, &flags);
  433. return prph_len;
  434. }
  435. void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
  436. {
  437. struct iwl_fw_error_dump_file *dump_file;
  438. struct iwl_fw_error_dump_data *dump_data;
  439. struct iwl_fw_error_dump_info *dump_info;
  440. struct iwl_fw_error_dump_mem *dump_mem;
  441. struct iwl_fw_error_dump_trigger_desc *dump_trig;
  442. struct iwl_mvm_dump_ptrs *fw_error_dump;
  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 < ARRAY_SIZE(mem_cfg->txfifo_size); 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. dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
  711. GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
  712. out:
  713. iwl_mvm_free_fw_dump_desc(mvm);
  714. mvm->fw_dump_trig = NULL;
  715. clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
  716. }
  717. const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
  718. .trig_desc = {
  719. .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
  720. },
  721. };
  722. int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
  723. const struct iwl_mvm_dump_desc *desc,
  724. const struct iwl_fw_dbg_trigger_tlv *trigger)
  725. {
  726. unsigned int delay = 0;
  727. if (trigger)
  728. delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
  729. if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
  730. return -EBUSY;
  731. if (WARN_ON(mvm->fw_dump_desc))
  732. iwl_mvm_free_fw_dump_desc(mvm);
  733. IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
  734. le32_to_cpu(desc->trig_desc.type));
  735. mvm->fw_dump_desc = desc;
  736. mvm->fw_dump_trig = trigger;
  737. queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
  738. return 0;
  739. }
  740. int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
  741. const char *str, size_t len,
  742. const struct iwl_fw_dbg_trigger_tlv *trigger)
  743. {
  744. struct iwl_mvm_dump_desc *desc;
  745. desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
  746. if (!desc)
  747. return -ENOMEM;
  748. desc->len = len;
  749. desc->trig_desc.type = cpu_to_le32(trig);
  750. memcpy(desc->trig_desc.data, str, len);
  751. return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
  752. }
  753. int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
  754. struct iwl_fw_dbg_trigger_tlv *trigger,
  755. const char *fmt, ...)
  756. {
  757. u16 occurrences = le16_to_cpu(trigger->occurrences);
  758. int ret, len = 0;
  759. char buf[64];
  760. if (!occurrences)
  761. return 0;
  762. if (fmt) {
  763. va_list ap;
  764. buf[sizeof(buf) - 1] = '\0';
  765. va_start(ap, fmt);
  766. vsnprintf(buf, sizeof(buf), fmt, ap);
  767. va_end(ap);
  768. /* check for truncation */
  769. if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
  770. buf[sizeof(buf) - 1] = '\0';
  771. len = strlen(buf) + 1;
  772. }
  773. ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
  774. trigger);
  775. if (ret)
  776. return ret;
  777. trigger->occurrences = cpu_to_le16(occurrences - 1);
  778. return 0;
  779. }
  780. static inline void iwl_mvm_restart_early_start(struct iwl_mvm *mvm)
  781. {
  782. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  783. iwl_clear_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  784. else
  785. iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 1);
  786. }
  787. int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
  788. {
  789. u8 *ptr;
  790. int ret;
  791. int i;
  792. if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
  793. "Invalid configuration %d\n", conf_id))
  794. return -EINVAL;
  795. /* EARLY START - firmware's configuration is hard coded */
  796. if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
  797. !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
  798. conf_id == FW_DBG_START_FROM_ALIVE) {
  799. iwl_mvm_restart_early_start(mvm);
  800. return 0;
  801. }
  802. if (!mvm->fw->dbg_conf_tlv[conf_id])
  803. return -EINVAL;
  804. if (mvm->fw_dbg_conf != FW_DBG_INVALID)
  805. IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
  806. mvm->fw_dbg_conf);
  807. /* Send all HCMDs for configuring the FW debug */
  808. ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
  809. for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
  810. struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
  811. ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
  812. le16_to_cpu(cmd->len), cmd->data);
  813. if (ret)
  814. return ret;
  815. ptr += sizeof(*cmd);
  816. ptr += le16_to_cpu(cmd->len);
  817. }
  818. mvm->fw_dbg_conf = conf_id;
  819. return ret;
  820. }