wil_crash_dump.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2015 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. #include "wil6210.h"
  17. #include <linux/devcoredump.h>
  18. static int wil_fw_get_crash_dump_bounds(struct wil6210_priv *wil,
  19. u32 *out_dump_size, u32 *out_host_min)
  20. {
  21. int i;
  22. const struct fw_map *map;
  23. u32 host_min, host_max, tmp_max;
  24. if (!out_dump_size)
  25. return -EINVAL;
  26. /* calculate the total size of the unpacked crash dump */
  27. BUILD_BUG_ON(ARRAY_SIZE(fw_mapping) == 0);
  28. map = &fw_mapping[0];
  29. host_min = map->host;
  30. host_max = map->host + (map->to - map->from);
  31. for (i = 1; i < ARRAY_SIZE(fw_mapping); i++) {
  32. map = &fw_mapping[i];
  33. if (map->host < host_min)
  34. host_min = map->host;
  35. tmp_max = map->host + (map->to - map->from);
  36. if (tmp_max > host_max)
  37. host_max = tmp_max;
  38. }
  39. *out_dump_size = host_max - host_min;
  40. if (out_host_min)
  41. *out_host_min = host_min;
  42. return 0;
  43. }
  44. static int wil_fw_copy_crash_dump(struct wil6210_priv *wil, void *dest,
  45. u32 size)
  46. {
  47. int i;
  48. const struct fw_map *map;
  49. void *data;
  50. u32 host_min, dump_size, offset, len;
  51. if (wil_fw_get_crash_dump_bounds(wil, &dump_size, &host_min)) {
  52. wil_err(wil, "%s: fail to obtain crash dump size\n", __func__);
  53. return -EINVAL;
  54. }
  55. if (dump_size > size) {
  56. wil_err(wil, "%s: not enough space for dump. Need %d have %d\n",
  57. __func__, dump_size, size);
  58. return -EINVAL;
  59. }
  60. /* copy to crash dump area */
  61. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  62. map = &fw_mapping[i];
  63. data = (void * __force)wil->csr + HOSTADDR(map->host);
  64. len = map->to - map->from;
  65. offset = map->host - host_min;
  66. wil_dbg_misc(wil, "%s() - dump %s, size %d, offset %d\n",
  67. __func__, fw_mapping[i].name, len, offset);
  68. wil_memcpy_fromio_32((void * __force)(dest + offset),
  69. (const void __iomem * __force)data, len);
  70. }
  71. return 0;
  72. }
  73. void wil_fw_core_dump(struct wil6210_priv *wil)
  74. {
  75. void *fw_dump_data;
  76. u32 fw_dump_size;
  77. if (wil_fw_get_crash_dump_bounds(wil, &fw_dump_size, NULL)) {
  78. wil_err(wil, "%s: fail to get fw dump size\n", __func__);
  79. return;
  80. }
  81. fw_dump_data = vzalloc(fw_dump_size);
  82. if (!fw_dump_data)
  83. return;
  84. if (wil_fw_copy_crash_dump(wil, fw_dump_data, fw_dump_size)) {
  85. vfree(fw_dump_data);
  86. return;
  87. }
  88. /* fw_dump_data will be free in device coredump release function
  89. * after 5 min
  90. */
  91. dev_coredumpv(wil_to_dev(wil), fw_dump_data, fw_dump_size, GFP_KERNEL);
  92. wil_info(wil, "%s: fw core dumped, size %d bytes\n", __func__,
  93. fw_dump_size);
  94. }