Commit | Line | Data |
---|---|---|
8ca151b5 JB |
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 | * | |
51368bf7 | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of version 2 of the GNU General Public License as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
22 | * USA | |
23 | * | |
24 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 25 | * in the file called COPYING. |
8ca151b5 JB |
26 | * |
27 | * Contact Information: | |
28 | * Intel Linux Wireless <ilw@linux.intel.com> | |
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
30 | * | |
31 | * BSD LICENSE | |
32 | * | |
51368bf7 | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
34 | * All rights reserved. |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * | |
40 | * * Redistributions of source code must retain the above copyright | |
41 | * notice, this list of conditions and the following disclaimer. | |
42 | * * Redistributions in binary form must reproduce the above copyright | |
43 | * notice, this list of conditions and the following disclaimer in | |
44 | * the documentation and/or other materials provided with the | |
45 | * distribution. | |
46 | * * Neither the name Intel Corporation nor the names of its | |
47 | * contributors may be used to endorse or promote products derived | |
48 | * from this software without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
61 | * | |
62 | *****************************************************************************/ | |
63 | #include <net/mac80211.h> | |
64 | ||
65 | #include "iwl-debug.h" | |
66 | #include "iwl-io.h" | |
7b445f35 | 67 | #include "iwl-prph.h" |
8ca151b5 JB |
68 | |
69 | #include "mvm.h" | |
70 | #include "fw-api-rs.h" | |
71 | ||
72 | /* | |
73 | * Will return 0 even if the cmd failed when RFKILL is asserted unless | |
74 | * CMD_WANT_SKB is set in cmd->flags. | |
75 | */ | |
76 | int iwl_mvm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd) | |
77 | { | |
78 | int ret; | |
79 | ||
debff618 JB |
80 | #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP) |
81 | if (WARN_ON(mvm->d3_test_active)) | |
82 | return -EIO; | |
83 | #endif | |
84 | ||
8ca151b5 JB |
85 | /* |
86 | * Synchronous commands from this op-mode must hold | |
87 | * the mutex, this ensures we don't try to send two | |
88 | * (or more) synchronous commands at a time. | |
89 | */ | |
90 | if (!(cmd->flags & CMD_ASYNC)) | |
91 | lockdep_assert_held(&mvm->mutex); | |
92 | ||
93 | ret = iwl_trans_send_cmd(mvm->trans, cmd); | |
94 | ||
95 | /* | |
96 | * If the caller wants the SKB, then don't hide any problems, the | |
97 | * caller might access the response buffer which will be NULL if | |
98 | * the command failed. | |
99 | */ | |
100 | if (cmd->flags & CMD_WANT_SKB) | |
101 | return ret; | |
102 | ||
103 | /* Silently ignore failures if RFKILL is asserted */ | |
104 | if (!ret || ret == -ERFKILL) | |
105 | return 0; | |
106 | return ret; | |
107 | } | |
108 | ||
109 | int iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u8 id, | |
110 | u32 flags, u16 len, const void *data) | |
111 | { | |
112 | struct iwl_host_cmd cmd = { | |
113 | .id = id, | |
114 | .len = { len, }, | |
115 | .data = { data, }, | |
116 | .flags = flags, | |
117 | }; | |
118 | ||
119 | return iwl_mvm_send_cmd(mvm, &cmd); | |
120 | } | |
121 | ||
122 | /* | |
123 | * We assume that the caller set the status to the sucess value | |
124 | */ | |
125 | int iwl_mvm_send_cmd_status(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd, | |
126 | u32 *status) | |
127 | { | |
128 | struct iwl_rx_packet *pkt; | |
129 | struct iwl_cmd_response *resp; | |
130 | int ret, resp_len; | |
131 | ||
132 | lockdep_assert_held(&mvm->mutex); | |
133 | ||
debff618 JB |
134 | #if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP) |
135 | if (WARN_ON(mvm->d3_test_active)) | |
136 | return -EIO; | |
137 | #endif | |
138 | ||
8ca151b5 JB |
139 | /* |
140 | * Only synchronous commands can wait for status, | |
141 | * we use WANT_SKB so the caller can't. | |
142 | */ | |
143 | if (WARN_ONCE(cmd->flags & (CMD_ASYNC | CMD_WANT_SKB), | |
144 | "cmd flags %x", cmd->flags)) | |
145 | return -EINVAL; | |
146 | ||
a1022927 | 147 | cmd->flags |= CMD_WANT_SKB; |
8ca151b5 JB |
148 | |
149 | ret = iwl_trans_send_cmd(mvm->trans, cmd); | |
150 | if (ret == -ERFKILL) { | |
151 | /* | |
152 | * The command failed because of RFKILL, don't update | |
153 | * the status, leave it as success and return 0. | |
154 | */ | |
155 | return 0; | |
156 | } else if (ret) { | |
157 | return ret; | |
158 | } | |
159 | ||
160 | pkt = cmd->resp_pkt; | |
161 | /* Can happen if RFKILL is asserted */ | |
162 | if (!pkt) { | |
163 | ret = 0; | |
164 | goto out_free_resp; | |
165 | } | |
166 | ||
167 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | |
168 | ret = -EIO; | |
169 | goto out_free_resp; | |
170 | } | |
171 | ||
65b30348 JB |
172 | resp_len = iwl_rx_packet_payload_len(pkt); |
173 | if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { | |
8ca151b5 JB |
174 | ret = -EIO; |
175 | goto out_free_resp; | |
176 | } | |
177 | ||
178 | resp = (void *)pkt->data; | |
179 | *status = le32_to_cpu(resp->status); | |
180 | out_free_resp: | |
181 | iwl_free_resp(cmd); | |
182 | return ret; | |
183 | } | |
184 | ||
185 | /* | |
186 | * We assume that the caller set the status to the sucess value | |
187 | */ | |
188 | int iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u8 id, u16 len, | |
189 | const void *data, u32 *status) | |
190 | { | |
191 | struct iwl_host_cmd cmd = { | |
192 | .id = id, | |
193 | .len = { len, }, | |
194 | .data = { data, }, | |
195 | }; | |
196 | ||
197 | return iwl_mvm_send_cmd_status(mvm, &cmd, status); | |
198 | } | |
199 | ||
200 | #define IWL_DECLARE_RATE_INFO(r) \ | |
201 | [IWL_RATE_##r##M_INDEX] = IWL_RATE_##r##M_PLCP | |
202 | ||
203 | /* | |
204 | * Translate from fw_rate_index (IWL_RATE_XXM_INDEX) to PLCP | |
205 | */ | |
206 | static const u8 fw_rate_idx_to_plcp[IWL_RATE_COUNT] = { | |
207 | IWL_DECLARE_RATE_INFO(1), | |
208 | IWL_DECLARE_RATE_INFO(2), | |
209 | IWL_DECLARE_RATE_INFO(5), | |
210 | IWL_DECLARE_RATE_INFO(11), | |
211 | IWL_DECLARE_RATE_INFO(6), | |
212 | IWL_DECLARE_RATE_INFO(9), | |
213 | IWL_DECLARE_RATE_INFO(12), | |
214 | IWL_DECLARE_RATE_INFO(18), | |
215 | IWL_DECLARE_RATE_INFO(24), | |
216 | IWL_DECLARE_RATE_INFO(36), | |
217 | IWL_DECLARE_RATE_INFO(48), | |
218 | IWL_DECLARE_RATE_INFO(54), | |
219 | }; | |
220 | ||
221 | int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags, | |
222 | enum ieee80211_band band) | |
223 | { | |
224 | int rate = rate_n_flags & RATE_LEGACY_RATE_MSK; | |
225 | int idx; | |
226 | int band_offset = 0; | |
227 | ||
228 | /* Legacy rate format, search for match in table */ | |
229 | if (band == IEEE80211_BAND_5GHZ) | |
230 | band_offset = IWL_FIRST_OFDM_RATE; | |
231 | for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++) | |
232 | if (fw_rate_idx_to_plcp[idx] == rate) | |
233 | return idx - band_offset; | |
234 | ||
235 | return -1; | |
236 | } | |
237 | ||
238 | u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx) | |
239 | { | |
240 | /* Get PLCP rate for tx_cmd->rate_n_flags */ | |
241 | return fw_rate_idx_to_plcp[rate_idx]; | |
242 | } | |
243 | ||
244 | int iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, | |
245 | struct iwl_device_cmd *cmd) | |
246 | { | |
247 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
248 | struct iwl_error_resp *err_resp = (void *)pkt->data; | |
249 | ||
250 | IWL_ERR(mvm, "FW Error notification: type 0x%08X cmd_id 0x%02X\n", | |
251 | le32_to_cpu(err_resp->error_type), err_resp->cmd_id); | |
252 | IWL_ERR(mvm, "FW Error notification: seq 0x%04X service 0x%08X\n", | |
253 | le16_to_cpu(err_resp->bad_cmd_seq_num), | |
254 | le32_to_cpu(err_resp->error_service)); | |
255 | IWL_ERR(mvm, "FW Error notification: timestamp 0x%16llX\n", | |
256 | le64_to_cpu(err_resp->timestamp)); | |
257 | return 0; | |
258 | } | |
259 | ||
260 | /* | |
261 | * Returns the first antenna as ANT_[ABC], as defined in iwl-config.h. | |
262 | * The parameter should also be a combination of ANT_[ABC]. | |
263 | */ | |
264 | u8 first_antenna(u8 mask) | |
265 | { | |
266 | BUILD_BUG_ON(ANT_A != BIT(0)); /* using ffs is wrong if not */ | |
d7dad550 EG |
267 | if (WARN_ON_ONCE(!mask)) /* ffs will return 0 if mask is zeroed */ |
268 | return BIT(0); | |
269 | return BIT(ffs(mask) - 1); | |
8ca151b5 JB |
270 | } |
271 | ||
272 | /* | |
273 | * Toggles between TX antennas to send the probe request on. | |
274 | * Receives the bitmask of valid TX antennas and the *index* used | |
275 | * for the last TX, and returns the next valid *index* to use. | |
276 | * In order to set it in the tx_cmd, must do BIT(idx). | |
277 | */ | |
278 | u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx) | |
279 | { | |
280 | u8 ind = last_idx; | |
281 | int i; | |
282 | ||
283 | for (i = 0; i < RATE_MCS_ANT_NUM; i++) { | |
284 | ind = (ind + 1) % RATE_MCS_ANT_NUM; | |
285 | if (valid & BIT(ind)) | |
286 | return ind; | |
287 | } | |
288 | ||
289 | WARN_ONCE(1, "Failed to toggle between antennas 0x%x", valid); | |
290 | return last_idx; | |
291 | } | |
292 | ||
e5209263 JB |
293 | static const struct { |
294 | const char *name; | |
8ca151b5 JB |
295 | u8 num; |
296 | } advanced_lookup[] = { | |
297 | { "NMI_INTERRUPT_WDG", 0x34 }, | |
298 | { "SYSASSERT", 0x35 }, | |
299 | { "UCODE_VERSION_MISMATCH", 0x37 }, | |
300 | { "BAD_COMMAND", 0x38 }, | |
301 | { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C }, | |
302 | { "FATAL_ERROR", 0x3D }, | |
303 | { "NMI_TRM_HW_ERR", 0x46 }, | |
304 | { "NMI_INTERRUPT_TRM", 0x4C }, | |
305 | { "NMI_INTERRUPT_BREAK_POINT", 0x54 }, | |
306 | { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C }, | |
307 | { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 }, | |
308 | { "NMI_INTERRUPT_HOST", 0x66 }, | |
309 | { "NMI_INTERRUPT_ACTION_PT", 0x7C }, | |
310 | { "NMI_INTERRUPT_UNKNOWN", 0x84 }, | |
311 | { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 }, | |
312 | { "ADVANCED_SYSASSERT", 0 }, | |
313 | }; | |
314 | ||
315 | static const char *desc_lookup(u32 num) | |
316 | { | |
317 | int i; | |
318 | ||
319 | for (i = 0; i < ARRAY_SIZE(advanced_lookup) - 1; i++) | |
320 | if (advanced_lookup[i].num == num) | |
321 | return advanced_lookup[i].name; | |
322 | ||
323 | /* No entry matches 'num', so it is the last: ADVANCED_SYSASSERT */ | |
324 | return advanced_lookup[i].name; | |
325 | } | |
326 | ||
327 | /* | |
328 | * Note: This structure is read from the device with IO accesses, | |
329 | * and the reading already does the endian conversion. As it is | |
330 | * read with u32-sized accesses, any members with a different size | |
331 | * need to be ordered correctly though! | |
332 | */ | |
333 | struct iwl_error_event_table { | |
334 | u32 valid; /* (nonzero) valid, (0) log is empty */ | |
335 | u32 error_id; /* type of error */ | |
336 | u32 pc; /* program counter */ | |
337 | u32 blink1; /* branch link */ | |
338 | u32 blink2; /* branch link */ | |
339 | u32 ilink1; /* interrupt link */ | |
340 | u32 ilink2; /* interrupt link */ | |
341 | u32 data1; /* error-specific data */ | |
342 | u32 data2; /* error-specific data */ | |
343 | u32 data3; /* error-specific data */ | |
344 | u32 bcon_time; /* beacon timer */ | |
345 | u32 tsf_low; /* network timestamp function timer */ | |
346 | u32 tsf_hi; /* network timestamp function timer */ | |
347 | u32 gp1; /* GP1 timer register */ | |
348 | u32 gp2; /* GP2 timer register */ | |
349 | u32 gp3; /* GP3 timer register */ | |
350 | u32 ucode_ver; /* uCode version */ | |
351 | u32 hw_ver; /* HW Silicon version */ | |
352 | u32 brd_ver; /* HW board version */ | |
353 | u32 log_pc; /* log program counter */ | |
354 | u32 frame_ptr; /* frame pointer */ | |
355 | u32 stack_ptr; /* stack pointer */ | |
356 | u32 hcmd; /* last host command header */ | |
357 | u32 isr0; /* isr status register LMPM_NIC_ISR0: | |
358 | * rxtx_flag */ | |
359 | u32 isr1; /* isr status register LMPM_NIC_ISR1: | |
360 | * host_flag */ | |
361 | u32 isr2; /* isr status register LMPM_NIC_ISR2: | |
362 | * enc_flag */ | |
363 | u32 isr3; /* isr status register LMPM_NIC_ISR3: | |
364 | * time_flag */ | |
365 | u32 isr4; /* isr status register LMPM_NIC_ISR4: | |
366 | * wico interrupt */ | |
367 | u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */ | |
368 | u32 wait_event; /* wait event() caller address */ | |
369 | u32 l2p_control; /* L2pControlField */ | |
370 | u32 l2p_duration; /* L2pDurationField */ | |
371 | u32 l2p_mhvalid; /* L2pMhValidBits */ | |
372 | u32 l2p_addr_match; /* L2pAddrMatchStat */ | |
373 | u32 lmpm_pmg_sel; /* indicate which clocks are turned on | |
374 | * (LMPM_PMG_SEL) */ | |
375 | u32 u_timestamp; /* indicate when the date and time of the | |
376 | * compilation */ | |
377 | u32 flow_handler; /* FH read/write pointers, RX credit */ | |
378 | } __packed; | |
379 | ||
01a9ca51 EH |
380 | /* |
381 | * UMAC error struct - relevant starting from family 8000 chip. | |
382 | * Note: This structure is read from the device with IO accesses, | |
383 | * and the reading already does the endian conversion. As it is | |
384 | * read with u32-sized accesses, any members with a different size | |
385 | * need to be ordered correctly though! | |
386 | */ | |
387 | struct iwl_umac_error_event_table { | |
388 | u32 valid; /* (nonzero) valid, (0) log is empty */ | |
389 | u32 error_id; /* type of error */ | |
390 | u32 pc; /* program counter */ | |
391 | u32 blink1; /* branch link */ | |
392 | u32 blink2; /* branch link */ | |
393 | u32 ilink1; /* interrupt link */ | |
394 | u32 ilink2; /* interrupt link */ | |
395 | u32 data1; /* error-specific data */ | |
396 | u32 data2; /* error-specific data */ | |
397 | u32 line; /* source code line of error */ | |
398 | u32 umac_ver; /* umac version */ | |
399 | } __packed; | |
400 | ||
8ca151b5 JB |
401 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
402 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) | |
403 | ||
01a9ca51 EH |
404 | static void iwl_mvm_dump_umac_error_log(struct iwl_mvm *mvm) |
405 | { | |
406 | struct iwl_trans *trans = mvm->trans; | |
407 | struct iwl_umac_error_event_table table; | |
408 | u32 base; | |
409 | ||
410 | base = mvm->umac_error_event_table; | |
411 | ||
412 | if (base < 0x800000 || base >= 0x80C000) { | |
413 | IWL_ERR(mvm, | |
414 | "Not valid error log pointer 0x%08X for %s uCode\n", | |
415 | base, | |
416 | (mvm->cur_ucode == IWL_UCODE_INIT) | |
417 | ? "Init" : "RT"); | |
418 | return; | |
419 | } | |
420 | ||
421 | iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table)); | |
422 | ||
423 | if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) { | |
424 | IWL_ERR(trans, "Start IWL Error Log Dump:\n"); | |
425 | IWL_ERR(trans, "Status: 0x%08lX, count: %d\n", | |
426 | mvm->status, table.valid); | |
427 | } | |
428 | ||
429 | IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id, | |
430 | desc_lookup(table.error_id)); | |
431 | IWL_ERR(mvm, "0x%08X | umac uPc\n", table.pc); | |
432 | IWL_ERR(mvm, "0x%08X | umac branchlink1\n", table.blink1); | |
433 | IWL_ERR(mvm, "0x%08X | umac branchlink2\n", table.blink2); | |
434 | IWL_ERR(mvm, "0x%08X | umac interruptlink1\n", table.ilink1); | |
435 | IWL_ERR(mvm, "0x%08X | umac interruptlink2\n", table.ilink2); | |
436 | IWL_ERR(mvm, "0x%08X | umac data1\n", table.data1); | |
437 | IWL_ERR(mvm, "0x%08X | umac data2\n", table.data2); | |
438 | IWL_ERR(mvm, "0x%08X | umac version\n", table.umac_ver); | |
439 | } | |
440 | ||
8ca151b5 JB |
441 | void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm) |
442 | { | |
443 | struct iwl_trans *trans = mvm->trans; | |
444 | struct iwl_error_event_table table; | |
445 | u32 base; | |
446 | ||
447 | base = mvm->error_event_table; | |
448 | if (mvm->cur_ucode == IWL_UCODE_INIT) { | |
449 | if (!base) | |
450 | base = mvm->fw->init_errlog_ptr; | |
451 | } else { | |
452 | if (!base) | |
453 | base = mvm->fw->inst_errlog_ptr; | |
454 | } | |
455 | ||
15ef4137 | 456 | if (base < 0x800000) { |
8ca151b5 JB |
457 | IWL_ERR(mvm, |
458 | "Not valid error log pointer 0x%08X for %s uCode\n", | |
459 | base, | |
460 | (mvm->cur_ucode == IWL_UCODE_INIT) | |
461 | ? "Init" : "RT"); | |
462 | return; | |
463 | } | |
464 | ||
465 | iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table)); | |
466 | ||
467 | if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) { | |
468 | IWL_ERR(trans, "Start IWL Error Log Dump:\n"); | |
469 | IWL_ERR(trans, "Status: 0x%08lX, count: %d\n", | |
470 | mvm->status, table.valid); | |
471 | } | |
472 | ||
7b445f35 EG |
473 | /* Do not change this output - scripts rely on it */ |
474 | ||
b900a87b EG |
475 | IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version); |
476 | ||
8ca151b5 JB |
477 | trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low, |
478 | table.data1, table.data2, table.data3, | |
479 | table.blink1, table.blink2, table.ilink1, | |
480 | table.ilink2, table.bcon_time, table.gp1, | |
481 | table.gp2, table.gp3, table.ucode_ver, | |
482 | table.hw_ver, table.brd_ver); | |
483 | IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id, | |
484 | desc_lookup(table.error_id)); | |
485 | IWL_ERR(mvm, "0x%08X | uPc\n", table.pc); | |
486 | IWL_ERR(mvm, "0x%08X | branchlink1\n", table.blink1); | |
487 | IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2); | |
488 | IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1); | |
489 | IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2); | |
490 | IWL_ERR(mvm, "0x%08X | data1\n", table.data1); | |
491 | IWL_ERR(mvm, "0x%08X | data2\n", table.data2); | |
492 | IWL_ERR(mvm, "0x%08X | data3\n", table.data3); | |
493 | IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time); | |
494 | IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low); | |
495 | IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi); | |
496 | IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1); | |
497 | IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2); | |
498 | IWL_ERR(mvm, "0x%08X | time gp3\n", table.gp3); | |
499 | IWL_ERR(mvm, "0x%08X | uCode version\n", table.ucode_ver); | |
500 | IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver); | |
501 | IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver); | |
502 | IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd); | |
503 | IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0); | |
504 | IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1); | |
505 | IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2); | |
506 | IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3); | |
507 | IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4); | |
508 | IWL_ERR(mvm, "0x%08X | isr_pref\n", table.isr_pref); | |
509 | IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event); | |
510 | IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control); | |
511 | IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration); | |
512 | IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid); | |
513 | IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match); | |
514 | IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel); | |
515 | IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp); | |
516 | IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler); | |
01a9ca51 EH |
517 | |
518 | if (mvm->support_umac_log) | |
519 | iwl_mvm_dump_umac_error_log(mvm); | |
8ca151b5 JB |
520 | } |
521 | ||
522 | /** | |
523 | * iwl_mvm_send_lq_cmd() - Send link quality command | |
524 | * @init: This command is sent as part of station initialization right | |
525 | * after station has been added. | |
526 | * | |
527 | * The link quality command is sent as the last step of station creation. | |
528 | * This is the special case in which init is set and we call a callback in | |
529 | * this case to clear the state indicating that station creation is in | |
530 | * progress. | |
531 | */ | |
9e680946 | 532 | int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq, bool init) |
8ca151b5 JB |
533 | { |
534 | struct iwl_host_cmd cmd = { | |
535 | .id = LQ_CMD, | |
536 | .len = { sizeof(struct iwl_lq_cmd), }, | |
a1022927 | 537 | .flags = init ? 0 : CMD_ASYNC, |
8ca151b5 JB |
538 | .data = { lq, }, |
539 | }; | |
540 | ||
881acd89 | 541 | if (WARN_ON(lq->sta_id == IWL_MVM_STATION_COUNT)) |
8ca151b5 JB |
542 | return -EINVAL; |
543 | ||
8ca151b5 JB |
544 | return iwl_mvm_send_cmd(mvm, &cmd); |
545 | } | |
9ee718aa EL |
546 | |
547 | /** | |
548 | * iwl_mvm_update_smps - Get a requst to change the SMPS mode | |
549 | * @req_type: The part of the driver who call for a change. | |
550 | * @smps_requests: The request to change the SMPS mode. | |
551 | * | |
552 | * Get a requst to change the SMPS mode, | |
553 | * and change it according to all other requests in the driver. | |
554 | */ | |
555 | void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
556 | enum iwl_mvm_smps_type_request req_type, | |
557 | enum ieee80211_smps_mode smps_request) | |
558 | { | |
559 | struct iwl_mvm_vif *mvmvif; | |
f6415f6b | 560 | enum ieee80211_smps_mode smps_mode; |
9ee718aa EL |
561 | int i; |
562 | ||
563 | lockdep_assert_held(&mvm->mutex); | |
710e4d08 EG |
564 | |
565 | /* SMPS is irrelevant for NICs that don't have at least 2 RX antenna */ | |
4ed735e7 | 566 | if (num_of_ant(mvm->fw->valid_rx_ant) == 1) |
710e4d08 EG |
567 | return; |
568 | ||
f6415f6b EG |
569 | if (vif->type == NL80211_IFTYPE_AP) |
570 | smps_mode = IEEE80211_SMPS_OFF; | |
571 | else | |
572 | smps_mode = IEEE80211_SMPS_AUTOMATIC; | |
573 | ||
9ee718aa EL |
574 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
575 | mvmvif->smps_requests[req_type] = smps_request; | |
576 | for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) { | |
577 | if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) { | |
578 | smps_mode = IEEE80211_SMPS_STATIC; | |
579 | break; | |
580 | } | |
581 | if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC) | |
582 | smps_mode = IEEE80211_SMPS_DYNAMIC; | |
583 | } | |
584 | ||
585 | ieee80211_request_smps(vif, smps_mode); | |
586 | } | |
a21d7bcb | 587 | |
5c904224 EG |
588 | static void iwl_mvm_diversity_iter(void *_data, u8 *mac, |
589 | struct ieee80211_vif *vif) | |
590 | { | |
591 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
592 | bool *result = _data; | |
593 | int i; | |
594 | ||
595 | for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) { | |
596 | if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC || | |
597 | mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC) | |
598 | *result = false; | |
599 | } | |
600 | } | |
601 | ||
602 | bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm) | |
603 | { | |
604 | bool result = true; | |
605 | ||
606 | lockdep_assert_held(&mvm->mutex); | |
607 | ||
608 | if (num_of_ant(mvm->fw->valid_rx_ant) == 1) | |
609 | return false; | |
610 | ||
611 | if (!mvm->cfg->rx_with_siso_diversity) | |
612 | return false; | |
613 | ||
614 | ieee80211_iterate_active_interfaces_atomic( | |
615 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
616 | iwl_mvm_diversity_iter, &result); | |
617 | ||
618 | return result; | |
619 | } | |
620 | ||
a21d7bcb JB |
621 | int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
622 | bool value) | |
623 | { | |
624 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
e03f9bef | 625 | int res; |
a21d7bcb JB |
626 | |
627 | lockdep_assert_held(&mvm->mutex); | |
628 | ||
3510aea4 JB |
629 | if (mvmvif->low_latency == value) |
630 | return 0; | |
631 | ||
a21d7bcb JB |
632 | mvmvif->low_latency = value; |
633 | ||
0166230c | 634 | res = iwl_mvm_update_quotas(mvm, NULL); |
e03f9bef JB |
635 | if (res) |
636 | return res; | |
0ee5bcdd EG |
637 | |
638 | iwl_mvm_bt_coex_vif_change(mvm); | |
639 | ||
999609f1 | 640 | return iwl_mvm_power_update_mac(mvm); |
a21d7bcb | 641 | } |
50df8a30 AB |
642 | |
643 | static void iwl_mvm_ll_iter(void *_data, u8 *mac, struct ieee80211_vif *vif) | |
644 | { | |
645 | bool *result = _data; | |
646 | ||
647 | if (iwl_mvm_vif_low_latency(iwl_mvm_vif_from_mac80211(vif))) | |
648 | *result = true; | |
649 | } | |
650 | ||
651 | bool iwl_mvm_low_latency(struct iwl_mvm *mvm) | |
652 | { | |
653 | bool result = false; | |
654 | ||
655 | ieee80211_iterate_active_interfaces_atomic( | |
656 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
657 | iwl_mvm_ll_iter, &result); | |
658 | ||
659 | return result; | |
660 | } | |
bd5e4744 | 661 | |
b538b8ce | 662 | static void iwl_mvm_idle_iter(void *_data, u8 *mac, struct ieee80211_vif *vif) |
bd5e4744 | 663 | { |
b538b8ce | 664 | bool *idle = _data; |
bd5e4744 | 665 | |
b538b8ce DS |
666 | if (!vif->bss_conf.idle) |
667 | *idle = false; | |
bd5e4744 DS |
668 | } |
669 | ||
b538b8ce | 670 | bool iwl_mvm_is_idle(struct iwl_mvm *mvm) |
bd5e4744 | 671 | { |
b538b8ce | 672 | bool idle = true; |
bd5e4744 DS |
673 | |
674 | ieee80211_iterate_active_interfaces_atomic( | |
675 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
b538b8ce | 676 | iwl_mvm_idle_iter, &idle); |
bd5e4744 | 677 | |
b538b8ce | 678 | return idle; |
bd5e4744 | 679 | } |