1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2015,2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
8 #include <linux/devcoredump.h>
10 static int wil_fw_get_crash_dump_bounds(struct wil6210_priv
*wil
,
11 u32
*out_dump_size
, u32
*out_host_min
)
14 const struct fw_map
*map
;
15 u32 host_min
, host_max
, tmp_max
;
20 /* calculate the total size of the unpacked crash dump */
21 BUILD_BUG_ON(ARRAY_SIZE(fw_mapping
) == 0);
24 host_max
= map
->host
+ (map
->to
- map
->from
);
26 for (i
= 1; i
< ARRAY_SIZE(fw_mapping
); i
++) {
32 if (map
->host
< host_min
)
35 tmp_max
= map
->host
+ (map
->to
- map
->from
);
36 if (tmp_max
> host_max
)
40 *out_dump_size
= host_max
- host_min
;
42 *out_host_min
= host_min
;
47 int wil_fw_copy_crash_dump(struct wil6210_priv
*wil
, void *dest
, u32 size
)
50 const struct fw_map
*map
;
52 u32 host_min
, dump_size
, offset
, len
;
54 if (wil_fw_get_crash_dump_bounds(wil
, &dump_size
, &host_min
)) {
55 wil_err(wil
, "fail to obtain crash dump size\n");
59 if (dump_size
> size
) {
60 wil_err(wil
, "not enough space for dump. Need %d have %d\n",
65 down_write(&wil
->mem_lock
);
67 if (test_bit(wil_status_suspending
, wil
->status
) ||
68 test_bit(wil_status_suspended
, wil
->status
)) {
70 "suspend/resume in progress. cannot copy crash dump\n");
71 up_write(&wil
->mem_lock
);
75 /* copy to crash dump area */
76 for (i
= 0; i
< ARRAY_SIZE(fw_mapping
); i
++) {
82 data
= (void * __force
)wil
->csr
+ HOSTADDR(map
->host
);
83 len
= map
->to
- map
->from
;
84 offset
= map
->host
- host_min
;
87 "fw_copy_crash_dump: - dump %s, size %d, offset %d\n",
88 fw_mapping
[i
].name
, len
, offset
);
90 wil_memcpy_fromio_32((void * __force
)(dest
+ offset
),
91 (const void __iomem
* __force
)data
, len
);
94 up_write(&wil
->mem_lock
);
99 void wil_fw_core_dump(struct wil6210_priv
*wil
)
104 if (wil_fw_get_crash_dump_bounds(wil
, &fw_dump_size
, NULL
)) {
105 wil_err(wil
, "fail to get fw dump size\n");
109 fw_dump_data
= vzalloc(fw_dump_size
);
113 if (wil_fw_copy_crash_dump(wil
, fw_dump_data
, fw_dump_size
)) {
117 /* fw_dump_data will be free in device coredump release function
120 dev_coredumpv(wil_to_dev(wil
), fw_dump_data
, fw_dump_size
, GFP_KERNEL
);
121 wil_info(wil
, "fw core dumped, size %d bytes\n", fw_dump_size
);