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 68 #ifndef __iwl_fw_dbg_h__ 69 #define __iwl_fw_dbg_h__ 70 #include <linux/workqueue.h> 71 #include <net/cfg80211.h> 72 #include "runtime.h" 73 #include "iwl-prph.h" 74 #include "iwl-io.h" 75 #include "file.h" 76 #include "error-dump.h" 77 78 /** 79 * struct iwl_fw_dump_desc - describes the dump 80 * @len: length of trig_desc->data 81 * @trig_desc: the description of the dump 82 */ 83 struct iwl_fw_dump_desc { 84 size_t len; 85 /* must be last */ 86 struct iwl_fw_error_dump_trigger_desc trig_desc; 87 }; 88 89 extern const struct iwl_fw_dump_desc iwl_dump_desc_assert; 90 91 static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt) 92 { 93 if (fwrt->dump.desc != &iwl_dump_desc_assert) 94 kfree(fwrt->dump.desc); 95 fwrt->dump.desc = NULL; 96 fwrt->dump.trig = NULL; 97 } 98 99 void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt); 100 int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt, 101 const struct iwl_fw_dump_desc *desc, 102 const struct iwl_fw_dbg_trigger_tlv *trigger); 103 int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt, 104 enum iwl_fw_dbg_trigger trig, 105 const char *str, size_t len, 106 const struct iwl_fw_dbg_trigger_tlv *trigger); 107 int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt, 108 struct iwl_fw_dbg_trigger_tlv *trigger, 109 const char *fmt, ...) __printf(3, 4); 110 int iwl_fw_start_dbg_conf(struct iwl_fw_runtime *fwrt, u8 id); 111 112 #define iwl_fw_dbg_trigger_enabled(fw, id) ({ \ 113 void *__dbg_trigger = (fw)->dbg_trigger_tlv[(id)]; \ 114 unlikely(__dbg_trigger); \ 115 }) 116 117 static inline struct iwl_fw_dbg_trigger_tlv* 118 _iwl_fw_dbg_get_trigger(const struct iwl_fw *fw, enum iwl_fw_dbg_trigger id) 119 { 120 return fw->dbg_trigger_tlv[id]; 121 } 122 123 #define iwl_fw_dbg_get_trigger(fw, id) ({ \ 124 BUILD_BUG_ON(!__builtin_constant_p(id)); \ 125 BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \ 126 _iwl_fw_dbg_get_trigger((fw), (id)); \ 127 }) 128 129 static inline bool 130 iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig, 131 struct wireless_dev *wdev) 132 { 133 u32 trig_vif = le32_to_cpu(trig->vif_type); 134 135 return trig_vif == IWL_FW_DBG_CONF_VIF_ANY || 136 wdev->iftype == trig_vif; 137 } 138 139 static inline bool 140 iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt, 141 struct iwl_fw_dbg_trigger_tlv *trig) 142 { 143 return ((trig->mode & IWL_FW_DBG_TRIGGER_STOP) && 144 (fwrt->dump.conf == FW_DBG_INVALID || 145 (BIT(fwrt->dump.conf) & le32_to_cpu(trig->stop_conf_ids)))); 146 } 147 148 static inline bool 149 iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt, 150 struct iwl_fw_dbg_trigger_tlv *trig) 151 { 152 unsigned long wind_jiff = 153 msecs_to_jiffies(le16_to_cpu(trig->trig_dis_ms)); 154 u32 id = le32_to_cpu(trig->id); 155 156 /* If this is the first event checked, jump to update start ts */ 157 if (fwrt->dump.non_collect_ts_start[id] && 158 (time_after(fwrt->dump.non_collect_ts_start[id] + wind_jiff, 159 jiffies))) 160 return true; 161 162 fwrt->dump.non_collect_ts_start[id] = jiffies; 163 return false; 164 } 165 166 static inline bool 167 iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt, 168 struct wireless_dev *wdev, 169 struct iwl_fw_dbg_trigger_tlv *trig) 170 { 171 if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev)) 172 return false; 173 174 if (iwl_fw_dbg_no_trig_window(fwrt, trig)) { 175 IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n", 176 trig->id); 177 return false; 178 } 179 180 return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig); 181 } 182 183 static inline void 184 _iwl_fw_dbg_trigger_simple_stop(struct iwl_fw_runtime *fwrt, 185 struct wireless_dev *wdev, 186 struct iwl_fw_dbg_trigger_tlv *trigger) 187 { 188 if (!trigger) 189 return; 190 191 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger)) 192 return; 193 194 iwl_fw_dbg_collect_trig(fwrt, trigger, NULL); 195 } 196 197 #define iwl_fw_dbg_trigger_simple_stop(fwrt, wdev, trig) \ 198 _iwl_fw_dbg_trigger_simple_stop((fwrt), (wdev), \ 199 iwl_fw_dbg_get_trigger((fwrt)->fw,\ 200 (trig))) 201 202 static inline void iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt) 203 { 204 if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) { 205 iwl_set_bits_prph(fwrt->trans, MON_BUFF_SAMPLE_CTL, 0x100); 206 } else { 207 iwl_write_prph(fwrt->trans, DBGC_IN_SAMPLE, 0); 208 udelay(100); 209 iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, 0); 210 } 211 } 212 213 static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt) 214 { 215 fwrt->dump.conf = FW_DBG_INVALID; 216 } 217 218 void iwl_fw_error_dump_wk(struct work_struct *work); 219 220 static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt) 221 { 222 flush_delayed_work(&fwrt->dump.wk); 223 } 224 225 static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt) 226 { 227 cancel_delayed_work_sync(&fwrt->dump.wk); 228 } 229 230 #ifdef CONFIG_IWLWIFI_DEBUGFS 231 static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) 232 { 233 fwrt->timestamp.delay = 0; 234 cancel_delayed_work_sync(&fwrt->timestamp.wk); 235 } 236 237 void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, u32 delay); 238 239 static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) 240 { 241 cancel_delayed_work_sync(&fwrt->timestamp.wk); 242 } 243 244 static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) 245 { 246 if (!fwrt->timestamp.delay) 247 return; 248 249 schedule_delayed_work(&fwrt->timestamp.wk, 250 round_jiffies_relative(fwrt->timestamp.delay)); 251 } 252 253 #else 254 255 static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) {} 256 257 static inline void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, 258 u32 delay) {} 259 260 static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) {} 261 262 static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) {} 263 264 #endif /* CONFIG_IWLWIFI_DEBUGFS */ 265 266 #endif /* __iwl_fw_dbg_h__ */ 267