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#include <net/mac80211.h>
64
65#include "iwl-debug.h"
66#include "iwl-io.h"
67
68#include "mvm.h"
69#include "fw-api-rs.h"
70
71
72
73
74
75int iwl_mvm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd)
76{
77 int ret;
78
79#if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
80 if (WARN_ON(mvm->d3_test_active))
81 return -EIO;
82#endif
83
84
85
86
87
88
89 if (!(cmd->flags & CMD_ASYNC))
90 lockdep_assert_held(&mvm->mutex);
91
92 ret = iwl_trans_send_cmd(mvm->trans, cmd);
93
94
95
96
97
98
99 if (cmd->flags & CMD_WANT_SKB)
100 return ret;
101
102
103 if (!ret || ret == -ERFKILL)
104 return 0;
105 return ret;
106}
107
108int iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u8 id,
109 u32 flags, u16 len, const void *data)
110{
111 struct iwl_host_cmd cmd = {
112 .id = id,
113 .len = { len, },
114 .data = { data, },
115 .flags = flags,
116 };
117
118 return iwl_mvm_send_cmd(mvm, &cmd);
119}
120
121
122
123
124int iwl_mvm_send_cmd_status(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd,
125 u32 *status)
126{
127 struct iwl_rx_packet *pkt;
128 struct iwl_cmd_response *resp;
129 int ret, resp_len;
130
131 lockdep_assert_held(&mvm->mutex);
132
133#if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
134 if (WARN_ON(mvm->d3_test_active))
135 return -EIO;
136#endif
137
138
139
140
141
142 if (WARN_ONCE(cmd->flags & (CMD_ASYNC | CMD_WANT_SKB),
143 "cmd flags %x", cmd->flags))
144 return -EINVAL;
145
146 cmd->flags |= CMD_SYNC | CMD_WANT_SKB;
147
148 ret = iwl_trans_send_cmd(mvm->trans, cmd);
149 if (ret == -ERFKILL) {
150
151
152
153
154 return 0;
155 } else if (ret) {
156 return ret;
157 }
158
159 pkt = cmd->resp_pkt;
160
161 if (!pkt) {
162 ret = 0;
163 goto out_free_resp;
164 }
165
166 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
167 ret = -EIO;
168 goto out_free_resp;
169 }
170
171 resp_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
172 if (WARN_ON_ONCE(resp_len != sizeof(pkt->hdr) + sizeof(*resp))) {
173 ret = -EIO;
174 goto out_free_resp;
175 }
176
177 resp = (void *)pkt->data;
178 *status = le32_to_cpu(resp->status);
179 out_free_resp:
180 iwl_free_resp(cmd);
181 return ret;
182}
183
184
185
186
187int iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u8 id, u16 len,
188 const void *data, u32 *status)
189{
190 struct iwl_host_cmd cmd = {
191 .id = id,
192 .len = { len, },
193 .data = { data, },
194 };
195
196 return iwl_mvm_send_cmd_status(mvm, &cmd, status);
197}
198
199#define IWL_DECLARE_RATE_INFO(r) \
200 [IWL_RATE_##r##M_INDEX] = IWL_RATE_##r##M_PLCP
201
202
203
204
205static const u8 fw_rate_idx_to_plcp[IWL_RATE_COUNT] = {
206 IWL_DECLARE_RATE_INFO(1),
207 IWL_DECLARE_RATE_INFO(2),
208 IWL_DECLARE_RATE_INFO(5),
209 IWL_DECLARE_RATE_INFO(11),
210 IWL_DECLARE_RATE_INFO(6),
211 IWL_DECLARE_RATE_INFO(9),
212 IWL_DECLARE_RATE_INFO(12),
213 IWL_DECLARE_RATE_INFO(18),
214 IWL_DECLARE_RATE_INFO(24),
215 IWL_DECLARE_RATE_INFO(36),
216 IWL_DECLARE_RATE_INFO(48),
217 IWL_DECLARE_RATE_INFO(54),
218};
219
220int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
221 enum ieee80211_band band)
222{
223 int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
224 int idx;
225 int band_offset = 0;
226
227
228 if (band == IEEE80211_BAND_5GHZ)
229 band_offset = IWL_FIRST_OFDM_RATE;
230 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
231 if (fw_rate_idx_to_plcp[idx] == rate)
232 return idx - band_offset;
233
234 return -1;
235}
236
237u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx)
238{
239
240 return fw_rate_idx_to_plcp[rate_idx];
241}
242
243int iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
244 struct iwl_device_cmd *cmd)
245{
246 struct iwl_rx_packet *pkt = rxb_addr(rxb);
247 struct iwl_error_resp *err_resp = (void *)pkt->data;
248
249 IWL_ERR(mvm, "FW Error notification: type 0x%08X cmd_id 0x%02X\n",
250 le32_to_cpu(err_resp->error_type), err_resp->cmd_id);
251 IWL_ERR(mvm, "FW Error notification: seq 0x%04X service 0x%08X\n",
252 le16_to_cpu(err_resp->bad_cmd_seq_num),
253 le32_to_cpu(err_resp->error_service));
254 IWL_ERR(mvm, "FW Error notification: timestamp 0x%16llX\n",
255 le64_to_cpu(err_resp->timestamp));
256 return 0;
257}
258
259
260
261
262
263u8 first_antenna(u8 mask)
264{
265 BUILD_BUG_ON(ANT_A != BIT(0));
266 if (WARN_ON_ONCE(!mask))
267 return BIT(0);
268 return BIT(ffs(mask) - 1);
269}
270
271
272
273
274
275
276
277u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx)
278{
279 u8 ind = last_idx;
280 int i;
281
282 for (i = 0; i < RATE_MCS_ANT_NUM; i++) {
283 ind = (ind + 1) % RATE_MCS_ANT_NUM;
284 if (valid & BIT(ind))
285 return ind;
286 }
287
288 WARN_ONCE(1, "Failed to toggle between antennas 0x%x", valid);
289 return last_idx;
290}
291
292static struct {
293 char *name;
294 u8 num;
295} advanced_lookup[] = {
296 { "NMI_INTERRUPT_WDG", 0x34 },
297 { "SYSASSERT", 0x35 },
298 { "UCODE_VERSION_MISMATCH", 0x37 },
299 { "BAD_COMMAND", 0x38 },
300 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
301 { "FATAL_ERROR", 0x3D },
302 { "NMI_TRM_HW_ERR", 0x46 },
303 { "NMI_INTERRUPT_TRM", 0x4C },
304 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
305 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
306 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
307 { "NMI_INTERRUPT_HOST", 0x66 },
308 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
309 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
310 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
311 { "ADVANCED_SYSASSERT", 0 },
312};
313
314static const char *desc_lookup(u32 num)
315{
316 int i;
317
318 for (i = 0; i < ARRAY_SIZE(advanced_lookup) - 1; i++)
319 if (advanced_lookup[i].num == num)
320 return advanced_lookup[i].name;
321
322
323 return advanced_lookup[i].name;
324}
325
326
327
328
329
330
331
332struct iwl_error_event_table {
333 u32 valid;
334 u32 error_id;
335 u32 pc;
336 u32 blink1;
337 u32 blink2;
338 u32 ilink1;
339 u32 ilink2;
340 u32 data1;
341 u32 data2;
342 u32 data3;
343 u32 bcon_time;
344 u32 tsf_low;
345 u32 tsf_hi;
346 u32 gp1;
347 u32 gp2;
348 u32 gp3;
349 u32 ucode_ver;
350 u32 hw_ver;
351 u32 brd_ver;
352 u32 log_pc;
353 u32 frame_ptr;
354 u32 stack_ptr;
355 u32 hcmd;
356 u32 isr0;
357
358 u32 isr1;
359
360 u32 isr2;
361
362 u32 isr3;
363
364 u32 isr4;
365
366 u32 isr_pref;
367 u32 wait_event;
368 u32 l2p_control;
369 u32 l2p_duration;
370 u32 l2p_mhvalid;
371 u32 l2p_addr_match;
372 u32 lmpm_pmg_sel;
373
374 u32 u_timestamp;
375
376 u32 flow_handler;
377} __packed;
378
379#define ERROR_START_OFFSET (1 * sizeof(u32))
380#define ERROR_ELEM_SIZE (7 * sizeof(u32))
381
382void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
383{
384 struct iwl_trans *trans = mvm->trans;
385 struct iwl_error_event_table table;
386 u32 base;
387
388 base = mvm->error_event_table;
389 if (mvm->cur_ucode == IWL_UCODE_INIT) {
390 if (!base)
391 base = mvm->fw->init_errlog_ptr;
392 } else {
393 if (!base)
394 base = mvm->fw->inst_errlog_ptr;
395 }
396
397 if (base < 0x800000 || base >= 0x80C000) {
398 IWL_ERR(mvm,
399 "Not valid error log pointer 0x%08X for %s uCode\n",
400 base,
401 (mvm->cur_ucode == IWL_UCODE_INIT)
402 ? "Init" : "RT");
403 return;
404 }
405
406 iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
407
408 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
409 IWL_ERR(trans, "Start IWL Error Log Dump:\n");
410 IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
411 mvm->status, table.valid);
412 }
413
414 trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
415 table.data1, table.data2, table.data3,
416 table.blink1, table.blink2, table.ilink1,
417 table.ilink2, table.bcon_time, table.gp1,
418 table.gp2, table.gp3, table.ucode_ver,
419 table.hw_ver, table.brd_ver);
420 IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
421 desc_lookup(table.error_id));
422 IWL_ERR(mvm, "0x%08X | uPc\n", table.pc);
423 IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1);
424 IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
425 IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
426 IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
427 IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
428 IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
429 IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
430 IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
431 IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
432 IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
433 IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
434 IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
435 IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3);
436 IWL_ERR(mvm, "0x%08X | uCode version\n", table.ucode_ver);
437 IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
438 IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
439 IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
440 IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
441 IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
442 IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
443 IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
444 IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
445 IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref);
446 IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
447 IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
448 IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
449 IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
450 IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
451 IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
452 IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
453 IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
454}
455
456
457
458
459
460
461
462
463
464
465
466int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq,
467 u8 flags, bool init)
468{
469 struct iwl_host_cmd cmd = {
470 .id = LQ_CMD,
471 .len = { sizeof(struct iwl_lq_cmd), },
472 .flags = flags,
473 .data = { lq, },
474 };
475
476 if (WARN_ON(lq->sta_id == IWL_MVM_STATION_COUNT))
477 return -EINVAL;
478
479 if (WARN_ON(init && (cmd.flags & CMD_ASYNC)))
480 return -EINVAL;
481
482 return iwl_mvm_send_cmd(mvm, &cmd);
483}
484
485
486
487
488
489
490
491
492
493void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
494 enum iwl_mvm_smps_type_request req_type,
495 enum ieee80211_smps_mode smps_request)
496{
497 struct iwl_mvm_vif *mvmvif;
498 enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
499 int i;
500
501 lockdep_assert_held(&mvm->mutex);
502 mvmvif = iwl_mvm_vif_from_mac80211(vif);
503 mvmvif->smps_requests[req_type] = smps_request;
504 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
505 if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) {
506 smps_mode = IEEE80211_SMPS_STATIC;
507 break;
508 }
509 if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
510 smps_mode = IEEE80211_SMPS_DYNAMIC;
511 }
512
513 ieee80211_request_smps(vif, smps_mode);
514}
515