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 * You should have received a copy of the GNU General Public License
23 * along with this program;
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <linuxwifi@intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
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.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
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
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.
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.
66 *****************************************************************************/
68 #ifndef __iwl_fw_dbg_h__
69 #define __iwl_fw_dbg_h__
70 #include <linux/workqueue.h>
71 #include <net/cfg80211.h>
76 #include "error-dump.h"
79 * struct iwl_fw_dump_desc - describes the dump
80 * @len: length of trig_desc->data
81 * @trig_desc: the description of the dump
83 struct iwl_fw_dump_desc {
86 struct iwl_fw_error_dump_trigger_desc trig_desc;
89 extern const struct iwl_fw_dump_desc iwl_dump_desc_assert;
91 static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt)
93 if (fwrt->dump.desc != &iwl_dump_desc_assert)
94 kfree(fwrt->dump.desc);
95 fwrt->dump.desc = NULL;
96 fwrt->dump.trig = NULL;
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);
112 #define iwl_fw_dbg_trigger_enabled(fw, id) ({ \
113 void *__dbg_trigger = (fw)->dbg_trigger_tlv[(id)]; \
114 unlikely(__dbg_trigger); \
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)
120 return fw->dbg_trigger_tlv[id];
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)); \
130 iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig,
131 struct wireless_dev *wdev)
133 u32 trig_vif = le32_to_cpu(trig->vif_type);
135 return trig_vif == IWL_FW_DBG_CONF_VIF_ANY ||
136 wdev->iftype == trig_vif;
140 iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt,
141 struct iwl_fw_dbg_trigger_tlv *trig)
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))));
149 iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt,
150 struct iwl_fw_dbg_trigger_tlv *trig)
152 unsigned long wind_jiff =
153 msecs_to_jiffies(le16_to_cpu(trig->trig_dis_ms));
154 u32 id = le32_to_cpu(trig->id);
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,
162 fwrt->dump.non_collect_ts_start[id] = jiffies;
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)
171 if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev))
174 if (iwl_fw_dbg_no_trig_window(fwrt, trig)) {
175 IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n",
180 return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig);
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)
191 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger))
194 iwl_fw_dbg_collect_trig(fwrt, trigger, NULL);
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,\
202 static inline void iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt)
204 if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
205 iwl_set_bits_prph(fwrt->trans, MON_BUFF_SAMPLE_CTL, 0x100);
207 iwl_write_prph(fwrt->trans, DBGC_IN_SAMPLE, 0);
209 iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, 0);
213 static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt)
215 fwrt->dump.conf = FW_DBG_INVALID;
218 void iwl_fw_error_dump_wk(struct work_struct *work);
220 static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt)
222 flush_delayed_work(&fwrt->dump.wk);
225 static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt)
227 cancel_delayed_work_sync(&fwrt->dump.wk);
230 #endif /* __iwl_fw_dbg_h__ */