1 /******************************************************************************
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.
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
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.
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.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
65 #ifndef __iwl_fw_dbg_h__
66 #define __iwl_fw_dbg_h__
67 #include <linux/workqueue.h>
68 #include <net/cfg80211.h>
73 #include "error-dump.h"
74 #include "api/commands.h"
77 * struct iwl_fw_dump_desc - describes the dump
78 * @len: length of trig_desc->data
79 * @trig_desc: the description of the dump
81 struct iwl_fw_dump_desc {
84 struct iwl_fw_error_dump_trigger_desc trig_desc;
88 * struct iwl_fw_dbg_params - register values to restore
89 * @in_sample: DBGC_IN_SAMPLE value
90 * @out_ctrl: DBGC_OUT_CTRL value
92 struct iwl_fw_dbg_params {
97 extern const struct iwl_fw_dump_desc iwl_dump_desc_assert;
99 static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt)
101 if (fwrt->dump.desc != &iwl_dump_desc_assert)
102 kfree(fwrt->dump.desc);
103 fwrt->dump.desc = NULL;
104 fwrt->dump.trig = NULL;
107 void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt);
108 int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
109 const struct iwl_fw_dump_desc *desc,
110 void *trigger, unsigned int delay);
111 int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
112 enum iwl_fw_dbg_trigger trig,
113 const char *str, size_t len,
114 struct iwl_fw_dbg_trigger_tlv *trigger);
115 int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
116 struct iwl_fw_dbg_trigger_tlv *trigger,
117 const char *fmt, ...) __printf(3, 4);
118 int iwl_fw_start_dbg_conf(struct iwl_fw_runtime *fwrt, u8 id);
120 #define iwl_fw_dbg_trigger_enabled(fw, id) ({ \
121 void *__dbg_trigger = (fw)->dbg.trigger_tlv[(id)]; \
122 unlikely(__dbg_trigger); \
125 static inline struct iwl_fw_dbg_trigger_tlv*
126 _iwl_fw_dbg_get_trigger(const struct iwl_fw *fw, enum iwl_fw_dbg_trigger id)
128 return fw->dbg.trigger_tlv[id];
131 #define iwl_fw_dbg_get_trigger(fw, id) ({ \
132 BUILD_BUG_ON(!__builtin_constant_p(id)); \
133 BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \
134 _iwl_fw_dbg_get_trigger((fw), (id)); \
138 iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig,
139 struct wireless_dev *wdev)
141 u32 trig_vif = le32_to_cpu(trig->vif_type);
143 return trig_vif == IWL_FW_DBG_CONF_VIF_ANY ||
144 wdev->iftype == trig_vif;
148 iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt,
149 struct iwl_fw_dbg_trigger_tlv *trig)
151 return ((trig->mode & IWL_FW_DBG_TRIGGER_STOP) &&
152 (fwrt->dump.conf == FW_DBG_INVALID ||
153 (BIT(fwrt->dump.conf) & le32_to_cpu(trig->stop_conf_ids))));
157 iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt, u32 id, u32 dis_ms)
159 unsigned long wind_jiff = msecs_to_jiffies(dis_ms);
161 /* If this is the first event checked, jump to update start ts */
162 if (fwrt->dump.non_collect_ts_start[id] &&
163 (time_after(fwrt->dump.non_collect_ts_start[id] + wind_jiff,
167 fwrt->dump.non_collect_ts_start[id] = jiffies;
172 iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt,
173 struct wireless_dev *wdev,
174 struct iwl_fw_dbg_trigger_tlv *trig)
176 if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev))
179 if (iwl_fw_dbg_no_trig_window(fwrt, le32_to_cpu(trig->id),
180 le16_to_cpu(trig->trig_dis_ms))) {
181 IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n",
186 return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig);
189 static inline struct iwl_fw_dbg_trigger_tlv*
190 _iwl_fw_dbg_trigger_on(struct iwl_fw_runtime *fwrt,
191 struct wireless_dev *wdev,
192 const enum iwl_fw_dbg_trigger id)
194 struct iwl_fw_dbg_trigger_tlv *trig;
196 if (!iwl_fw_dbg_trigger_enabled(fwrt->fw, id))
199 trig = _iwl_fw_dbg_get_trigger(fwrt->fw, id);
201 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trig))
207 #define iwl_fw_dbg_trigger_on(fwrt, wdev, id) ({ \
208 BUILD_BUG_ON(!__builtin_constant_p(id)); \
209 BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \
210 _iwl_fw_dbg_trigger_on((fwrt), (wdev), (id)); \
214 _iwl_fw_dbg_trigger_simple_stop(struct iwl_fw_runtime *fwrt,
215 struct wireless_dev *wdev,
216 struct iwl_fw_dbg_trigger_tlv *trigger)
221 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger))
224 iwl_fw_dbg_collect_trig(fwrt, trigger, NULL);
227 #define iwl_fw_dbg_trigger_simple_stop(fwrt, wdev, trig) \
228 _iwl_fw_dbg_trigger_simple_stop((fwrt), (wdev), \
229 iwl_fw_dbg_get_trigger((fwrt)->fw,\
232 static int iwl_fw_dbg_start_stop_hcmd(struct iwl_fw_runtime *fwrt, bool start)
234 struct iwl_continuous_record_cmd cont_rec = {};
235 struct iwl_host_cmd hcmd = {
236 .id = LDBG_CONFIG_CMD,
238 .data[0] = &cont_rec,
239 .len[0] = sizeof(cont_rec),
242 cont_rec.record_mode.enable_recording = start ?
243 cpu_to_le16(START_DEBUG_RECORDING) :
244 cpu_to_le16(STOP_DEBUG_RECORDING);
246 return iwl_trans_send_cmd(fwrt->trans, &hcmd);
250 _iwl_fw_dbg_stop_recording(struct iwl_trans *trans,
251 struct iwl_fw_dbg_params *params)
253 if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
254 iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100);
259 params->in_sample = iwl_read_prph(trans, DBGC_IN_SAMPLE);
260 params->out_ctrl = iwl_read_prph(trans, DBGC_OUT_CTRL);
263 iwl_write_prph(trans, DBGC_IN_SAMPLE, 0);
265 iwl_write_prph(trans, DBGC_OUT_CTRL, 0);
269 iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt,
270 struct iwl_fw_dbg_params *params)
272 if (fwrt->trans->cfg->device_family < IWL_DEVICE_FAMILY_22560)
273 _iwl_fw_dbg_stop_recording(fwrt->trans, params);
275 iwl_fw_dbg_start_stop_hcmd(fwrt, false);
279 _iwl_fw_dbg_restart_recording(struct iwl_trans *trans,
280 struct iwl_fw_dbg_params *params)
282 if (WARN_ON(!params))
285 if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
286 iwl_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100);
287 iwl_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1);
288 iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1);
290 iwl_write_prph(trans, DBGC_IN_SAMPLE, params->in_sample);
292 iwl_write_prph(trans, DBGC_OUT_CTRL, params->out_ctrl);
297 iwl_fw_dbg_restart_recording(struct iwl_fw_runtime *fwrt,
298 struct iwl_fw_dbg_params *params)
300 if (fwrt->trans->cfg->device_family < IWL_DEVICE_FAMILY_22560)
301 _iwl_fw_dbg_restart_recording(fwrt->trans, params);
303 iwl_fw_dbg_start_stop_hcmd(fwrt, true);
306 static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt)
308 fwrt->dump.conf = FW_DBG_INVALID;
311 void iwl_fw_error_dump_wk(struct work_struct *work);
313 static inline bool iwl_fw_dbg_is_d3_debug_enabled(struct iwl_fw_runtime *fwrt)
315 return fw_has_capa(&fwrt->fw->ucode_capa,
316 IWL_UCODE_TLV_CAPA_D3_DEBUG) &&
317 fwrt->trans->cfg->d3_debug_data_length &&
318 fwrt->fw->dbg.dump_mask & BIT(IWL_FW_ERROR_DUMP_D3_DEBUG_DATA);
321 void iwl_fw_dbg_read_d3_debug_data(struct iwl_fw_runtime *fwrt);
323 static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt)
325 flush_delayed_work(&fwrt->dump.wk);
328 static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt)
330 cancel_delayed_work_sync(&fwrt->dump.wk);
333 #ifdef CONFIG_IWLWIFI_DEBUGFS
334 static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt)
336 fwrt->timestamp.delay = 0;
337 cancel_delayed_work_sync(&fwrt->timestamp.wk);
340 void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, u32 delay);
342 static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt)
344 cancel_delayed_work_sync(&fwrt->timestamp.wk);
347 static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt)
349 if (!fwrt->timestamp.delay)
352 schedule_delayed_work(&fwrt->timestamp.wk,
353 round_jiffies_relative(fwrt->timestamp.delay));
358 static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) {}
360 static inline void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt,
363 static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) {}
365 static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) {}
367 #endif /* CONFIG_IWLWIFI_DEBUGFS */
369 void iwl_fw_alive_error_dump(struct iwl_fw_runtime *fwrt);
370 void iwl_fw_dbg_collect_sync(struct iwl_fw_runtime *fwrt);
371 #endif /* __iwl_fw_dbg_h__ */