dbg.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. *
  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:
  28. * Intel Linux Wireless <linuxwifi@intel.com>
  29. * 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
  35. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  36. * 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. #ifndef __iwl_fw_dbg_h__
  66. #define __iwl_fw_dbg_h__
  67. #include <linux/workqueue.h>
  68. #include <net/cfg80211.h>
  69. #include "runtime.h"
  70. #include "iwl-prph.h"
  71. #include "iwl-io.h"
  72. #include "file.h"
  73. #include "error-dump.h"
  74. /**
  75. * struct iwl_fw_dump_desc - describes the dump
  76. * @len: length of trig_desc->data
  77. * @trig_desc: the description of the dump
  78. */
  79. struct iwl_fw_dump_desc {
  80. size_t len;
  81. /* must be last */
  82. struct iwl_fw_error_dump_trigger_desc trig_desc;
  83. };
  84. extern const struct iwl_fw_dump_desc iwl_dump_desc_assert;
  85. static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt)
  86. {
  87. if (fwrt->dump.desc != &iwl_dump_desc_assert)
  88. kfree(fwrt->dump.desc);
  89. fwrt->dump.desc = NULL;
  90. }
  91. void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt);
  92. int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
  93. const struct iwl_fw_dump_desc *desc,
  94. const struct iwl_fw_dbg_trigger_tlv *trigger);
  95. int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
  96. enum iwl_fw_dbg_trigger trig,
  97. const char *str, size_t len,
  98. const struct iwl_fw_dbg_trigger_tlv *trigger);
  99. int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
  100. struct iwl_fw_dbg_trigger_tlv *trigger,
  101. const char *fmt, ...) __printf(3, 4);
  102. int iwl_fw_start_dbg_conf(struct iwl_fw_runtime *fwrt, u8 id);
  103. #define iwl_fw_dbg_trigger_enabled(fw, id) ({ \
  104. void *__dbg_trigger = (fw)->dbg_trigger_tlv[(id)]; \
  105. unlikely(__dbg_trigger); \
  106. })
  107. static inline struct iwl_fw_dbg_trigger_tlv*
  108. _iwl_fw_dbg_get_trigger(const struct iwl_fw *fw, enum iwl_fw_dbg_trigger id)
  109. {
  110. return fw->dbg_trigger_tlv[id];
  111. }
  112. #define iwl_fw_dbg_get_trigger(fw, id) ({ \
  113. BUILD_BUG_ON(!__builtin_constant_p(id)); \
  114. BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \
  115. _iwl_fw_dbg_get_trigger((fw), (id)); \
  116. })
  117. static inline bool
  118. iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig,
  119. struct wireless_dev *wdev)
  120. {
  121. u32 trig_vif = le32_to_cpu(trig->vif_type);
  122. return trig_vif == IWL_FW_DBG_CONF_VIF_ANY ||
  123. wdev->iftype == trig_vif;
  124. }
  125. static inline bool
  126. iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt,
  127. struct iwl_fw_dbg_trigger_tlv *trig)
  128. {
  129. return ((trig->mode & IWL_FW_DBG_TRIGGER_STOP) &&
  130. (fwrt->dump.conf == FW_DBG_INVALID ||
  131. (BIT(fwrt->dump.conf) & le32_to_cpu(trig->stop_conf_ids))));
  132. }
  133. static inline bool
  134. iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt,
  135. struct iwl_fw_dbg_trigger_tlv *trig)
  136. {
  137. unsigned long wind_jiff =
  138. msecs_to_jiffies(le16_to_cpu(trig->trig_dis_ms));
  139. u32 id = le32_to_cpu(trig->id);
  140. /* If this is the first event checked, jump to update start ts */
  141. if (fwrt->dump.non_collect_ts_start[id] &&
  142. (time_after(fwrt->dump.non_collect_ts_start[id] + wind_jiff,
  143. jiffies)))
  144. return true;
  145. fwrt->dump.non_collect_ts_start[id] = jiffies;
  146. return false;
  147. }
  148. static inline bool
  149. iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt,
  150. struct wireless_dev *wdev,
  151. struct iwl_fw_dbg_trigger_tlv *trig)
  152. {
  153. if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev))
  154. return false;
  155. if (iwl_fw_dbg_no_trig_window(fwrt, trig)) {
  156. IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n",
  157. trig->id);
  158. return false;
  159. }
  160. return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig);
  161. }
  162. static inline void
  163. _iwl_fw_dbg_trigger_simple_stop(struct iwl_fw_runtime *fwrt,
  164. struct wireless_dev *wdev,
  165. struct iwl_fw_dbg_trigger_tlv *trigger)
  166. {
  167. if (!trigger)
  168. return;
  169. if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger))
  170. return;
  171. iwl_fw_dbg_collect_trig(fwrt, trigger, NULL);
  172. }
  173. #define iwl_fw_dbg_trigger_simple_stop(fwrt, wdev, trig) \
  174. _iwl_fw_dbg_trigger_simple_stop((fwrt), (wdev), \
  175. iwl_fw_dbg_get_trigger((fwrt)->fw,\
  176. (trig)))
  177. static inline void iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt)
  178. {
  179. if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  180. iwl_set_bits_prph(fwrt->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  181. } else {
  182. iwl_write_prph(fwrt->trans, DBGC_IN_SAMPLE, 0);
  183. udelay(100);
  184. iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, 0);
  185. }
  186. }
  187. static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt)
  188. {
  189. iwl_fw_dbg_stop_recording(fwrt);
  190. fwrt->dump.conf = FW_DBG_INVALID;
  191. }
  192. void iwl_fw_error_dump_wk(struct work_struct *work);
  193. static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt)
  194. {
  195. flush_delayed_work(&fwrt->dump.wk);
  196. }
  197. static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt)
  198. {
  199. cancel_delayed_work_sync(&fwrt->dump.wk);
  200. }
  201. #endif /* __iwl_fw_dbg_h__ */