1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66#ifndef __iwl_fw_dbg_h__
67#define __iwl_fw_dbg_h__
68#include <linux/workqueue.h>
69#include <net/cfg80211.h>
70#include "runtime.h"
71#include "iwl-prph.h"
72#include "iwl-io.h"
73#include "file.h"
74#include "error-dump.h"
75
76
77
78
79
80
81struct iwl_fw_dump_desc {
82 size_t len;
83
84 struct iwl_fw_error_dump_trigger_desc trig_desc;
85};
86
87extern const struct iwl_fw_dump_desc iwl_dump_desc_assert;
88
89static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt)
90{
91 if (fwrt->dump.desc != &iwl_dump_desc_assert)
92 kfree(fwrt->dump.desc);
93 fwrt->dump.desc = NULL;
94}
95
96void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt);
97int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
98 const struct iwl_fw_dump_desc *desc,
99 const struct iwl_fw_dbg_trigger_tlv *trigger);
100int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
101 enum iwl_fw_dbg_trigger trig,
102 const char *str, size_t len,
103 const struct iwl_fw_dbg_trigger_tlv *trigger);
104int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
105 struct iwl_fw_dbg_trigger_tlv *trigger,
106 const char *fmt, ...) __printf(3, 4);
107int iwl_fw_start_dbg_conf(struct iwl_fw_runtime *fwrt, u8 id);
108
109#define iwl_fw_dbg_trigger_enabled(fw, id) ({ \
110 void *__dbg_trigger = (fw)->dbg_trigger_tlv[(id)]; \
111 unlikely(__dbg_trigger); \
112})
113
114static inline struct iwl_fw_dbg_trigger_tlv*
115_iwl_fw_dbg_get_trigger(const struct iwl_fw *fw, enum iwl_fw_dbg_trigger id)
116{
117 return fw->dbg_trigger_tlv[id];
118}
119
120#define iwl_fw_dbg_get_trigger(fw, id) ({ \
121 BUILD_BUG_ON(!__builtin_constant_p(id)); \
122 BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \
123 _iwl_fw_dbg_get_trigger((fw), (id)); \
124})
125
126static inline bool
127iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig,
128 struct wireless_dev *wdev)
129{
130 u32 trig_vif = le32_to_cpu(trig->vif_type);
131
132 return trig_vif == IWL_FW_DBG_CONF_VIF_ANY ||
133 wdev->iftype == trig_vif;
134}
135
136static inline bool
137iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt,
138 struct iwl_fw_dbg_trigger_tlv *trig)
139{
140 return ((trig->mode & IWL_FW_DBG_TRIGGER_STOP) &&
141 (fwrt->dump.conf == FW_DBG_INVALID ||
142 (BIT(fwrt->dump.conf) & le32_to_cpu(trig->stop_conf_ids))));
143}
144
145static inline bool
146iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt,
147 struct iwl_fw_dbg_trigger_tlv *trig)
148{
149 unsigned long wind_jiff =
150 msecs_to_jiffies(le16_to_cpu(trig->trig_dis_ms));
151 u32 id = le32_to_cpu(trig->id);
152
153
154 if (fwrt->dump.non_collect_ts_start[id] &&
155 (time_after(fwrt->dump.non_collect_ts_start[id] + wind_jiff,
156 jiffies)))
157 return true;
158
159 fwrt->dump.non_collect_ts_start[id] = jiffies;
160 return false;
161}
162
163static inline bool
164iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt,
165 struct wireless_dev *wdev,
166 struct iwl_fw_dbg_trigger_tlv *trig)
167{
168 if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev))
169 return false;
170
171 if (iwl_fw_dbg_no_trig_window(fwrt, trig)) {
172 IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n",
173 trig->id);
174 return false;
175 }
176
177 return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig);
178}
179
180static inline void
181_iwl_fw_dbg_trigger_simple_stop(struct iwl_fw_runtime *fwrt,
182 struct wireless_dev *wdev,
183 struct iwl_fw_dbg_trigger_tlv *trigger)
184{
185 if (!trigger)
186 return;
187
188 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger))
189 return;
190
191 iwl_fw_dbg_collect_trig(fwrt, trigger, NULL);
192}
193
194#define iwl_fw_dbg_trigger_simple_stop(fwrt, wdev, trig) \
195 _iwl_fw_dbg_trigger_simple_stop((fwrt), (wdev), \
196 iwl_fw_dbg_get_trigger((fwrt)->fw,\
197 (trig)))
198
199static inline void iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt)
200{
201 if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
202 iwl_set_bits_prph(fwrt->trans, MON_BUFF_SAMPLE_CTL, 0x100);
203 } else {
204 iwl_write_prph(fwrt->trans, DBGC_IN_SAMPLE, 0);
205 udelay(100);
206 iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, 0);
207 }
208}
209
210static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt)
211{
212 iwl_fw_dbg_stop_recording(fwrt);
213
214 fwrt->dump.conf = FW_DBG_INVALID;
215}
216
217void iwl_fw_error_dump_wk(struct work_struct *work);
218
219static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt)
220{
221 flush_delayed_work(&fwrt->dump.wk);
222}
223
224static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt)
225{
226 cancel_delayed_work_sync(&fwrt->dump.wk);
227}
228
229#endif
230