dbg.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 - 2017 Intel Deutschland GmbH
  11. * Copyright(c) 2018 Intel Corporation
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of version 2 of the GNU General Public License as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program;
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <linuxwifi@intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  36. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  37. * Copyright(c) 2018 Intel Corporation
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #ifndef __iwl_fw_dbg_h__
  68. #define __iwl_fw_dbg_h__
  69. #include <linux/workqueue.h>
  70. #include <net/cfg80211.h>
  71. #include "runtime.h"
  72. #include "iwl-prph.h"
  73. #include "iwl-io.h"
  74. #include "file.h"
  75. #include "error-dump.h"
  76. /**
  77. * struct iwl_fw_dump_desc - describes the dump
  78. * @len: length of trig_desc->data
  79. * @trig_desc: the description of the dump
  80. */
  81. struct iwl_fw_dump_desc {
  82. size_t len;
  83. /* must be last */
  84. struct iwl_fw_error_dump_trigger_desc trig_desc;
  85. };
  86. extern const struct iwl_fw_dump_desc iwl_dump_desc_assert;
  87. static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt)
  88. {
  89. if (fwrt->dump.desc != &iwl_dump_desc_assert)
  90. kfree(fwrt->dump.desc);
  91. fwrt->dump.desc = NULL;
  92. fwrt->dump.trig = NULL;
  93. }
  94. void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt);
  95. int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
  96. const struct iwl_fw_dump_desc *desc,
  97. const struct iwl_fw_dbg_trigger_tlv *trigger);
  98. int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
  99. enum iwl_fw_dbg_trigger trig,
  100. const char *str, size_t len,
  101. const struct iwl_fw_dbg_trigger_tlv *trigger);
  102. int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
  103. struct iwl_fw_dbg_trigger_tlv *trigger,
  104. const char *fmt, ...) __printf(3, 4);
  105. int iwl_fw_start_dbg_conf(struct iwl_fw_runtime *fwrt, u8 id);
  106. #define iwl_fw_dbg_trigger_enabled(fw, id) ({ \
  107. void *__dbg_trigger = (fw)->dbg_trigger_tlv[(id)]; \
  108. unlikely(__dbg_trigger); \
  109. })
  110. static inline struct iwl_fw_dbg_trigger_tlv*
  111. _iwl_fw_dbg_get_trigger(const struct iwl_fw *fw, enum iwl_fw_dbg_trigger id)
  112. {
  113. return fw->dbg_trigger_tlv[id];
  114. }
  115. #define iwl_fw_dbg_get_trigger(fw, id) ({ \
  116. BUILD_BUG_ON(!__builtin_constant_p(id)); \
  117. BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \
  118. _iwl_fw_dbg_get_trigger((fw), (id)); \
  119. })
  120. static inline bool
  121. iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig,
  122. struct wireless_dev *wdev)
  123. {
  124. u32 trig_vif = le32_to_cpu(trig->vif_type);
  125. return trig_vif == IWL_FW_DBG_CONF_VIF_ANY ||
  126. wdev->iftype == trig_vif;
  127. }
  128. static inline bool
  129. iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt,
  130. struct iwl_fw_dbg_trigger_tlv *trig)
  131. {
  132. return ((trig->mode & IWL_FW_DBG_TRIGGER_STOP) &&
  133. (fwrt->dump.conf == FW_DBG_INVALID ||
  134. (BIT(fwrt->dump.conf) & le32_to_cpu(trig->stop_conf_ids))));
  135. }
  136. static inline bool
  137. iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt,
  138. struct iwl_fw_dbg_trigger_tlv *trig)
  139. {
  140. unsigned long wind_jiff =
  141. msecs_to_jiffies(le16_to_cpu(trig->trig_dis_ms));
  142. u32 id = le32_to_cpu(trig->id);
  143. /* If this is the first event checked, jump to update start ts */
  144. if (fwrt->dump.non_collect_ts_start[id] &&
  145. (time_after(fwrt->dump.non_collect_ts_start[id] + wind_jiff,
  146. jiffies)))
  147. return true;
  148. fwrt->dump.non_collect_ts_start[id] = jiffies;
  149. return false;
  150. }
  151. static inline bool
  152. iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt,
  153. struct wireless_dev *wdev,
  154. struct iwl_fw_dbg_trigger_tlv *trig)
  155. {
  156. if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev))
  157. return false;
  158. if (iwl_fw_dbg_no_trig_window(fwrt, trig)) {
  159. IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n",
  160. trig->id);
  161. return false;
  162. }
  163. return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig);
  164. }
  165. static inline void
  166. _iwl_fw_dbg_trigger_simple_stop(struct iwl_fw_runtime *fwrt,
  167. struct wireless_dev *wdev,
  168. struct iwl_fw_dbg_trigger_tlv *trigger)
  169. {
  170. if (!trigger)
  171. return;
  172. if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger))
  173. return;
  174. iwl_fw_dbg_collect_trig(fwrt, trigger, NULL);
  175. }
  176. #define iwl_fw_dbg_trigger_simple_stop(fwrt, wdev, trig) \
  177. _iwl_fw_dbg_trigger_simple_stop((fwrt), (wdev), \
  178. iwl_fw_dbg_get_trigger((fwrt)->fw,\
  179. (trig)))
  180. static inline void iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt)
  181. {
  182. if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  183. iwl_set_bits_prph(fwrt->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  184. } else {
  185. iwl_write_prph(fwrt->trans, DBGC_IN_SAMPLE, 0);
  186. udelay(100);
  187. iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, 0);
  188. }
  189. }
  190. static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt)
  191. {
  192. fwrt->dump.conf = FW_DBG_INVALID;
  193. }
  194. void iwl_fw_error_dump_wk(struct work_struct *work);
  195. static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt)
  196. {
  197. flush_delayed_work(&fwrt->dump.wk);
  198. }
  199. static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt)
  200. {
  201. cancel_delayed_work_sync(&fwrt->dump.wk);
  202. }
  203. #ifdef CONFIG_IWLWIFI_DEBUGFS
  204. static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt)
  205. {
  206. fwrt->timestamp.delay = 0;
  207. cancel_delayed_work_sync(&fwrt->timestamp.wk);
  208. }
  209. void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, u32 delay);
  210. static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt)
  211. {
  212. cancel_delayed_work_sync(&fwrt->timestamp.wk);
  213. }
  214. static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt)
  215. {
  216. if (!fwrt->timestamp.delay)
  217. return;
  218. schedule_delayed_work(&fwrt->timestamp.wk,
  219. round_jiffies_relative(fwrt->timestamp.delay));
  220. }
  221. #else
  222. static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) {}
  223. static inline void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt,
  224. u32 delay) {}
  225. static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) {}
  226. static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) {}
  227. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  228. #endif /* __iwl_fw_dbg_h__ */