blob: d5cb47e2fe449ee6bb078dfc368184d832c8a1a7 [file] [log] [blame]
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +02001/******************************************************************************
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
Sara Sharonfa1f2b62017-01-26 12:40:25 +020010 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020011 *
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:
Emmanuel Grumbachd01c5362015-11-17 15:39:56 +020028 * Intel Linux Wireless <linuxwifi@intel.com>
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020029 * 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
Sara Sharonfa1f2b62017-01-26 12:40:25 +020035 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020036 * 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
67#include "fw-dbg.h"
68#include "iwl-io.h"
69#include "mvm.h"
70#include "iwl-prph.h"
71#include "iwl-csr.h"
72
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +020073#define RADIO_REG_MAX_READ 0x2ad
74static void iwl_mvm_read_radio_reg(struct iwl_mvm *mvm,
75 struct iwl_fw_error_dump_data **dump_data)
76{
77 u8 *pos = (void *)(*dump_data)->data;
78 unsigned long flags;
79 int i;
80
81 if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
82 return;
83
84 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RADIO_REG);
85 (*dump_data)->len = cpu_to_le32(RADIO_REG_MAX_READ);
86
87 for (i = 0; i < RADIO_REG_MAX_READ; i++) {
88 u32 rd_cmd = RADIO_RSP_RD_CMD;
89
90 rd_cmd |= i << RADIO_RSP_ADDR_POS;
91 iwl_write_prph_no_grab(mvm->trans, RSP_RADIO_CMD, rd_cmd);
92 *pos = (u8)iwl_read_prph_no_grab(mvm->trans, RSP_RADIO_RDDAT);
93
94 pos++;
95 }
96
97 *dump_data = iwl_fw_error_next_data(*dump_data);
98
99 iwl_trans_release_nic_access(mvm->trans, &flags);
100}
101
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200102static void iwl_mvm_dump_rxf(struct iwl_mvm *mvm,
103 struct iwl_fw_error_dump_data **dump_data,
104 int size, u32 offset, int fifo_num)
105{
106 struct iwl_fw_error_dump_fifo *fifo_hdr;
107 u32 *fifo_data;
108 u32 fifo_len;
109 int i;
110
111 fifo_hdr = (void *)(*dump_data)->data;
112 fifo_data = (void *)fifo_hdr->data;
113 fifo_len = size;
114
115 /* No need to try to read the data if the length is 0 */
116 if (fifo_len == 0)
117 return;
118
119 /* Add a TLV for the RXF */
120 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
121 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
122
123 fifo_hdr->fifo_num = cpu_to_le32(fifo_num);
124 fifo_hdr->available_bytes =
125 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
126 RXF_RD_D_SPACE + offset));
127 fifo_hdr->wr_ptr =
128 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
129 RXF_RD_WR_PTR + offset));
130 fifo_hdr->rd_ptr =
131 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
132 RXF_RD_RD_PTR + offset));
133 fifo_hdr->fence_ptr =
134 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
135 RXF_RD_FENCE_PTR + offset));
136 fifo_hdr->fence_mode =
137 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
138 RXF_SET_FENCE_MODE + offset));
139
140 /* Lock fence */
141 iwl_trans_write_prph(mvm->trans, RXF_SET_FENCE_MODE + offset, 0x1);
142 /* Set fence pointer to the same place like WR pointer */
143 iwl_trans_write_prph(mvm->trans, RXF_LD_WR2FENCE + offset, 0x1);
144 /* Set fence offset */
145 iwl_trans_write_prph(mvm->trans,
146 RXF_LD_FENCE_OFFSET_ADDR + offset, 0x0);
147
148 /* Read FIFO */
149 fifo_len /= sizeof(u32); /* Size in DWORDS */
150 for (i = 0; i < fifo_len; i++)
151 fifo_data[i] = iwl_trans_read_prph(mvm->trans,
152 RXF_FIFO_RD_FENCE_INC +
153 offset);
154 *dump_data = iwl_fw_error_next_data(*dump_data);
155}
156
157static void iwl_mvm_dump_txf(struct iwl_mvm *mvm,
158 struct iwl_fw_error_dump_data **dump_data,
159 int size, u32 offset, int fifo_num)
160{
161 struct iwl_fw_error_dump_fifo *fifo_hdr;
162 u32 *fifo_data;
163 u32 fifo_len;
164 int i;
165
166 fifo_hdr = (void *)(*dump_data)->data;
167 fifo_data = (void *)fifo_hdr->data;
168 fifo_len = size;
169
170 /* No need to try to read the data if the length is 0 */
171 if (fifo_len == 0)
172 return;
173
174 /* Add a TLV for the FIFO */
175 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
176 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
177
178 fifo_hdr->fifo_num = cpu_to_le32(fifo_num);
179 fifo_hdr->available_bytes =
180 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
181 TXF_FIFO_ITEM_CNT + offset));
182 fifo_hdr->wr_ptr =
183 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
184 TXF_WR_PTR + offset));
185 fifo_hdr->rd_ptr =
186 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
187 TXF_RD_PTR + offset));
188 fifo_hdr->fence_ptr =
189 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
190 TXF_FENCE_PTR + offset));
191 fifo_hdr->fence_mode =
192 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
193 TXF_LOCK_FENCE + offset));
194
195 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
196 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR + offset,
197 TXF_WR_PTR + offset);
198
199 /* Dummy-read to advance the read pointer to the head */
200 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA + offset);
201
202 /* Read FIFO */
203 fifo_len /= sizeof(u32); /* Size in DWORDS */
204 for (i = 0; i < fifo_len; i++)
205 fifo_data[i] = iwl_trans_read_prph(mvm->trans,
206 TXF_READ_MODIFY_DATA +
207 offset);
208 *dump_data = iwl_fw_error_next_data(*dump_data);
209}
210
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200211static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
212 struct iwl_fw_error_dump_data **dump_data)
213{
214 struct iwl_fw_error_dump_fifo *fifo_hdr;
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200215 struct iwl_mvm_shared_mem_cfg *cfg = &mvm->smem_cfg;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200216 u32 *fifo_data;
217 u32 fifo_len;
218 unsigned long flags;
219 int i, j;
220
Emmanuel Grumbach23ba9342015-12-17 11:55:13 +0200221 if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200222 return;
223
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200224 /* Pull RXF1 */
225 iwl_mvm_dump_rxf(mvm, dump_data, cfg->lmac[0].rxfifo1_size, 0, 0);
226 /* Pull RXF2 */
227 iwl_mvm_dump_rxf(mvm, dump_data, cfg->rxfifo2_size,
228 RXF_DIFF_FROM_PREV, 1);
229 /* Pull LMAC2 RXF1 */
230 if (mvm->smem_cfg.num_lmacs > 1)
231 iwl_mvm_dump_rxf(mvm, dump_data, cfg->lmac[1].rxfifo1_size,
232 LMAC2_PRPH_OFFSET, 2);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200233
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200234 /* Pull TXF data from LMAC1 */
235 for (i = 0; i < mvm->smem_cfg.num_txfifo_entries; i++) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200236 /* Mark the number of TXF we're pulling now */
237 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200238 iwl_mvm_dump_txf(mvm, dump_data, cfg->lmac[0].txfifo_size[i],
239 0, i);
240 }
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200241
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200242 /* Pull TXF data from LMAC2 */
243 if (mvm->smem_cfg.num_lmacs > 1) {
244 for (i = 0; i < mvm->smem_cfg.num_txfifo_entries; i++) {
245 /* Mark the number of TXF we're pulling now */
246 iwl_trans_write_prph(mvm->trans,
247 TXF_LARC_NUM + LMAC2_PRPH_OFFSET,
248 i);
249 iwl_mvm_dump_txf(mvm, dump_data,
250 cfg->lmac[1].txfifo_size[i],
251 LMAC2_PRPH_OFFSET,
252 i + cfg->num_txfifo_entries);
253 }
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200254 }
255
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200256 if (fw_has_capa(&mvm->fw->ucode_capa,
257 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
258 /* Pull UMAC internal TXF data from all TXFs */
259 for (i = 0;
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200260 i < ARRAY_SIZE(mvm->smem_cfg.internal_txfifo_size);
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200261 i++) {
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200262 fifo_hdr = (void *)(*dump_data)->data;
263 fifo_data = (void *)fifo_hdr->data;
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200264 fifo_len = mvm->smem_cfg.internal_txfifo_size[i];
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200265
266 /* No need to try to read the data if the length is 0 */
267 if (fifo_len == 0)
268 continue;
269
270 /* Add a TLV for the internal FIFOs */
271 (*dump_data)->type =
272 cpu_to_le32(IWL_FW_ERROR_DUMP_INTERNAL_TXF);
273 (*dump_data)->len =
274 cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
275
276 fifo_hdr->fifo_num = cpu_to_le32(i);
Emmanuel Grumbach39654cb32016-04-12 13:07:52 +0300277
278 /* Mark the number of TXF we're pulling now */
Golan Ben-Amie7c9bd12016-06-15 09:16:24 +0300279 iwl_trans_write_prph(mvm->trans, TXF_CPU2_NUM, i +
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200280 mvm->smem_cfg.num_txfifo_entries);
Emmanuel Grumbach39654cb32016-04-12 13:07:52 +0300281
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200282 fifo_hdr->available_bytes =
283 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
284 TXF_CPU2_FIFO_ITEM_CNT));
285 fifo_hdr->wr_ptr =
286 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
287 TXF_CPU2_WR_PTR));
288 fifo_hdr->rd_ptr =
289 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
290 TXF_CPU2_RD_PTR));
291 fifo_hdr->fence_ptr =
292 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
293 TXF_CPU2_FENCE_PTR));
294 fifo_hdr->fence_mode =
295 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
296 TXF_CPU2_LOCK_FENCE));
297
298 /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */
299 iwl_trans_write_prph(mvm->trans,
300 TXF_CPU2_READ_MODIFY_ADDR,
301 TXF_CPU2_WR_PTR);
302
303 /* Dummy-read to advance the read pointer to head */
304 iwl_trans_read_prph(mvm->trans,
305 TXF_CPU2_READ_MODIFY_DATA);
306
307 /* Read FIFO */
308 fifo_len /= sizeof(u32); /* Size in DWORDS */
309 for (j = 0; j < fifo_len; j++)
310 fifo_data[j] =
311 iwl_trans_read_prph(mvm->trans,
312 TXF_CPU2_READ_MODIFY_DATA);
313 *dump_data = iwl_fw_error_next_data(*dump_data);
314 }
315 }
316
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200317 iwl_trans_release_nic_access(mvm->trans, &flags);
318}
319
320void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
321{
Emmanuel Grumbach9fb78072016-01-05 09:35:21 +0200322 if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200323 return;
324
325 kfree(mvm->fw_dump_desc);
326 mvm->fw_dump_desc = NULL;
327}
328
329#define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
330#define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
331
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300332struct iwl_prph_range {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200333 u32 start, end;
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300334};
335
336static const struct iwl_prph_range iwl_prph_dump_addr_comm[] = {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200337 { .start = 0x00a00000, .end = 0x00a00000 },
338 { .start = 0x00a0000c, .end = 0x00a00024 },
339 { .start = 0x00a0002c, .end = 0x00a0003c },
340 { .start = 0x00a00410, .end = 0x00a00418 },
341 { .start = 0x00a00420, .end = 0x00a00420 },
342 { .start = 0x00a00428, .end = 0x00a00428 },
343 { .start = 0x00a00430, .end = 0x00a0043c },
344 { .start = 0x00a00444, .end = 0x00a00444 },
345 { .start = 0x00a004c0, .end = 0x00a004cc },
346 { .start = 0x00a004d8, .end = 0x00a004d8 },
347 { .start = 0x00a004e0, .end = 0x00a004f0 },
348 { .start = 0x00a00840, .end = 0x00a00840 },
349 { .start = 0x00a00850, .end = 0x00a00858 },
350 { .start = 0x00a01004, .end = 0x00a01008 },
351 { .start = 0x00a01010, .end = 0x00a01010 },
352 { .start = 0x00a01018, .end = 0x00a01018 },
353 { .start = 0x00a01024, .end = 0x00a01024 },
354 { .start = 0x00a0102c, .end = 0x00a01034 },
355 { .start = 0x00a0103c, .end = 0x00a01040 },
356 { .start = 0x00a01048, .end = 0x00a01094 },
357 { .start = 0x00a01c00, .end = 0x00a01c20 },
358 { .start = 0x00a01c58, .end = 0x00a01c58 },
359 { .start = 0x00a01c7c, .end = 0x00a01c7c },
360 { .start = 0x00a01c28, .end = 0x00a01c54 },
361 { .start = 0x00a01c5c, .end = 0x00a01c5c },
362 { .start = 0x00a01c60, .end = 0x00a01cdc },
363 { .start = 0x00a01ce0, .end = 0x00a01d0c },
364 { .start = 0x00a01d18, .end = 0x00a01d20 },
365 { .start = 0x00a01d2c, .end = 0x00a01d30 },
366 { .start = 0x00a01d40, .end = 0x00a01d5c },
367 { .start = 0x00a01d80, .end = 0x00a01d80 },
368 { .start = 0x00a01d98, .end = 0x00a01d9c },
369 { .start = 0x00a01da8, .end = 0x00a01da8 },
370 { .start = 0x00a01db8, .end = 0x00a01df4 },
371 { .start = 0x00a01dc0, .end = 0x00a01dfc },
372 { .start = 0x00a01e00, .end = 0x00a01e2c },
373 { .start = 0x00a01e40, .end = 0x00a01e60 },
374 { .start = 0x00a01e68, .end = 0x00a01e6c },
375 { .start = 0x00a01e74, .end = 0x00a01e74 },
376 { .start = 0x00a01e84, .end = 0x00a01e90 },
377 { .start = 0x00a01e9c, .end = 0x00a01ec4 },
378 { .start = 0x00a01ed0, .end = 0x00a01ee0 },
379 { .start = 0x00a01f00, .end = 0x00a01f1c },
380 { .start = 0x00a01f44, .end = 0x00a01ffc },
381 { .start = 0x00a02000, .end = 0x00a02048 },
382 { .start = 0x00a02068, .end = 0x00a020f0 },
383 { .start = 0x00a02100, .end = 0x00a02118 },
384 { .start = 0x00a02140, .end = 0x00a0214c },
385 { .start = 0x00a02168, .end = 0x00a0218c },
386 { .start = 0x00a021c0, .end = 0x00a021c0 },
387 { .start = 0x00a02400, .end = 0x00a02410 },
388 { .start = 0x00a02418, .end = 0x00a02420 },
389 { .start = 0x00a02428, .end = 0x00a0242c },
390 { .start = 0x00a02434, .end = 0x00a02434 },
391 { .start = 0x00a02440, .end = 0x00a02460 },
392 { .start = 0x00a02468, .end = 0x00a024b0 },
393 { .start = 0x00a024c8, .end = 0x00a024cc },
394 { .start = 0x00a02500, .end = 0x00a02504 },
395 { .start = 0x00a0250c, .end = 0x00a02510 },
396 { .start = 0x00a02540, .end = 0x00a02554 },
397 { .start = 0x00a02580, .end = 0x00a025f4 },
398 { .start = 0x00a02600, .end = 0x00a0260c },
399 { .start = 0x00a02648, .end = 0x00a02650 },
400 { .start = 0x00a02680, .end = 0x00a02680 },
401 { .start = 0x00a026c0, .end = 0x00a026d0 },
402 { .start = 0x00a02700, .end = 0x00a0270c },
403 { .start = 0x00a02804, .end = 0x00a02804 },
404 { .start = 0x00a02818, .end = 0x00a0281c },
405 { .start = 0x00a02c00, .end = 0x00a02db4 },
406 { .start = 0x00a02df4, .end = 0x00a02fb0 },
407 { .start = 0x00a03000, .end = 0x00a03014 },
408 { .start = 0x00a0301c, .end = 0x00a0302c },
409 { .start = 0x00a03034, .end = 0x00a03038 },
410 { .start = 0x00a03040, .end = 0x00a03048 },
411 { .start = 0x00a03060, .end = 0x00a03068 },
412 { .start = 0x00a03070, .end = 0x00a03074 },
413 { .start = 0x00a0307c, .end = 0x00a0307c },
414 { .start = 0x00a03080, .end = 0x00a03084 },
415 { .start = 0x00a0308c, .end = 0x00a03090 },
416 { .start = 0x00a03098, .end = 0x00a03098 },
417 { .start = 0x00a030a0, .end = 0x00a030a0 },
418 { .start = 0x00a030a8, .end = 0x00a030b4 },
419 { .start = 0x00a030bc, .end = 0x00a030bc },
420 { .start = 0x00a030c0, .end = 0x00a0312c },
421 { .start = 0x00a03c00, .end = 0x00a03c5c },
422 { .start = 0x00a04400, .end = 0x00a04454 },
423 { .start = 0x00a04460, .end = 0x00a04474 },
424 { .start = 0x00a044c0, .end = 0x00a044ec },
425 { .start = 0x00a04500, .end = 0x00a04504 },
426 { .start = 0x00a04510, .end = 0x00a04538 },
427 { .start = 0x00a04540, .end = 0x00a04548 },
428 { .start = 0x00a04560, .end = 0x00a0457c },
429 { .start = 0x00a04590, .end = 0x00a04598 },
430 { .start = 0x00a045c0, .end = 0x00a045f4 },
431};
432
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300433static const struct iwl_prph_range iwl_prph_dump_addr_9000[] = {
434 { .start = 0x00a05c00, .end = 0x00a05c18 },
435 { .start = 0x00a05400, .end = 0x00a056e8 },
436 { .start = 0x00a08000, .end = 0x00a098bc },
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300437 { .start = 0x00a02400, .end = 0x00a02758 },
438};
439
Johannes Berg5bdaa0e2016-10-20 10:01:43 +0200440static void _iwl_read_prph_block(struct iwl_trans *trans, u32 start,
441 u32 len_bytes, __le32 *data)
442{
443 u32 i;
444
445 for (i = 0; i < len_bytes; i += 4)
446 *data++ = cpu_to_le32(iwl_read_prph_no_grab(trans, start + i));
447}
448
449static bool iwl_read_prph_block(struct iwl_trans *trans, u32 start,
450 u32 len_bytes, __le32 *data)
451{
452 unsigned long flags;
453 bool success = false;
454
455 if (iwl_trans_grab_nic_access(trans, &flags)) {
456 success = true;
457 _iwl_read_prph_block(trans, start, len_bytes, data);
458 iwl_trans_release_nic_access(trans, &flags);
459 }
460
461 return success;
462}
463
Johannes Berg1110f8e2016-10-20 09:44:05 +0200464static void iwl_dump_prph(struct iwl_trans *trans,
465 struct iwl_fw_error_dump_data **data,
466 const struct iwl_prph_range *iwl_prph_dump_addr,
467 u32 range_len)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200468{
469 struct iwl_fw_error_dump_prph *prph;
470 unsigned long flags;
Johannes Berg1110f8e2016-10-20 09:44:05 +0200471 u32 i;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200472
Emmanuel Grumbach23ba9342015-12-17 11:55:13 +0200473 if (!iwl_trans_grab_nic_access(trans, &flags))
Johannes Berg1110f8e2016-10-20 09:44:05 +0200474 return;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200475
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300476 for (i = 0; i < range_len; i++) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200477 /* The range includes both boundaries */
478 int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
479 iwl_prph_dump_addr[i].start + 4;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200480
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200481 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
482 (*data)->len = cpu_to_le32(sizeof(*prph) +
483 num_bytes_in_chunk);
484 prph = (void *)(*data)->data;
485 prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200486
Johannes Berg5bdaa0e2016-10-20 10:01:43 +0200487 _iwl_read_prph_block(trans, iwl_prph_dump_addr[i].start,
488 /* our range is inclusive, hence + 4 */
489 iwl_prph_dump_addr[i].end -
490 iwl_prph_dump_addr[i].start + 4,
491 (void *)prph->data);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200492
Dan Carpenter95a451c2015-12-09 13:26:08 +0300493 *data = iwl_fw_error_next_data(*data);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200494 }
495
496 iwl_trans_release_nic_access(trans, &flags);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200497}
498
Aviya Erenfeld7e62a692016-09-20 18:07:44 +0300499/*
500 * alloc_sgtable - allocates scallerlist table in the given size,
501 * fills it with pages and returns it
502 * @size: the size (in bytes) of the table
503*/
504static struct scatterlist *alloc_sgtable(int size)
505{
506 int alloc_size, nents, i;
507 struct page *new_page;
508 struct scatterlist *iter;
509 struct scatterlist *table;
510
511 nents = DIV_ROUND_UP(size, PAGE_SIZE);
512 table = kcalloc(nents, sizeof(*table), GFP_KERNEL);
513 if (!table)
514 return NULL;
515 sg_init_table(table, nents);
516 iter = table;
517 for_each_sg(table, iter, sg_nents(table), i) {
518 new_page = alloc_page(GFP_KERNEL);
519 if (!new_page) {
520 /* release all previous allocated pages in the table */
521 iter = table;
522 for_each_sg(table, iter, sg_nents(table), i) {
523 new_page = sg_page(iter);
524 if (new_page)
525 __free_page(new_page);
526 }
527 return NULL;
528 }
529 alloc_size = min_t(int, size, PAGE_SIZE);
530 size -= PAGE_SIZE;
531 sg_set_page(iter, new_page, alloc_size, 0);
532 }
533 return table;
534}
535
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200536void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
537{
538 struct iwl_fw_error_dump_file *dump_file;
539 struct iwl_fw_error_dump_data *dump_data;
540 struct iwl_fw_error_dump_info *dump_info;
541 struct iwl_fw_error_dump_mem *dump_mem;
542 struct iwl_fw_error_dump_trigger_desc *dump_trig;
543 struct iwl_mvm_dump_ptrs *fw_error_dump;
Aviya Erenfeld7e62a692016-09-20 18:07:44 +0300544 struct scatterlist *sg_dump_data;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200545 u32 sram_len, sram_ofs;
Johannes Berg2ed1e012016-10-20 09:41:14 +0200546 const struct iwl_fw_dbg_mem_seg_tlv *fw_dbg_mem = mvm->fw->dbg_mem_tlv;
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +0200547 u32 file_len, fifo_data_len = 0, prph_len = 0, radio_len = 0;
Johannes Berg2ed1e012016-10-20 09:41:14 +0200548 u32 smem_len = mvm->fw->n_dbg_mem_tlv ? 0 : mvm->cfg->smem_len;
549 u32 sram2_len = mvm->fw->n_dbg_mem_tlv ? 0 : mvm->cfg->dccm2_len;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200550 bool monitor_dump_only = false;
551 int i;
552
Golan Ben-Ami33efe942015-12-23 17:53:27 +0200553 if (!IWL_MVM_COLLECT_FW_ERR_DUMP &&
554 !mvm->trans->dbg_dest_tlv)
555 return;
556
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200557 lockdep_assert_held(&mvm->mutex);
558
559 /* there's no point in fw dump if the bus is dead */
560 if (test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
561 IWL_ERR(mvm, "Skip fw error dump since bus is dead\n");
Emmanuel Grumbach9fb78072016-01-05 09:35:21 +0200562 goto out;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200563 }
564
565 if (mvm->fw_dump_trig &&
566 mvm->fw_dump_trig->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)
567 monitor_dump_only = true;
568
569 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
570 if (!fw_error_dump)
Emmanuel Grumbach9fb78072016-01-05 09:35:21 +0200571 goto out;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200572
573 /* SRAM - include stack CCM if driver knows the values for it */
574 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
575 const struct fw_img *img;
576
577 img = &mvm->fw->img[mvm->cur_ucode];
578 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
579 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
580 } else {
581 sram_ofs = mvm->cfg->dccm_offset;
582 sram_len = mvm->cfg->dccm_len;
583 }
584
585 /* reading RXF/TXF sizes */
586 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200587 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->smem_cfg;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200588
589 fifo_data_len = 0;
590
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200591 /* Count RXF2 size */
592 if (mem_cfg->rxfifo2_size) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200593 /* Add header info */
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200594 fifo_data_len += mem_cfg->rxfifo2_size +
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200595 sizeof(*dump_data) +
596 sizeof(struct iwl_fw_error_dump_fifo);
597 }
598
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200599 /* Count RXF1 sizes */
600 for (i = 0; i < mem_cfg->num_lmacs; i++) {
601 if (!mem_cfg->lmac[i].rxfifo1_size)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200602 continue;
603
604 /* Add header info */
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200605 fifo_data_len += mem_cfg->lmac[i].rxfifo1_size +
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200606 sizeof(*dump_data) +
607 sizeof(struct iwl_fw_error_dump_fifo);
608 }
Emmanuel Grumbache8f0c4d2015-12-16 13:42:17 +0200609
Sara Sharonfa1f2b62017-01-26 12:40:25 +0200610 /* Count TXF sizes */
611 for (i = 0; i < mem_cfg->num_lmacs; i++) {
612 int j;
613
614 for (j = 0; j < mem_cfg->num_txfifo_entries; j++) {
615 if (!mem_cfg->lmac[i].txfifo_size[j])
616 continue;
617
618 /* Add header info */
619 fifo_data_len +=
620 mem_cfg->lmac[i].txfifo_size[j] +
621 sizeof(*dump_data) +
622 sizeof(struct iwl_fw_error_dump_fifo);
623 }
624 }
625
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200626 if (fw_has_capa(&mvm->fw->ucode_capa,
627 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
628 for (i = 0;
629 i < ARRAY_SIZE(mem_cfg->internal_txfifo_size);
630 i++) {
631 if (!mem_cfg->internal_txfifo_size[i])
632 continue;
633
634 /* Add header info */
635 fifo_data_len +=
636 mem_cfg->internal_txfifo_size[i] +
637 sizeof(*dump_data) +
638 sizeof(struct iwl_fw_error_dump_fifo);
639 }
640 }
641
Emmanuel Grumbache8f0c4d2015-12-16 13:42:17 +0200642 /* Make room for PRPH registers */
Liad Kaufman9eca7022017-03-26 14:09:46 +0300643 if (!mvm->trans->cfg->gen2) {
644 for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr_comm);
645 i++) {
646 /* The range includes both boundaries */
647 int num_bytes_in_chunk =
648 iwl_prph_dump_addr_comm[i].end -
649 iwl_prph_dump_addr_comm[i].start + 4;
Emmanuel Grumbache8f0c4d2015-12-16 13:42:17 +0200650
Liad Kaufman9eca7022017-03-26 14:09:46 +0300651 prph_len += sizeof(*dump_data) +
652 sizeof(struct iwl_fw_error_dump_prph) +
653 num_bytes_in_chunk;
654 }
Emmanuel Grumbache8f0c4d2015-12-16 13:42:17 +0200655 }
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +0200656
Liad Kaufman9eca7022017-03-26 14:09:46 +0300657 if (!mvm->trans->cfg->gen2 && mvm->cfg->mq_rx_supported) {
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300658 for (i = 0; i <
659 ARRAY_SIZE(iwl_prph_dump_addr_9000); i++) {
660 /* The range includes both boundaries */
661 int num_bytes_in_chunk =
662 iwl_prph_dump_addr_9000[i].end -
663 iwl_prph_dump_addr_9000[i].start + 4;
664
665 prph_len += sizeof(*dump_data) +
666 sizeof(struct iwl_fw_error_dump_prph) +
667 num_bytes_in_chunk;
668 }
669 }
670
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +0200671 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
672 radio_len = sizeof(*dump_data) + RADIO_REG_MAX_READ;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200673 }
674
675 file_len = sizeof(*dump_file) +
676 sizeof(*dump_data) * 2 +
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200677 fifo_data_len +
Emmanuel Grumbache8f0c4d2015-12-16 13:42:17 +0200678 prph_len +
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +0200679 radio_len +
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200680 sizeof(*dump_info);
681
682 /* Make room for the SMEM, if it exists */
683 if (smem_len)
684 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
685
686 /* Make room for the secondary SRAM, if it exists */
687 if (sram2_len)
688 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
689
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200690 /* Make room for MEM segments */
Johannes Berg2ed1e012016-10-20 09:41:14 +0200691 for (i = 0; i < mvm->fw->n_dbg_mem_tlv; i++) {
692 file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
693 le32_to_cpu(fw_dbg_mem[i].len);
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200694 }
695
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200696 /* Make room for fw's virtual image pages, if it exists */
Liad Kaufman2ba57c82017-03-12 11:00:04 +0200697 if (!mvm->trans->cfg->gen2 &&
698 mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
Matti Gottliebf742aaf2016-04-10 10:53:57 +0300699 mvm->fw_paging_db[0].fw_paging_block)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200700 file_len += mvm->num_of_paging_blk *
701 (sizeof(*dump_data) +
702 sizeof(struct iwl_fw_error_dump_paging) +
703 PAGING_BLOCK_SIZE);
704
705 /* If we only want a monitor dump, reset the file length */
706 if (monitor_dump_only) {
707 file_len = sizeof(*dump_file) + sizeof(*dump_data) +
708 sizeof(*dump_info);
709 }
710
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200711 if (mvm->fw_dump_desc)
712 file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
713 mvm->fw_dump_desc->len;
714
Johannes Berg2ed1e012016-10-20 09:41:14 +0200715 if (!mvm->fw->n_dbg_mem_tlv)
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200716 file_len += sram_len + sizeof(*dump_mem);
717
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200718 dump_file = vzalloc(file_len);
719 if (!dump_file) {
720 kfree(fw_error_dump);
Emmanuel Grumbach9fb78072016-01-05 09:35:21 +0200721 goto out;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200722 }
723
724 fw_error_dump->op_mode_ptr = dump_file;
725
726 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
727 dump_data = (void *)dump_file->data;
728
729 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
730 dump_data->len = cpu_to_le32(sizeof(*dump_info));
731 dump_info = (void *)dump_data->data;
732 dump_info->device_family =
733 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
734 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
735 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
736 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
737 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
738 sizeof(dump_info->fw_human_readable));
739 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
740 sizeof(dump_info->dev_human_readable));
741 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
742 sizeof(dump_info->bus_human_readable));
743
744 dump_data = iwl_fw_error_next_data(dump_data);
745 /* We only dump the FIFOs if the FW is in error state */
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +0200746 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200747 iwl_mvm_dump_fifos(mvm, &dump_data);
Emmanuel Grumbach976f15a2015-12-28 15:22:28 +0200748 if (radio_len)
749 iwl_mvm_read_radio_reg(mvm, &dump_data);
750 }
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200751
752 if (mvm->fw_dump_desc) {
753 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
754 dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
755 mvm->fw_dump_desc->len);
756 dump_trig = (void *)dump_data->data;
757 memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
758 sizeof(*dump_trig) + mvm->fw_dump_desc->len);
759
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200760 dump_data = iwl_fw_error_next_data(dump_data);
761 }
762
763 /* In case we only want monitor dump, skip to dump trasport data */
764 if (monitor_dump_only)
765 goto dump_trans_data;
766
Johannes Berg2ed1e012016-10-20 09:41:14 +0200767 if (!mvm->fw->n_dbg_mem_tlv) {
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200768 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
769 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
770 dump_mem = (void *)dump_data->data;
771 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
772 dump_mem->offset = cpu_to_le32(sram_ofs);
773 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
774 sram_len);
775 dump_data = iwl_fw_error_next_data(dump_data);
776 }
777
Johannes Berg2ed1e012016-10-20 09:41:14 +0200778 for (i = 0; i < mvm->fw->n_dbg_mem_tlv; i++) {
779 u32 len = le32_to_cpu(fw_dbg_mem[i].len);
780 u32 ofs = le32_to_cpu(fw_dbg_mem[i].ofs);
Johannes Berg5bdaa0e2016-10-20 10:01:43 +0200781 bool success;
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200782
Johannes Berg2ed1e012016-10-20 09:41:14 +0200783 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
784 dump_data->len = cpu_to_le32(len + sizeof(*dump_mem));
785 dump_mem = (void *)dump_data->data;
786 dump_mem->type = fw_dbg_mem[i].data_type;
787 dump_mem->offset = cpu_to_le32(ofs);
Johannes Berg5bdaa0e2016-10-20 10:01:43 +0200788
789 switch (dump_mem->type & cpu_to_le32(FW_DBG_MEM_TYPE_MASK)) {
790 case cpu_to_le32(FW_DBG_MEM_TYPE_REGULAR):
791 iwl_trans_read_mem_bytes(mvm->trans, ofs,
792 dump_mem->data,
793 len);
794 success = true;
795 break;
796 case cpu_to_le32(FW_DBG_MEM_TYPE_PRPH):
797 success = iwl_read_prph_block(mvm->trans, ofs, len,
798 (void *)dump_mem->data);
799 break;
800 default:
801 /*
802 * shouldn't get here, we ignored this kind
803 * of TLV earlier during the TLV parsing?!
804 */
805 WARN_ON(1);
806 success = false;
807 }
808
809 if (success)
810 dump_data = iwl_fw_error_next_data(dump_data);
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200811 }
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200812
813 if (smem_len) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200814 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
815 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
816 dump_mem = (void *)dump_data->data;
817 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
818 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
819 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
820 dump_mem->data, smem_len);
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200821 dump_data = iwl_fw_error_next_data(dump_data);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200822 }
823
824 if (sram2_len) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200825 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
826 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
827 dump_mem = (void *)dump_data->data;
828 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
829 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
830 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
831 dump_mem->data, sram2_len);
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200832 dump_data = iwl_fw_error_next_data(dump_data);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200833 }
834
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200835 /* Dump fw's virtual image */
Liad Kaufman2ba57c82017-03-12 11:00:04 +0200836 if (!mvm->trans->cfg->gen2 &&
837 mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
Matti Gottliebf742aaf2016-04-10 10:53:57 +0300838 mvm->fw_paging_db[0].fw_paging_block) {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200839 for (i = 1; i < mvm->num_of_paging_blk + 1; i++) {
840 struct iwl_fw_error_dump_paging *paging;
841 struct page *pages =
842 mvm->fw_paging_db[i].fw_paging_block;
Sara Sharon4b70f072016-11-30 16:49:11 +0200843 dma_addr_t addr = mvm->fw_paging_db[i].fw_paging_phys;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200844
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200845 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
846 dump_data->len = cpu_to_le32(sizeof(*paging) +
847 PAGING_BLOCK_SIZE);
848 paging = (void *)dump_data->data;
849 paging->index = cpu_to_le32(i);
Sara Sharon4b70f072016-11-30 16:49:11 +0200850 dma_sync_single_for_cpu(mvm->trans->dev, addr,
851 PAGING_BLOCK_SIZE,
852 DMA_BIDIRECTIONAL);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200853 memcpy(paging->data, page_address(pages),
854 PAGING_BLOCK_SIZE);
Golan Ben-Amia6017b92016-03-14 12:24:20 +0200855 dump_data = iwl_fw_error_next_data(dump_data);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200856 }
857 }
858
Golan Ben-Amie87e26392016-04-06 11:59:50 +0300859 if (prph_len) {
860 iwl_dump_prph(mvm->trans, &dump_data,
861 iwl_prph_dump_addr_comm,
862 ARRAY_SIZE(iwl_prph_dump_addr_comm));
863
864 if (mvm->cfg->mq_rx_supported)
865 iwl_dump_prph(mvm->trans, &dump_data,
866 iwl_prph_dump_addr_9000,
867 ARRAY_SIZE(iwl_prph_dump_addr_9000));
868 }
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200869
870dump_trans_data:
871 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans,
872 mvm->fw_dump_trig);
873 fw_error_dump->op_mode_len = file_len;
874 if (fw_error_dump->trans_ptr)
875 file_len += fw_error_dump->trans_ptr->len;
876 dump_file->file_len = cpu_to_le32(file_len);
877
Aviya Erenfeld7e62a692016-09-20 18:07:44 +0300878 sg_dump_data = alloc_sgtable(file_len);
879 if (sg_dump_data) {
880 sg_pcopy_from_buffer(sg_dump_data,
881 sg_nents(sg_dump_data),
882 fw_error_dump->op_mode_ptr,
883 fw_error_dump->op_mode_len, 0);
Johannes Bergc2e27e12016-10-20 15:25:00 +0200884 if (fw_error_dump->trans_ptr)
885 sg_pcopy_from_buffer(sg_dump_data,
886 sg_nents(sg_dump_data),
887 fw_error_dump->trans_ptr->data,
888 fw_error_dump->trans_ptr->len,
889 fw_error_dump->op_mode_len);
Aviya Erenfeld7e62a692016-09-20 18:07:44 +0300890 dev_coredumpsg(mvm->trans->dev, sg_dump_data, file_len,
891 GFP_KERNEL);
892 }
893 vfree(fw_error_dump->op_mode_ptr);
894 vfree(fw_error_dump->trans_ptr);
895 kfree(fw_error_dump);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200896
Emmanuel Grumbach9fb78072016-01-05 09:35:21 +0200897out:
898 iwl_mvm_free_fw_dump_desc(mvm);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200899 mvm->fw_dump_trig = NULL;
900 clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
901}
902
Emmanuel Grumbacha80c7a62016-01-05 09:14:08 +0200903const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200904 .trig_desc = {
905 .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
906 },
907};
908
909int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
Emmanuel Grumbacha80c7a62016-01-05 09:14:08 +0200910 const struct iwl_mvm_dump_desc *desc,
911 const struct iwl_fw_dbg_trigger_tlv *trigger)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200912{
913 unsigned int delay = 0;
914
915 if (trigger)
916 delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
917
Liad Kaufmanf45f9792017-03-23 11:08:59 +0200918 if (WARN(mvm->trans->state == IWL_TRANS_NO_FW,
919 "Can't collect dbg data when FW isn't alive\n"))
920 return -EIO;
921
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200922 if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
923 return -EBUSY;
924
925 if (WARN_ON(mvm->fw_dump_desc))
926 iwl_mvm_free_fw_dump_desc(mvm);
927
928 IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
929 le32_to_cpu(desc->trig_desc.type));
930
931 mvm->fw_dump_desc = desc;
932 mvm->fw_dump_trig = trigger;
933
Johannes Berg86bbb1e2017-03-22 21:44:59 +0100934 schedule_delayed_work(&mvm->fw_dump_wk, delay);
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200935
936 return 0;
937}
938
939int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
940 const char *str, size_t len,
Emmanuel Grumbacha80c7a62016-01-05 09:14:08 +0200941 const struct iwl_fw_dbg_trigger_tlv *trigger)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200942{
943 struct iwl_mvm_dump_desc *desc;
944
945 desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
946 if (!desc)
947 return -ENOMEM;
948
949 desc->len = len;
950 desc->trig_desc.type = cpu_to_le32(trig);
951 memcpy(desc->trig_desc.data, str, len);
952
953 return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
954}
955
956int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
957 struct iwl_fw_dbg_trigger_tlv *trigger,
958 const char *fmt, ...)
959{
960 u16 occurrences = le16_to_cpu(trigger->occurrences);
961 int ret, len = 0;
962 char buf[64];
963
964 if (!occurrences)
965 return 0;
966
967 if (fmt) {
968 va_list ap;
969
970 buf[sizeof(buf) - 1] = '\0';
971
972 va_start(ap, fmt);
973 vsnprintf(buf, sizeof(buf), fmt, ap);
974 va_end(ap);
975
976 /* check for truncation */
977 if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
978 buf[sizeof(buf) - 1] = '\0';
979
980 len = strlen(buf) + 1;
981 }
982
983 ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
984 trigger);
985
986 if (ret)
987 return ret;
988
989 trigger->occurrences = cpu_to_le16(occurrences - 1);
990 return 0;
991}
992
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +0200993int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
994{
995 u8 *ptr;
996 int ret;
997 int i;
998
999 if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
1000 "Invalid configuration %d\n", conf_id))
1001 return -EINVAL;
1002
1003 /* EARLY START - firmware's configuration is hard coded */
1004 if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
1005 !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
Emmanuel Grumbachaddce852017-03-29 10:21:09 +03001006 conf_id == FW_DBG_START_FROM_ALIVE)
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +02001007 return 0;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +02001008
1009 if (!mvm->fw->dbg_conf_tlv[conf_id])
1010 return -EINVAL;
1011
1012 if (mvm->fw_dbg_conf != FW_DBG_INVALID)
1013 IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
1014 mvm->fw_dbg_conf);
1015
1016 /* Send all HCMDs for configuring the FW debug */
1017 ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
1018 for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
1019 struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
1020
1021 ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
1022 le16_to_cpu(cmd->len), cmd->data);
1023 if (ret)
1024 return ret;
1025
1026 ptr += sizeof(*cmd);
1027 ptr += le16_to_cpu(cmd->len);
1028 }
1029
1030 mvm->fw_dbg_conf = conf_id;
Emmanuel Grumbachff6e58e2016-08-03 22:06:43 +03001031
1032 return 0;
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +02001033}