xref: /linux/drivers/net/wireless/ath/ath10k/coredump.c (revision 55f3538c4923e9dfca132e99ebec370e8094afda)
1 /*
2  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include "coredump.h"
18 
19 #include <linux/devcoredump.h>
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/utsname.h>
23 
24 #include "debug.h"
25 #include "hw.h"
26 
27 static const struct ath10k_mem_section qca6174_hw21_register_sections[] = {
28 	{0x800, 0x810},
29 	{0x820, 0x82C},
30 	{0x830, 0x8F4},
31 	{0x90C, 0x91C},
32 	{0xA14, 0xA18},
33 	{0xA84, 0xA94},
34 	{0xAA8, 0xAD4},
35 	{0xADC, 0xB40},
36 	{0x1000, 0x10A4},
37 	{0x10BC, 0x111C},
38 	{0x1134, 0x1138},
39 	{0x1144, 0x114C},
40 	{0x1150, 0x115C},
41 	{0x1160, 0x1178},
42 	{0x1240, 0x1260},
43 	{0x2000, 0x207C},
44 	{0x3000, 0x3014},
45 	{0x4000, 0x4014},
46 	{0x5000, 0x5124},
47 	{0x6000, 0x6040},
48 	{0x6080, 0x60CC},
49 	{0x6100, 0x611C},
50 	{0x6140, 0x61D8},
51 	{0x6200, 0x6238},
52 	{0x6240, 0x628C},
53 	{0x62C0, 0x62EC},
54 	{0x6380, 0x63E8},
55 	{0x6400, 0x6440},
56 	{0x6480, 0x64CC},
57 	{0x6500, 0x651C},
58 	{0x6540, 0x6580},
59 	{0x6600, 0x6638},
60 	{0x6640, 0x668C},
61 	{0x66C0, 0x66EC},
62 	{0x6780, 0x67E8},
63 	{0x7080, 0x708C},
64 	{0x70C0, 0x70C8},
65 	{0x7400, 0x741C},
66 	{0x7440, 0x7454},
67 	{0x7800, 0x7818},
68 	{0x8000, 0x8004},
69 	{0x8010, 0x8064},
70 	{0x8080, 0x8084},
71 	{0x80A0, 0x80A4},
72 	{0x80C0, 0x80C4},
73 	{0x80E0, 0x80F4},
74 	{0x8100, 0x8104},
75 	{0x8110, 0x812C},
76 	{0x9000, 0x9004},
77 	{0x9800, 0x982C},
78 	{0x9830, 0x9838},
79 	{0x9840, 0x986C},
80 	{0x9870, 0x9898},
81 	{0x9A00, 0x9C00},
82 	{0xD580, 0xD59C},
83 	{0xF000, 0xF0E0},
84 	{0xF140, 0xF190},
85 	{0xF250, 0xF25C},
86 	{0xF260, 0xF268},
87 	{0xF26C, 0xF2A8},
88 	{0x10008, 0x1000C},
89 	{0x10014, 0x10018},
90 	{0x1001C, 0x10020},
91 	{0x10024, 0x10028},
92 	{0x10030, 0x10034},
93 	{0x10040, 0x10054},
94 	{0x10058, 0x1007C},
95 	{0x10080, 0x100C4},
96 	{0x100C8, 0x10114},
97 	{0x1012C, 0x10130},
98 	{0x10138, 0x10144},
99 	{0x10200, 0x10220},
100 	{0x10230, 0x10250},
101 	{0x10260, 0x10280},
102 	{0x10290, 0x102B0},
103 	{0x102C0, 0x102DC},
104 	{0x102E0, 0x102F4},
105 	{0x102FC, 0x1037C},
106 	{0x10380, 0x10390},
107 	{0x10800, 0x10828},
108 	{0x10840, 0x10844},
109 	{0x10880, 0x10884},
110 	{0x108C0, 0x108E8},
111 	{0x10900, 0x10928},
112 	{0x10940, 0x10944},
113 	{0x10980, 0x10984},
114 	{0x109C0, 0x109E8},
115 	{0x10A00, 0x10A28},
116 	{0x10A40, 0x10A50},
117 	{0x11000, 0x11028},
118 	{0x11030, 0x11034},
119 	{0x11038, 0x11068},
120 	{0x11070, 0x11074},
121 	{0x11078, 0x110A8},
122 	{0x110B0, 0x110B4},
123 	{0x110B8, 0x110E8},
124 	{0x110F0, 0x110F4},
125 	{0x110F8, 0x11128},
126 	{0x11138, 0x11144},
127 	{0x11178, 0x11180},
128 	{0x111B8, 0x111C0},
129 	{0x111F8, 0x11200},
130 	{0x11238, 0x1123C},
131 	{0x11270, 0x11274},
132 	{0x11278, 0x1127C},
133 	{0x112B0, 0x112B4},
134 	{0x112B8, 0x112BC},
135 	{0x112F0, 0x112F4},
136 	{0x112F8, 0x112FC},
137 	{0x11338, 0x1133C},
138 	{0x11378, 0x1137C},
139 	{0x113B8, 0x113BC},
140 	{0x113F8, 0x113FC},
141 	{0x11438, 0x11440},
142 	{0x11478, 0x11480},
143 	{0x114B8, 0x114BC},
144 	{0x114F8, 0x114FC},
145 	{0x11538, 0x1153C},
146 	{0x11578, 0x1157C},
147 	{0x115B8, 0x115BC},
148 	{0x115F8, 0x115FC},
149 	{0x11638, 0x1163C},
150 	{0x11678, 0x1167C},
151 	{0x116B8, 0x116BC},
152 	{0x116F8, 0x116FC},
153 	{0x11738, 0x1173C},
154 	{0x11778, 0x1177C},
155 	{0x117B8, 0x117BC},
156 	{0x117F8, 0x117FC},
157 	{0x17000, 0x1701C},
158 	{0x17020, 0x170AC},
159 	{0x18000, 0x18050},
160 	{0x18054, 0x18074},
161 	{0x18080, 0x180D4},
162 	{0x180DC, 0x18104},
163 	{0x18108, 0x1813C},
164 	{0x18144, 0x18148},
165 	{0x18168, 0x18174},
166 	{0x18178, 0x18180},
167 	{0x181C8, 0x181E0},
168 	{0x181E4, 0x181E8},
169 	{0x181EC, 0x1820C},
170 	{0x1825C, 0x18280},
171 	{0x18284, 0x18290},
172 	{0x18294, 0x182A0},
173 	{0x18300, 0x18304},
174 	{0x18314, 0x18320},
175 	{0x18328, 0x18350},
176 	{0x1835C, 0x1836C},
177 	{0x18370, 0x18390},
178 	{0x18398, 0x183AC},
179 	{0x183BC, 0x183D8},
180 	{0x183DC, 0x183F4},
181 	{0x18400, 0x186F4},
182 	{0x186F8, 0x1871C},
183 	{0x18720, 0x18790},
184 	{0x19800, 0x19830},
185 	{0x19834, 0x19840},
186 	{0x19880, 0x1989C},
187 	{0x198A4, 0x198B0},
188 	{0x198BC, 0x19900},
189 	{0x19C00, 0x19C88},
190 	{0x19D00, 0x19D20},
191 	{0x19E00, 0x19E7C},
192 	{0x19E80, 0x19E94},
193 	{0x19E98, 0x19EAC},
194 	{0x19EB0, 0x19EBC},
195 	{0x19F70, 0x19F74},
196 	{0x19F80, 0x19F8C},
197 	{0x19FA0, 0x19FB4},
198 	{0x19FC0, 0x19FD8},
199 	{0x1A000, 0x1A200},
200 	{0x1A204, 0x1A210},
201 	{0x1A228, 0x1A22C},
202 	{0x1A230, 0x1A248},
203 	{0x1A250, 0x1A270},
204 	{0x1A280, 0x1A290},
205 	{0x1A2A0, 0x1A2A4},
206 	{0x1A2C0, 0x1A2EC},
207 	{0x1A300, 0x1A3BC},
208 	{0x1A3F0, 0x1A3F4},
209 	{0x1A3F8, 0x1A434},
210 	{0x1A438, 0x1A444},
211 	{0x1A448, 0x1A468},
212 	{0x1A580, 0x1A58C},
213 	{0x1A644, 0x1A654},
214 	{0x1A670, 0x1A698},
215 	{0x1A6AC, 0x1A6B0},
216 	{0x1A6D0, 0x1A6D4},
217 	{0x1A6EC, 0x1A70C},
218 	{0x1A710, 0x1A738},
219 	{0x1A7C0, 0x1A7D0},
220 	{0x1A7D4, 0x1A7D8},
221 	{0x1A7DC, 0x1A7E4},
222 	{0x1A7F0, 0x1A7F8},
223 	{0x1A888, 0x1A89C},
224 	{0x1A8A8, 0x1A8AC},
225 	{0x1A8C0, 0x1A8DC},
226 	{0x1A8F0, 0x1A8FC},
227 	{0x1AE04, 0x1AE08},
228 	{0x1AE18, 0x1AE24},
229 	{0x1AF80, 0x1AF8C},
230 	{0x1AFA0, 0x1AFB4},
231 	{0x1B000, 0x1B200},
232 	{0x1B284, 0x1B288},
233 	{0x1B2D0, 0x1B2D8},
234 	{0x1B2DC, 0x1B2EC},
235 	{0x1B300, 0x1B340},
236 	{0x1B374, 0x1B378},
237 	{0x1B380, 0x1B384},
238 	{0x1B388, 0x1B38C},
239 	{0x1B404, 0x1B408},
240 	{0x1B420, 0x1B428},
241 	{0x1B440, 0x1B444},
242 	{0x1B448, 0x1B44C},
243 	{0x1B450, 0x1B458},
244 	{0x1B45C, 0x1B468},
245 	{0x1B584, 0x1B58C},
246 	{0x1B68C, 0x1B690},
247 	{0x1B6AC, 0x1B6B0},
248 	{0x1B7F0, 0x1B7F8},
249 	{0x1C800, 0x1CC00},
250 	{0x1CE00, 0x1CE04},
251 	{0x1CF80, 0x1CF84},
252 	{0x1D200, 0x1D800},
253 	{0x1E000, 0x20014},
254 	{0x20100, 0x20124},
255 	{0x21400, 0x217A8},
256 	{0x21800, 0x21BA8},
257 	{0x21C00, 0x21FA8},
258 	{0x22000, 0x223A8},
259 	{0x22400, 0x227A8},
260 	{0x22800, 0x22BA8},
261 	{0x22C00, 0x22FA8},
262 	{0x23000, 0x233A8},
263 	{0x24000, 0x24034},
264 	{0x26000, 0x26064},
265 	{0x27000, 0x27024},
266 	{0x34000, 0x3400C},
267 	{0x34400, 0x3445C},
268 	{0x34800, 0x3485C},
269 	{0x34C00, 0x34C5C},
270 	{0x35000, 0x3505C},
271 	{0x35400, 0x3545C},
272 	{0x35800, 0x3585C},
273 	{0x35C00, 0x35C5C},
274 	{0x36000, 0x3605C},
275 	{0x38000, 0x38064},
276 	{0x38070, 0x380E0},
277 	{0x3A000, 0x3A064},
278 	{0x40000, 0x400A4},
279 	{0x80000, 0x8000C},
280 	{0x80010, 0x80020},
281 };
282 
283 static const struct ath10k_mem_section qca6174_hw30_register_sections[] = {
284 	{0x800, 0x810},
285 	{0x820, 0x82C},
286 	{0x830, 0x8F4},
287 	{0x90C, 0x91C},
288 	{0xA14, 0xA18},
289 	{0xA84, 0xA94},
290 	{0xAA8, 0xAD4},
291 	{0xADC, 0xB40},
292 	{0x1000, 0x10A4},
293 	{0x10BC, 0x111C},
294 	{0x1134, 0x1138},
295 	{0x1144, 0x114C},
296 	{0x1150, 0x115C},
297 	{0x1160, 0x1178},
298 	{0x1240, 0x1260},
299 	{0x2000, 0x207C},
300 	{0x3000, 0x3014},
301 	{0x4000, 0x4014},
302 	{0x5000, 0x5124},
303 	{0x6000, 0x6040},
304 	{0x6080, 0x60CC},
305 	{0x6100, 0x611C},
306 	{0x6140, 0x61D8},
307 	{0x6200, 0x6238},
308 	{0x6240, 0x628C},
309 	{0x62C0, 0x62EC},
310 	{0x6380, 0x63E8},
311 	{0x6400, 0x6440},
312 	{0x6480, 0x64CC},
313 	{0x6500, 0x651C},
314 	{0x6540, 0x6580},
315 	{0x6600, 0x6638},
316 	{0x6640, 0x668C},
317 	{0x66C0, 0x66EC},
318 	{0x6780, 0x67E8},
319 	{0x7080, 0x708C},
320 	{0x70C0, 0x70C8},
321 	{0x7400, 0x741C},
322 	{0x7440, 0x7454},
323 	{0x7800, 0x7818},
324 	{0x8000, 0x8004},
325 	{0x8010, 0x8064},
326 	{0x8080, 0x8084},
327 	{0x80A0, 0x80A4},
328 	{0x80C0, 0x80C4},
329 	{0x80E0, 0x80F4},
330 	{0x8100, 0x8104},
331 	{0x8110, 0x812C},
332 	{0x9000, 0x9004},
333 	{0x9800, 0x982C},
334 	{0x9830, 0x9838},
335 	{0x9840, 0x986C},
336 	{0x9870, 0x9898},
337 	{0x9A00, 0x9C00},
338 	{0xD580, 0xD59C},
339 	{0xF000, 0xF0E0},
340 	{0xF140, 0xF190},
341 	{0xF250, 0xF25C},
342 	{0xF260, 0xF268},
343 	{0xF26C, 0xF2A8},
344 	{0x10008, 0x1000C},
345 	{0x10014, 0x10018},
346 	{0x1001C, 0x10020},
347 	{0x10024, 0x10028},
348 	{0x10030, 0x10034},
349 	{0x10040, 0x10054},
350 	{0x10058, 0x1007C},
351 	{0x10080, 0x100C4},
352 	{0x100C8, 0x10114},
353 	{0x1012C, 0x10130},
354 	{0x10138, 0x10144},
355 	{0x10200, 0x10220},
356 	{0x10230, 0x10250},
357 	{0x10260, 0x10280},
358 	{0x10290, 0x102B0},
359 	{0x102C0, 0x102DC},
360 	{0x102E0, 0x102F4},
361 	{0x102FC, 0x1037C},
362 	{0x10380, 0x10390},
363 	{0x10800, 0x10828},
364 	{0x10840, 0x10844},
365 	{0x10880, 0x10884},
366 	{0x108C0, 0x108E8},
367 	{0x10900, 0x10928},
368 	{0x10940, 0x10944},
369 	{0x10980, 0x10984},
370 	{0x109C0, 0x109E8},
371 	{0x10A00, 0x10A28},
372 	{0x10A40, 0x10A50},
373 	{0x11000, 0x11028},
374 	{0x11030, 0x11034},
375 	{0x11038, 0x11068},
376 	{0x11070, 0x11074},
377 	{0x11078, 0x110A8},
378 	{0x110B0, 0x110B4},
379 	{0x110B8, 0x110E8},
380 	{0x110F0, 0x110F4},
381 	{0x110F8, 0x11128},
382 	{0x11138, 0x11144},
383 	{0x11178, 0x11180},
384 	{0x111B8, 0x111C0},
385 	{0x111F8, 0x11200},
386 	{0x11238, 0x1123C},
387 	{0x11270, 0x11274},
388 	{0x11278, 0x1127C},
389 	{0x112B0, 0x112B4},
390 	{0x112B8, 0x112BC},
391 	{0x112F0, 0x112F4},
392 	{0x112F8, 0x112FC},
393 	{0x11338, 0x1133C},
394 	{0x11378, 0x1137C},
395 	{0x113B8, 0x113BC},
396 	{0x113F8, 0x113FC},
397 	{0x11438, 0x11440},
398 	{0x11478, 0x11480},
399 	{0x114B8, 0x114BC},
400 	{0x114F8, 0x114FC},
401 	{0x11538, 0x1153C},
402 	{0x11578, 0x1157C},
403 	{0x115B8, 0x115BC},
404 	{0x115F8, 0x115FC},
405 	{0x11638, 0x1163C},
406 	{0x11678, 0x1167C},
407 	{0x116B8, 0x116BC},
408 	{0x116F8, 0x116FC},
409 	{0x11738, 0x1173C},
410 	{0x11778, 0x1177C},
411 	{0x117B8, 0x117BC},
412 	{0x117F8, 0x117FC},
413 	{0x17000, 0x1701C},
414 	{0x17020, 0x170AC},
415 	{0x18000, 0x18050},
416 	{0x18054, 0x18074},
417 	{0x18080, 0x180D4},
418 	{0x180DC, 0x18104},
419 	{0x18108, 0x1813C},
420 	{0x18144, 0x18148},
421 	{0x18168, 0x18174},
422 	{0x18178, 0x18180},
423 	{0x181C8, 0x181E0},
424 	{0x181E4, 0x181E8},
425 	{0x181EC, 0x1820C},
426 	{0x1825C, 0x18280},
427 	{0x18284, 0x18290},
428 	{0x18294, 0x182A0},
429 	{0x18300, 0x18304},
430 	{0x18314, 0x18320},
431 	{0x18328, 0x18350},
432 	{0x1835C, 0x1836C},
433 	{0x18370, 0x18390},
434 	{0x18398, 0x183AC},
435 	{0x183BC, 0x183D8},
436 	{0x183DC, 0x183F4},
437 	{0x18400, 0x186F4},
438 	{0x186F8, 0x1871C},
439 	{0x18720, 0x18790},
440 	{0x19800, 0x19830},
441 	{0x19834, 0x19840},
442 	{0x19880, 0x1989C},
443 	{0x198A4, 0x198B0},
444 	{0x198BC, 0x19900},
445 	{0x19C00, 0x19C88},
446 	{0x19D00, 0x19D20},
447 	{0x19E00, 0x19E7C},
448 	{0x19E80, 0x19E94},
449 	{0x19E98, 0x19EAC},
450 	{0x19EB0, 0x19EBC},
451 	{0x19F70, 0x19F74},
452 	{0x19F80, 0x19F8C},
453 	{0x19FA0, 0x19FB4},
454 	{0x19FC0, 0x19FD8},
455 	{0x1A000, 0x1A200},
456 	{0x1A204, 0x1A210},
457 	{0x1A228, 0x1A22C},
458 	{0x1A230, 0x1A248},
459 	{0x1A250, 0x1A270},
460 	{0x1A280, 0x1A290},
461 	{0x1A2A0, 0x1A2A4},
462 	{0x1A2C0, 0x1A2EC},
463 	{0x1A300, 0x1A3BC},
464 	{0x1A3F0, 0x1A3F4},
465 	{0x1A3F8, 0x1A434},
466 	{0x1A438, 0x1A444},
467 	{0x1A448, 0x1A468},
468 	{0x1A580, 0x1A58C},
469 	{0x1A644, 0x1A654},
470 	{0x1A670, 0x1A698},
471 	{0x1A6AC, 0x1A6B0},
472 	{0x1A6D0, 0x1A6D4},
473 	{0x1A6EC, 0x1A70C},
474 	{0x1A710, 0x1A738},
475 	{0x1A7C0, 0x1A7D0},
476 	{0x1A7D4, 0x1A7D8},
477 	{0x1A7DC, 0x1A7E4},
478 	{0x1A7F0, 0x1A7F8},
479 	{0x1A888, 0x1A89C},
480 	{0x1A8A8, 0x1A8AC},
481 	{0x1A8C0, 0x1A8DC},
482 	{0x1A8F0, 0x1A8FC},
483 	{0x1AE04, 0x1AE08},
484 	{0x1AE18, 0x1AE24},
485 	{0x1AF80, 0x1AF8C},
486 	{0x1AFA0, 0x1AFB4},
487 	{0x1B000, 0x1B200},
488 	{0x1B284, 0x1B288},
489 	{0x1B2D0, 0x1B2D8},
490 	{0x1B2DC, 0x1B2EC},
491 	{0x1B300, 0x1B340},
492 	{0x1B374, 0x1B378},
493 	{0x1B380, 0x1B384},
494 	{0x1B388, 0x1B38C},
495 	{0x1B404, 0x1B408},
496 	{0x1B420, 0x1B428},
497 	{0x1B440, 0x1B444},
498 	{0x1B448, 0x1B44C},
499 	{0x1B450, 0x1B458},
500 	{0x1B45C, 0x1B468},
501 	{0x1B584, 0x1B58C},
502 	{0x1B68C, 0x1B690},
503 	{0x1B6AC, 0x1B6B0},
504 	{0x1B7F0, 0x1B7F8},
505 	{0x1C800, 0x1CC00},
506 	{0x1CE00, 0x1CE04},
507 	{0x1CF80, 0x1CF84},
508 	{0x1D200, 0x1D800},
509 	{0x1E000, 0x20014},
510 	{0x20100, 0x20124},
511 	{0x21400, 0x217A8},
512 	{0x21800, 0x21BA8},
513 	{0x21C00, 0x21FA8},
514 	{0x22000, 0x223A8},
515 	{0x22400, 0x227A8},
516 	{0x22800, 0x22BA8},
517 	{0x22C00, 0x22FA8},
518 	{0x23000, 0x233A8},
519 	{0x24000, 0x24034},
520 	{0x26000, 0x26064},
521 	{0x27000, 0x27024},
522 	{0x34000, 0x3400C},
523 	{0x34400, 0x3445C},
524 	{0x34800, 0x3485C},
525 	{0x34C00, 0x34C5C},
526 	{0x35000, 0x3505C},
527 	{0x35400, 0x3545C},
528 	{0x35800, 0x3585C},
529 	{0x35C00, 0x35C5C},
530 	{0x36000, 0x3605C},
531 	{0x38000, 0x38064},
532 	{0x38070, 0x380E0},
533 	{0x3A000, 0x3A074},
534 	{0x40000, 0x400A4},
535 	{0x80000, 0x8000C},
536 	{0x80010, 0x80020},
537 };
538 
539 static const struct ath10k_mem_region qca6174_hw10_mem_regions[] = {
540 	{
541 		.type = ATH10K_MEM_REGION_TYPE_DRAM,
542 		.start = 0x400000,
543 		.len = 0x70000,
544 		.name = "DRAM",
545 		.section_table = {
546 			.sections = NULL,
547 			.size = 0,
548 		},
549 	},
550 	{
551 		.type = ATH10K_MEM_REGION_TYPE_REG,
552 
553 		/* RTC_SOC_BASE_ADDRESS */
554 		.start = 0x0,
555 
556 		/* WLAN_MBOX_BASE_ADDRESS - RTC_SOC_BASE_ADDRESS */
557 		.len = 0x800 - 0x0,
558 
559 		.name = "REG_PART1",
560 		.section_table = {
561 			.sections = NULL,
562 			.size = 0,
563 		},
564 	},
565 	{
566 		.type = ATH10K_MEM_REGION_TYPE_REG,
567 
568 		/* STEREO_BASE_ADDRESS */
569 		.start = 0x27000,
570 
571 		/* USB_BASE_ADDRESS - STEREO_BASE_ADDRESS */
572 		.len = 0x60000 - 0x27000,
573 
574 		.name = "REG_PART2",
575 		.section_table = {
576 			.sections = NULL,
577 			.size = 0,
578 		},
579 	},
580 };
581 
582 static const struct ath10k_mem_region qca6174_hw21_mem_regions[] = {
583 	{
584 		.type = ATH10K_MEM_REGION_TYPE_DRAM,
585 		.start = 0x400000,
586 		.len = 0x70000,
587 		.name = "DRAM",
588 		.section_table = {
589 			.sections = NULL,
590 			.size = 0,
591 		},
592 	},
593 	{
594 		.type = ATH10K_MEM_REGION_TYPE_AXI,
595 		.start = 0xa0000,
596 		.len = 0x18000,
597 		.name = "AXI",
598 		.section_table = {
599 			.sections = NULL,
600 			.size = 0,
601 		},
602 	},
603 	{
604 		.type = ATH10K_MEM_REGION_TYPE_REG,
605 		.start = 0x800,
606 		.len = 0x80020 - 0x800,
607 		.name = "REG_TOTAL",
608 		.section_table = {
609 			.sections = qca6174_hw21_register_sections,
610 			.size = ARRAY_SIZE(qca6174_hw21_register_sections),
611 		},
612 	},
613 };
614 
615 static const struct ath10k_mem_region qca6174_hw30_mem_regions[] = {
616 	{
617 		.type = ATH10K_MEM_REGION_TYPE_DRAM,
618 		.start = 0x400000,
619 		.len = 0x90000,
620 		.name = "DRAM",
621 		.section_table = {
622 			.sections = NULL,
623 			.size = 0,
624 		},
625 	},
626 	{
627 		.type = ATH10K_MEM_REGION_TYPE_AXI,
628 		.start = 0xa0000,
629 		.len = 0x18000,
630 		.name = "AXI",
631 		.section_table = {
632 			.sections = NULL,
633 			.size = 0,
634 		},
635 	},
636 	{
637 		.type = ATH10K_MEM_REGION_TYPE_REG,
638 		.start = 0x800,
639 		.len = 0x80020 - 0x800,
640 		.name = "REG_TOTAL",
641 		.section_table = {
642 			.sections = qca6174_hw30_register_sections,
643 			.size = ARRAY_SIZE(qca6174_hw30_register_sections),
644 		},
645 	},
646 
647 	/* IRAM dump must be put last */
648 	{
649 		.type = ATH10K_MEM_REGION_TYPE_IRAM1,
650 		.start = 0x00980000,
651 		.len = 0x00080000,
652 		.name = "IRAM1",
653 		.section_table = {
654 			.sections = NULL,
655 			.size = 0,
656 		},
657 	},
658 	{
659 		.type = ATH10K_MEM_REGION_TYPE_IRAM2,
660 		.start = 0x00a00000,
661 		.len = 0x00040000,
662 		.name = "IRAM2",
663 		.section_table = {
664 			.sections = NULL,
665 			.size = 0,
666 		},
667 	},
668 };
669 
670 static const struct ath10k_mem_region qca988x_hw20_mem_regions[] = {
671 	{
672 		.type = ATH10K_MEM_REGION_TYPE_DRAM,
673 		.start = 0x400000,
674 		.len = 0x50000,
675 		.name = "DRAM",
676 		.section_table = {
677 			.sections = NULL,
678 			.size = 0,
679 		},
680 	},
681 	{
682 		.type = ATH10K_MEM_REGION_TYPE_REG,
683 		.start = 0x4000,
684 		.len = 0x2000,
685 		.name = "REG_PART1",
686 		.section_table = {
687 			.sections = NULL,
688 			.size = 0,
689 		},
690 	},
691 	{
692 		.type = ATH10K_MEM_REGION_TYPE_REG,
693 		.start = 0x8000,
694 		.len = 0x58000,
695 		.name = "REG_PART2",
696 		.section_table = {
697 			.sections = NULL,
698 			.size = 0,
699 		},
700 	},
701 };
702 
703 static const struct ath10k_hw_mem_layout hw_mem_layouts[] = {
704 	{
705 		.hw_id = QCA6174_HW_1_0_VERSION,
706 		.region_table = {
707 			.regions = qca6174_hw10_mem_regions,
708 			.size = ARRAY_SIZE(qca6174_hw10_mem_regions),
709 		},
710 	},
711 	{
712 		.hw_id = QCA6174_HW_1_1_VERSION,
713 		.region_table = {
714 			.regions = qca6174_hw10_mem_regions,
715 			.size = ARRAY_SIZE(qca6174_hw10_mem_regions),
716 		},
717 	},
718 	{
719 		.hw_id = QCA6174_HW_1_3_VERSION,
720 		.region_table = {
721 			.regions = qca6174_hw10_mem_regions,
722 			.size = ARRAY_SIZE(qca6174_hw10_mem_regions),
723 		},
724 	},
725 	{
726 		.hw_id = QCA6174_HW_2_1_VERSION,
727 		.region_table = {
728 			.regions = qca6174_hw21_mem_regions,
729 			.size = ARRAY_SIZE(qca6174_hw21_mem_regions),
730 		},
731 	},
732 	{
733 		.hw_id = QCA6174_HW_3_0_VERSION,
734 		.region_table = {
735 			.regions = qca6174_hw30_mem_regions,
736 			.size = ARRAY_SIZE(qca6174_hw30_mem_regions),
737 		},
738 	},
739 	{
740 		.hw_id = QCA6174_HW_3_2_VERSION,
741 		.region_table = {
742 			.regions = qca6174_hw30_mem_regions,
743 			.size = ARRAY_SIZE(qca6174_hw30_mem_regions),
744 		},
745 	},
746 	{
747 		.hw_id = QCA9377_HW_1_1_DEV_VERSION,
748 		.region_table = {
749 			.regions = qca6174_hw30_mem_regions,
750 			.size = ARRAY_SIZE(qca6174_hw30_mem_regions),
751 		},
752 	},
753 	{
754 		.hw_id = QCA988X_HW_2_0_VERSION,
755 		.region_table = {
756 			.regions = qca988x_hw20_mem_regions,
757 			.size = ARRAY_SIZE(qca988x_hw20_mem_regions),
758 		},
759 	},
760 };
761 
762 static u32 ath10k_coredump_get_ramdump_size(struct ath10k *ar)
763 {
764 	const struct ath10k_hw_mem_layout *hw;
765 	const struct ath10k_mem_region *mem_region;
766 	size_t size = 0;
767 	int i;
768 
769 	hw = ath10k_coredump_get_mem_layout(ar);
770 
771 	if (!hw)
772 		return 0;
773 
774 	mem_region = &hw->region_table.regions[0];
775 
776 	for (i = 0; i < hw->region_table.size; i++) {
777 		size += mem_region->len;
778 		mem_region++;
779 	}
780 
781 	/* reserve space for the headers */
782 	size += hw->region_table.size * sizeof(struct ath10k_dump_ram_data_hdr);
783 
784 	/* make sure it is aligned 16 bytes for debug message print out */
785 	size = ALIGN(size, 16);
786 
787 	return size;
788 }
789 
790 const struct ath10k_hw_mem_layout *ath10k_coredump_get_mem_layout(struct ath10k *ar)
791 {
792 	int i;
793 
794 	if (!test_bit(ATH10K_FW_CRASH_DUMP_RAM_DATA, &ath10k_coredump_mask))
795 		return NULL;
796 
797 	if (WARN_ON(ar->target_version == 0))
798 		return NULL;
799 
800 	for (i = 0; i < ARRAY_SIZE(hw_mem_layouts); i++) {
801 		if (ar->target_version == hw_mem_layouts[i].hw_id)
802 			return &hw_mem_layouts[i];
803 	}
804 
805 	return NULL;
806 }
807 EXPORT_SYMBOL(ath10k_coredump_get_mem_layout);
808 
809 struct ath10k_fw_crash_data *ath10k_coredump_new(struct ath10k *ar)
810 {
811 	struct ath10k_fw_crash_data *crash_data = ar->coredump.fw_crash_data;
812 
813 	lockdep_assert_held(&ar->data_lock);
814 
815 	if (ath10k_coredump_mask == 0)
816 		/* coredump disabled */
817 		return NULL;
818 
819 	guid_gen(&crash_data->guid);
820 	ktime_get_real_ts64(&crash_data->timestamp);
821 
822 	return crash_data;
823 }
824 EXPORT_SYMBOL(ath10k_coredump_new);
825 
826 static struct ath10k_dump_file_data *ath10k_coredump_build(struct ath10k *ar)
827 {
828 	struct ath10k_fw_crash_data *crash_data = ar->coredump.fw_crash_data;
829 	struct ath10k_ce_crash_hdr *ce_hdr;
830 	struct ath10k_dump_file_data *dump_data;
831 	struct ath10k_tlv_dump_data *dump_tlv;
832 	size_t hdr_len = sizeof(*dump_data);
833 	size_t len, sofar = 0;
834 	unsigned char *buf;
835 
836 	len = hdr_len;
837 
838 	if (test_bit(ATH10K_FW_CRASH_DUMP_REGISTERS, &ath10k_coredump_mask))
839 		len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
840 
841 	if (test_bit(ATH10K_FW_CRASH_DUMP_CE_DATA, &ath10k_coredump_mask))
842 		len += sizeof(*dump_tlv) + sizeof(*ce_hdr) +
843 			CE_COUNT * sizeof(ce_hdr->entries[0]);
844 
845 	if (test_bit(ATH10K_FW_CRASH_DUMP_RAM_DATA, &ath10k_coredump_mask))
846 		len += sizeof(*dump_tlv) + crash_data->ramdump_buf_len;
847 
848 	sofar += hdr_len;
849 
850 	/* This is going to get big when we start dumping FW RAM and such,
851 	 * so go ahead and use vmalloc.
852 	 */
853 	buf = vzalloc(len);
854 	if (!buf)
855 		return NULL;
856 
857 	spin_lock_bh(&ar->data_lock);
858 
859 	dump_data = (struct ath10k_dump_file_data *)(buf);
860 	strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
861 		sizeof(dump_data->df_magic));
862 	dump_data->len = cpu_to_le32(len);
863 
864 	dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
865 
866 	guid_copy(&dump_data->guid, &crash_data->guid);
867 	dump_data->chip_id = cpu_to_le32(ar->chip_id);
868 	dump_data->bus_type = cpu_to_le32(0);
869 	dump_data->target_version = cpu_to_le32(ar->target_version);
870 	dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
871 	dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
872 	dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
873 	dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
874 	dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
875 	dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
876 	dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
877 	dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
878 	dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
879 	dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
880 
881 	strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
882 		sizeof(dump_data->fw_ver));
883 
884 	dump_data->kernel_ver_code = 0;
885 	strlcpy(dump_data->kernel_ver, init_utsname()->release,
886 		sizeof(dump_data->kernel_ver));
887 
888 	dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
889 	dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
890 
891 	if (test_bit(ATH10K_FW_CRASH_DUMP_REGISTERS, &ath10k_coredump_mask)) {
892 		dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
893 		dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
894 		dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
895 		memcpy(dump_tlv->tlv_data, &crash_data->registers,
896 		       sizeof(crash_data->registers));
897 		sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
898 	}
899 
900 	if (test_bit(ATH10K_FW_CRASH_DUMP_CE_DATA, &ath10k_coredump_mask)) {
901 		dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
902 		dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_CE_DATA);
903 		dump_tlv->tlv_len = cpu_to_le32(sizeof(*ce_hdr) +
904 						CE_COUNT * sizeof(ce_hdr->entries[0]));
905 		ce_hdr = (struct ath10k_ce_crash_hdr *)(dump_tlv->tlv_data);
906 		ce_hdr->ce_count = cpu_to_le32(CE_COUNT);
907 		memset(ce_hdr->reserved, 0, sizeof(ce_hdr->reserved));
908 		memcpy(ce_hdr->entries, crash_data->ce_crash_data,
909 		       CE_COUNT * sizeof(ce_hdr->entries[0]));
910 		sofar += sizeof(*dump_tlv) + sizeof(*ce_hdr) +
911 			CE_COUNT * sizeof(ce_hdr->entries[0]);
912 	}
913 
914 	/* Gather ram dump */
915 	if (test_bit(ATH10K_FW_CRASH_DUMP_RAM_DATA, &ath10k_coredump_mask)) {
916 		dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
917 		dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_RAM_DATA);
918 		dump_tlv->tlv_len = cpu_to_le32(crash_data->ramdump_buf_len);
919 		memcpy(dump_tlv->tlv_data, crash_data->ramdump_buf,
920 		       crash_data->ramdump_buf_len);
921 		sofar += sizeof(*dump_tlv) + crash_data->ramdump_buf_len;
922 	}
923 
924 	spin_unlock_bh(&ar->data_lock);
925 
926 	return dump_data;
927 }
928 
929 int ath10k_coredump_submit(struct ath10k *ar)
930 {
931 	struct ath10k_dump_file_data *dump;
932 
933 	if (ath10k_coredump_mask == 0)
934 		/* coredump disabled */
935 		return 0;
936 
937 	dump = ath10k_coredump_build(ar);
938 	if (!dump) {
939 		ath10k_warn(ar, "no crash dump data found for devcoredump");
940 		return -ENODATA;
941 	}
942 
943 	dev_coredumpv(ar->dev, dump, le32_to_cpu(dump->len), GFP_KERNEL);
944 
945 	return 0;
946 }
947 
948 int ath10k_coredump_create(struct ath10k *ar)
949 {
950 	if (ath10k_coredump_mask == 0)
951 		/* coredump disabled */
952 		return 0;
953 
954 	ar->coredump.fw_crash_data = vzalloc(sizeof(*ar->coredump.fw_crash_data));
955 	if (!ar->coredump.fw_crash_data)
956 		return -ENOMEM;
957 
958 	return 0;
959 }
960 
961 int ath10k_coredump_register(struct ath10k *ar)
962 {
963 	struct ath10k_fw_crash_data *crash_data = ar->coredump.fw_crash_data;
964 
965 	if (test_bit(ATH10K_FW_CRASH_DUMP_RAM_DATA, &ath10k_coredump_mask)) {
966 		crash_data->ramdump_buf_len = ath10k_coredump_get_ramdump_size(ar);
967 
968 		crash_data->ramdump_buf = vzalloc(crash_data->ramdump_buf_len);
969 		if (!crash_data->ramdump_buf)
970 			return -ENOMEM;
971 	}
972 
973 	return 0;
974 }
975 
976 void ath10k_coredump_unregister(struct ath10k *ar)
977 {
978 	struct ath10k_fw_crash_data *crash_data = ar->coredump.fw_crash_data;
979 
980 	vfree(crash_data->ramdump_buf);
981 }
982 
983 void ath10k_coredump_destroy(struct ath10k *ar)
984 {
985 	if (ar->coredump.fw_crash_data->ramdump_buf) {
986 		vfree(ar->coredump.fw_crash_data->ramdump_buf);
987 		ar->coredump.fw_crash_data->ramdump_buf = NULL;
988 		ar->coredump.fw_crash_data->ramdump_buf_len = 0;
989 	}
990 
991 	vfree(ar->coredump.fw_crash_data);
992 	ar->coredump.fw_crash_data = NULL;
993 }
994