blob: 0093e78dd571bd21ac926948f69d519aba690e79 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Sara Sharon87d0e1a2017-01-11 21:33:38 +020010 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020036 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Sara Sharon87d0e1a2017-01-11 21:33:38 +020037 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010038 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
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
49 * distribution.
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.
53 *
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.
65 *
66 *****************************************************************************/
67#include <net/mac80211.h>
68
69#include "iwl-debug.h"
70#include "iwl-io.h"
Emmanuel Grumbach7b445f32014-03-20 11:08:19 +020071#include "iwl-prph.h"
Luca Coelho6b54ebf2017-05-05 16:11:24 +030072#include "iwl-csr.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020073#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010074#include "mvm.h"
75#include "fw-api-rs.h"
76
77/*
78 * Will return 0 even if the cmd failed when RFKILL is asserted unless
79 * CMD_WANT_SKB is set in cmd->flags.
80 */
81int iwl_mvm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd)
82{
83 int ret;
84
Johannes Bergdebff612013-05-14 13:53:45 +020085#if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
86 if (WARN_ON(mvm->d3_test_active))
87 return -EIO;
88#endif
89
Johannes Berg8ca151b2013-01-24 14:25:36 +010090 /*
91 * Synchronous commands from this op-mode must hold
92 * the mutex, this ensures we don't try to send two
93 * (or more) synchronous commands at a time.
94 */
Luca Coelho71b12302016-03-11 12:12:16 +020095 if (!(cmd->flags & CMD_ASYNC)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +010096 lockdep_assert_held(&mvm->mutex);
Luca Coelho71b12302016-03-11 12:12:16 +020097 if (!(cmd->flags & CMD_SEND_IN_IDLE))
98 iwl_mvm_ref(mvm, IWL_MVM_REF_SENDING_CMD);
99 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100
101 ret = iwl_trans_send_cmd(mvm->trans, cmd);
102
Luca Coelho71b12302016-03-11 12:12:16 +0200103 if (!(cmd->flags & (CMD_ASYNC | CMD_SEND_IN_IDLE)))
104 iwl_mvm_unref(mvm, IWL_MVM_REF_SENDING_CMD);
105
Johannes Berg8ca151b2013-01-24 14:25:36 +0100106 /*
107 * If the caller wants the SKB, then don't hide any problems, the
108 * caller might access the response buffer which will be NULL if
109 * the command failed.
110 */
111 if (cmd->flags & CMD_WANT_SKB)
112 return ret;
113
114 /* Silently ignore failures if RFKILL is asserted */
115 if (!ret || ret == -ERFKILL)
116 return 0;
117 return ret;
118}
119
Aviya Erenfeldab021652015-06-09 16:45:52 +0300120int iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u32 id,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100121 u32 flags, u16 len, const void *data)
122{
123 struct iwl_host_cmd cmd = {
124 .id = id,
125 .len = { len, },
126 .data = { data, },
127 .flags = flags,
128 };
129
130 return iwl_mvm_send_cmd(mvm, &cmd);
131}
132
133/*
Sara Sharon0d365ae2015-03-31 12:24:05 +0300134 * We assume that the caller set the status to the success value
Johannes Berg8ca151b2013-01-24 14:25:36 +0100135 */
136int iwl_mvm_send_cmd_status(struct iwl_mvm *mvm, struct iwl_host_cmd *cmd,
137 u32 *status)
138{
139 struct iwl_rx_packet *pkt;
140 struct iwl_cmd_response *resp;
141 int ret, resp_len;
142
143 lockdep_assert_held(&mvm->mutex);
144
Johannes Bergdebff612013-05-14 13:53:45 +0200145#if defined(CONFIG_IWLWIFI_DEBUGFS) && defined(CONFIG_PM_SLEEP)
146 if (WARN_ON(mvm->d3_test_active))
147 return -EIO;
148#endif
149
Johannes Berg8ca151b2013-01-24 14:25:36 +0100150 /*
151 * Only synchronous commands can wait for status,
152 * we use WANT_SKB so the caller can't.
153 */
154 if (WARN_ONCE(cmd->flags & (CMD_ASYNC | CMD_WANT_SKB),
155 "cmd flags %x", cmd->flags))
156 return -EINVAL;
157
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300158 cmd->flags |= CMD_WANT_SKB;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159
160 ret = iwl_trans_send_cmd(mvm->trans, cmd);
161 if (ret == -ERFKILL) {
162 /*
163 * The command failed because of RFKILL, don't update
164 * the status, leave it as success and return 0.
165 */
166 return 0;
167 } else if (ret) {
168 return ret;
169 }
170
171 pkt = cmd->resp_pkt;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100172
Johannes Berg65b30342014-01-08 13:16:33 +0100173 resp_len = iwl_rx_packet_payload_len(pkt);
174 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100175 ret = -EIO;
176 goto out_free_resp;
177 }
178
179 resp = (void *)pkt->data;
180 *status = le32_to_cpu(resp->status);
181 out_free_resp:
182 iwl_free_resp(cmd);
183 return ret;
184}
185
186/*
187 * We assume that the caller set the status to the sucess value
188 */
Aviya Erenfeldab021652015-06-09 16:45:52 +0300189int iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u32 id, u16 len,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100190 const void *data, u32 *status)
191{
192 struct iwl_host_cmd cmd = {
193 .id = id,
194 .len = { len, },
195 .data = { data, },
196 };
197
198 return iwl_mvm_send_cmd_status(mvm, &cmd, status);
199}
200
201#define IWL_DECLARE_RATE_INFO(r) \
202 [IWL_RATE_##r##M_INDEX] = IWL_RATE_##r##M_PLCP
203
204/*
205 * Translate from fw_rate_index (IWL_RATE_XXM_INDEX) to PLCP
206 */
207static const u8 fw_rate_idx_to_plcp[IWL_RATE_COUNT] = {
208 IWL_DECLARE_RATE_INFO(1),
209 IWL_DECLARE_RATE_INFO(2),
210 IWL_DECLARE_RATE_INFO(5),
211 IWL_DECLARE_RATE_INFO(11),
212 IWL_DECLARE_RATE_INFO(6),
213 IWL_DECLARE_RATE_INFO(9),
214 IWL_DECLARE_RATE_INFO(12),
215 IWL_DECLARE_RATE_INFO(18),
216 IWL_DECLARE_RATE_INFO(24),
217 IWL_DECLARE_RATE_INFO(36),
218 IWL_DECLARE_RATE_INFO(48),
219 IWL_DECLARE_RATE_INFO(54),
220};
221
222int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200223 enum nl80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100224{
225 int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
226 int idx;
227 int band_offset = 0;
228
229 /* Legacy rate format, search for match in table */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200230 if (band == NL80211_BAND_5GHZ)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100231 band_offset = IWL_FIRST_OFDM_RATE;
232 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
233 if (fw_rate_idx_to_plcp[idx] == rate)
234 return idx - band_offset;
235
236 return -1;
237}
238
239u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx)
240{
241 /* Get PLCP rate for tx_cmd->rate_n_flags */
242 return fw_rate_idx_to_plcp[rate_idx];
243}
244
Johannes Berg04168412015-06-23 21:22:09 +0200245void iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100246{
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));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100257}
258
259/*
260 * Returns the first antenna as ANT_[ABC], as defined in iwl-config.h.
261 * The parameter should also be a combination of ANT_[ABC].
262 */
263u8 first_antenna(u8 mask)
264{
265 BUILD_BUG_ON(ANT_A != BIT(0)); /* using ffs is wrong if not */
Emmanuel Grumbachd7dad552013-04-14 14:41:03 +0300266 if (WARN_ON_ONCE(!mask)) /* ffs will return 0 if mask is zeroed */
267 return BIT(0);
268 return BIT(ffs(mask) - 1);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100269}
270
271/*
272 * Toggles between TX antennas to send the probe request on.
273 * Receives the bitmask of valid TX antennas and the *index* used
274 * for the last TX, and returns the next valid *index* to use.
275 * In order to set it in the tx_cmd, must do BIT(idx).
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
Johannes Berge5209262014-01-20 23:38:59 +0100292static const struct {
293 const char *name;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100294 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 /* No entry matches 'num', so it is the last: ADVANCED_SYSASSERT */
323 return advanced_lookup[i].name;
324}
325
326/*
327 * Note: This structure is read from the device with IO accesses,
328 * and the reading already does the endian conversion. As it is
329 * read with u32-sized accesses, any members with a different size
330 * need to be ordered correctly though!
331 */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200332struct iwl_error_event_table_v1 {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100333 u32 valid; /* (nonzero) valid, (0) log is empty */
334 u32 error_id; /* type of error */
335 u32 pc; /* program counter */
336 u32 blink1; /* branch link */
337 u32 blink2; /* branch link */
338 u32 ilink1; /* interrupt link */
339 u32 ilink2; /* interrupt link */
340 u32 data1; /* error-specific data */
341 u32 data2; /* error-specific data */
342 u32 data3; /* error-specific data */
343 u32 bcon_time; /* beacon timer */
344 u32 tsf_low; /* network timestamp function timer */
345 u32 tsf_hi; /* network timestamp function timer */
346 u32 gp1; /* GP1 timer register */
347 u32 gp2; /* GP2 timer register */
348 u32 gp3; /* GP3 timer register */
349 u32 ucode_ver; /* uCode version */
350 u32 hw_ver; /* HW Silicon version */
351 u32 brd_ver; /* HW board version */
352 u32 log_pc; /* log program counter */
353 u32 frame_ptr; /* frame pointer */
354 u32 stack_ptr; /* stack pointer */
355 u32 hcmd; /* last host command header */
356 u32 isr0; /* isr status register LMPM_NIC_ISR0:
357 * rxtx_flag */
358 u32 isr1; /* isr status register LMPM_NIC_ISR1:
359 * host_flag */
360 u32 isr2; /* isr status register LMPM_NIC_ISR2:
361 * enc_flag */
362 u32 isr3; /* isr status register LMPM_NIC_ISR3:
363 * time_flag */
364 u32 isr4; /* isr status register LMPM_NIC_ISR4:
365 * wico interrupt */
366 u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */
367 u32 wait_event; /* wait event() caller address */
368 u32 l2p_control; /* L2pControlField */
369 u32 l2p_duration; /* L2pDurationField */
370 u32 l2p_mhvalid; /* L2pMhValidBits */
371 u32 l2p_addr_match; /* L2pAddrMatchStat */
372 u32 lmpm_pmg_sel; /* indicate which clocks are turned on
373 * (LMPM_PMG_SEL) */
374 u32 u_timestamp; /* indicate when the date and time of the
375 * compilation */
376 u32 flow_handler; /* FH read/write pointers, RX credit */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200377} __packed /* LOG_ERROR_TABLE_API_S_VER_1 */;
378
379struct iwl_error_event_table {
380 u32 valid; /* (nonzero) valid, (0) log is empty */
381 u32 error_id; /* type of error */
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200382 u32 trm_hw_status0; /* TRM HW status */
383 u32 trm_hw_status1; /* TRM HW status */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200384 u32 blink2; /* branch link */
385 u32 ilink1; /* interrupt link */
386 u32 ilink2; /* interrupt link */
387 u32 data1; /* error-specific data */
388 u32 data2; /* error-specific data */
389 u32 data3; /* error-specific data */
390 u32 bcon_time; /* beacon timer */
391 u32 tsf_low; /* network timestamp function timer */
392 u32 tsf_hi; /* network timestamp function timer */
393 u32 gp1; /* GP1 timer register */
394 u32 gp2; /* GP2 timer register */
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200395 u32 fw_rev_type; /* firmware revision type */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200396 u32 major; /* uCode version major */
397 u32 minor; /* uCode version minor */
398 u32 hw_ver; /* HW Silicon version */
399 u32 brd_ver; /* HW board version */
400 u32 log_pc; /* log program counter */
401 u32 frame_ptr; /* frame pointer */
402 u32 stack_ptr; /* stack pointer */
403 u32 hcmd; /* last host command header */
404 u32 isr0; /* isr status register LMPM_NIC_ISR0:
405 * rxtx_flag */
406 u32 isr1; /* isr status register LMPM_NIC_ISR1:
407 * host_flag */
408 u32 isr2; /* isr status register LMPM_NIC_ISR2:
409 * enc_flag */
410 u32 isr3; /* isr status register LMPM_NIC_ISR3:
411 * time_flag */
412 u32 isr4; /* isr status register LMPM_NIC_ISR4:
413 * wico interrupt */
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200414 u32 last_cmd_id; /* last HCMD id handled by the firmware */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200415 u32 wait_event; /* wait event() caller address */
416 u32 l2p_control; /* L2pControlField */
417 u32 l2p_duration; /* L2pDurationField */
418 u32 l2p_mhvalid; /* L2pMhValidBits */
419 u32 l2p_addr_match; /* L2pAddrMatchStat */
420 u32 lmpm_pmg_sel; /* indicate which clocks are turned on
421 * (LMPM_PMG_SEL) */
422 u32 u_timestamp; /* indicate when the date and time of the
423 * compilation */
424 u32 flow_handler; /* FH read/write pointers, RX credit */
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200425} __packed /* LOG_ERROR_TABLE_API_S_VER_3 */;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426
Eran Harary01a9ca52014-02-03 09:29:57 +0200427/*
428 * UMAC error struct - relevant starting from family 8000 chip.
429 * Note: This structure is read from the device with IO accesses,
430 * and the reading already does the endian conversion. As it is
431 * read with u32-sized accesses, any members with a different size
432 * need to be ordered correctly though!
433 */
434struct iwl_umac_error_event_table {
435 u32 valid; /* (nonzero) valid, (0) log is empty */
436 u32 error_id; /* type of error */
Eran Harary01a9ca52014-02-03 09:29:57 +0200437 u32 blink1; /* branch link */
438 u32 blink2; /* branch link */
439 u32 ilink1; /* interrupt link */
440 u32 ilink2; /* interrupt link */
441 u32 data1; /* error-specific data */
442 u32 data2; /* error-specific data */
Eran Harary32be1a82014-08-24 08:02:46 +0300443 u32 data3; /* error-specific data */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200444 u32 umac_major;
445 u32 umac_minor;
Eran Harary32be1a82014-08-24 08:02:46 +0300446 u32 frame_pointer; /* core register 27*/
447 u32 stack_pointer; /* core register 28 */
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200448 u32 cmd_header; /* latest host cmd sent to UMAC */
Eran Harary32be1a82014-08-24 08:02:46 +0300449 u32 nic_isr_pref; /* ISR status register */
Eran Harary01a9ca52014-02-03 09:29:57 +0200450} __packed;
451
Johannes Berg8ca151b2013-01-24 14:25:36 +0100452#define ERROR_START_OFFSET (1 * sizeof(u32))
453#define ERROR_ELEM_SIZE (7 * sizeof(u32))
454
Eran Harary01a9ca52014-02-03 09:29:57 +0200455static void iwl_mvm_dump_umac_error_log(struct iwl_mvm *mvm)
456{
457 struct iwl_trans *trans = mvm->trans;
458 struct iwl_umac_error_event_table table;
459 u32 base;
460
461 base = mvm->umac_error_event_table;
462
Eran Harary32be1a82014-08-24 08:02:46 +0300463 if (base < 0x800000) {
Eran Harary01a9ca52014-02-03 09:29:57 +0200464 IWL_ERR(mvm,
465 "Not valid error log pointer 0x%08X for %s uCode\n",
466 base,
467 (mvm->cur_ucode == IWL_UCODE_INIT)
468 ? "Init" : "RT");
469 return;
470 }
471
472 iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
473
474 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
475 IWL_ERR(trans, "Start IWL Error Log Dump:\n");
476 IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
477 mvm->status, table.valid);
478 }
479
Johannes Bergedbad052015-01-28 23:43:24 +0100480 IWL_ERR(mvm, "0x%08X | %s\n", table.error_id,
Eran Harary01a9ca52014-02-03 09:29:57 +0200481 desc_lookup(table.error_id));
Eran Harary01a9ca52014-02-03 09:29:57 +0200482 IWL_ERR(mvm, "0x%08X | umac branchlink1\n", table.blink1);
483 IWL_ERR(mvm, "0x%08X | umac branchlink2\n", table.blink2);
484 IWL_ERR(mvm, "0x%08X | umac interruptlink1\n", table.ilink1);
485 IWL_ERR(mvm, "0x%08X | umac interruptlink2\n", table.ilink2);
486 IWL_ERR(mvm, "0x%08X | umac data1\n", table.data1);
487 IWL_ERR(mvm, "0x%08X | umac data2\n", table.data2);
Eran Harary32be1a82014-08-24 08:02:46 +0300488 IWL_ERR(mvm, "0x%08X | umac data3\n", table.data3);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200489 IWL_ERR(mvm, "0x%08X | umac major\n", table.umac_major);
490 IWL_ERR(mvm, "0x%08X | umac minor\n", table.umac_minor);
Eran Harary32be1a82014-08-24 08:02:46 +0300491 IWL_ERR(mvm, "0x%08X | frame pointer\n", table.frame_pointer);
492 IWL_ERR(mvm, "0x%08X | stack pointer\n", table.stack_pointer);
493 IWL_ERR(mvm, "0x%08X | last host cmd\n", table.cmd_header);
494 IWL_ERR(mvm, "0x%08X | isr status reg\n", table.nic_isr_pref);
Eran Harary01a9ca52014-02-03 09:29:57 +0200495}
496
Sara Sharon5c228d62016-11-24 13:48:27 +0200497static void iwl_mvm_dump_lmac_error_log(struct iwl_mvm *mvm, u32 base)
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200498{
499 struct iwl_trans *trans = mvm->trans;
500 struct iwl_error_event_table table;
Luca Coelho6b54ebf2017-05-05 16:11:24 +0300501 u32 val;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200502
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200503 if (mvm->cur_ucode == IWL_UCODE_INIT) {
504 if (!base)
505 base = mvm->fw->init_errlog_ptr;
506 } else {
507 if (!base)
508 base = mvm->fw->inst_errlog_ptr;
509 }
510
Sara Sharon3ac37d02016-09-08 10:44:38 +0300511 if (base < 0x400000) {
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200512 IWL_ERR(mvm,
513 "Not valid error log pointer 0x%08X for %s uCode\n",
514 base,
515 (mvm->cur_ucode == IWL_UCODE_INIT)
516 ? "Init" : "RT");
517 return;
518 }
519
Luca Coelho6b54ebf2017-05-05 16:11:24 +0300520 /* check if there is a HW error */
521 val = iwl_trans_read_mem32(trans, base);
522 if (((val & ~0xf) == 0xa5a5a5a0) || ((val & ~0xf) == 0x5a5a5a50)) {
523 int err;
524
525 IWL_ERR(trans, "HW error, resetting before reading\n");
526
527 /* reset the device */
528 iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
529 usleep_range(1000, 2000);
530
531 /* set INIT_DONE flag */
532 iwl_set_bit(trans, CSR_GP_CNTRL,
533 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
534
535 /* and wait for clock stabilization */
536 if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
537 udelay(2);
538
539 err = iwl_poll_bit(trans, CSR_GP_CNTRL,
540 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
541 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
542 25000);
543 if (err < 0) {
544 IWL_DEBUG_INFO(trans,
545 "Failed to reset the card for the dump\n");
546 return;
547 }
548 }
549
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200550 iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
551
552 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
553 IWL_ERR(trans, "Start IWL Error Log Dump:\n");
554 IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
555 mvm->status, table.valid);
556 }
557
558 /* Do not change this output - scripts rely on it */
559
560 IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version);
561
562 trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
563 table.data1, table.data2, table.data3,
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200564 table.blink2, table.ilink1,
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200565 table.ilink2, table.bcon_time, table.gp1,
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200566 table.gp2, table.fw_rev_type, table.major,
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200567 table.minor, table.hw_ver, table.brd_ver);
568 IWL_ERR(mvm, "0x%08X | %-28s\n", table.error_id,
569 desc_lookup(table.error_id));
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200570 IWL_ERR(mvm, "0x%08X | trm_hw_status0\n", table.trm_hw_status0);
571 IWL_ERR(mvm, "0x%08X | trm_hw_status1\n", table.trm_hw_status1);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200572 IWL_ERR(mvm, "0x%08X | branchlink2\n", table.blink2);
573 IWL_ERR(mvm, "0x%08X | interruptlink1\n", table.ilink1);
574 IWL_ERR(mvm, "0x%08X | interruptlink2\n", table.ilink2);
575 IWL_ERR(mvm, "0x%08X | data1\n", table.data1);
576 IWL_ERR(mvm, "0x%08X | data2\n", table.data2);
577 IWL_ERR(mvm, "0x%08X | data3\n", table.data3);
578 IWL_ERR(mvm, "0x%08X | beacon time\n", table.bcon_time);
579 IWL_ERR(mvm, "0x%08X | tsf low\n", table.tsf_low);
580 IWL_ERR(mvm, "0x%08X | tsf hi\n", table.tsf_hi);
581 IWL_ERR(mvm, "0x%08X | time gp1\n", table.gp1);
582 IWL_ERR(mvm, "0x%08X | time gp2\n", table.gp2);
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200583 IWL_ERR(mvm, "0x%08X | uCode revision type\n", table.fw_rev_type);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200584 IWL_ERR(mvm, "0x%08X | uCode version major\n", table.major);
585 IWL_ERR(mvm, "0x%08X | uCode version minor\n", table.minor);
586 IWL_ERR(mvm, "0x%08X | hw version\n", table.hw_ver);
587 IWL_ERR(mvm, "0x%08X | board version\n", table.brd_ver);
588 IWL_ERR(mvm, "0x%08X | hcmd\n", table.hcmd);
589 IWL_ERR(mvm, "0x%08X | isr0\n", table.isr0);
590 IWL_ERR(mvm, "0x%08X | isr1\n", table.isr1);
591 IWL_ERR(mvm, "0x%08X | isr2\n", table.isr2);
592 IWL_ERR(mvm, "0x%08X | isr3\n", table.isr3);
593 IWL_ERR(mvm, "0x%08X | isr4\n", table.isr4);
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +0200594 IWL_ERR(mvm, "0x%08X | last cmd Id\n", table.last_cmd_id);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200595 IWL_ERR(mvm, "0x%08X | wait_event\n", table.wait_event);
596 IWL_ERR(mvm, "0x%08X | l2p_control\n", table.l2p_control);
597 IWL_ERR(mvm, "0x%08X | l2p_duration\n", table.l2p_duration);
598 IWL_ERR(mvm, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
599 IWL_ERR(mvm, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
600 IWL_ERR(mvm, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
601 IWL_ERR(mvm, "0x%08X | timestamp\n", table.u_timestamp);
602 IWL_ERR(mvm, "0x%08X | flow_handler\n", table.flow_handler);
Sara Sharon5c228d62016-11-24 13:48:27 +0200603}
604
605void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
606{
607 iwl_mvm_dump_lmac_error_log(mvm, mvm->error_event_table[0]);
608
609 if (mvm->error_event_table[1])
610 iwl_mvm_dump_lmac_error_log(mvm, mvm->error_event_table[1]);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200611
612 if (mvm->support_umac_log)
613 iwl_mvm_dump_umac_error_log(mvm);
614}
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +0200615
Liad Kaufman9794c642015-08-19 17:34:28 +0300616int iwl_mvm_find_free_queue(struct iwl_mvm *mvm, u8 sta_id, u8 minq, u8 maxq)
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300617{
618 int i;
619
620 lockdep_assert_held(&mvm->queue_info_lock);
621
Sara Sharon396952e2017-02-22 19:40:55 +0200622 /* This should not be hit with new TX path */
623 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
624 return -ENOSPC;
625
Liad Kaufman9794c642015-08-19 17:34:28 +0300626 /* Start by looking for a free queue */
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300627 for (i = minq; i <= maxq; i++)
628 if (mvm->queue_info[i].hw_queue_refcount == 0 &&
Liad Kaufmancf961e12015-08-13 19:16:08 +0300629 mvm->queue_info[i].status == IWL_MVM_QUEUE_FREE)
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300630 return i;
631
Liad Kaufman9794c642015-08-19 17:34:28 +0300632 /*
633 * If no free queue found - settle for an inactive one to reconfigure
634 * Make sure that the inactive queue either already belongs to this STA,
635 * or that if it belongs to another one - it isn't the reserved queue
636 */
637 for (i = minq; i <= maxq; i++)
638 if (mvm->queue_info[i].status == IWL_MVM_QUEUE_INACTIVE &&
639 (sta_id == mvm->queue_info[i].ra_sta_id ||
640 !mvm->queue_info[i].reserved))
641 return i;
642
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300643 return -ENOSPC;
Avri Altman3edf8ff2014-07-30 11:41:01 +0300644}
645
Liad Kaufmancf961e12015-08-13 19:16:08 +0300646int iwl_mvm_reconfig_scd(struct iwl_mvm *mvm, int queue, int fifo, int sta_id,
647 int tid, int frame_limit, u16 ssn)
648{
649 struct iwl_scd_txq_cfg_cmd cmd = {
650 .scd_queue = queue,
Liad Kaufmanf7c692d2016-03-08 10:41:32 +0200651 .action = SCD_CFG_ENABLE_QUEUE,
Liad Kaufmancf961e12015-08-13 19:16:08 +0300652 .window = frame_limit,
653 .sta_id = sta_id,
654 .ssn = cpu_to_le16(ssn),
655 .tx_fifo = fifo,
656 .aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
657 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE),
658 .tid = tid,
659 };
660 int ret;
661
Sara Sharonbb497012016-09-29 14:52:40 +0300662 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
663 return -EINVAL;
664
Liad Kaufmancf961e12015-08-13 19:16:08 +0300665 spin_lock_bh(&mvm->queue_info_lock);
666 if (WARN(mvm->queue_info[queue].hw_queue_refcount == 0,
667 "Trying to reconfig unallocated queue %d\n", queue)) {
668 spin_unlock_bh(&mvm->queue_info_lock);
669 return -ENXIO;
670 }
671 spin_unlock_bh(&mvm->queue_info_lock);
672
673 IWL_DEBUG_TX_QUEUES(mvm, "Reconfig SCD for TXQ #%d\n", queue);
674
675 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
676 WARN_ONCE(ret, "Failed to re-configure queue %d on FIFO %d, ret=%d\n",
677 queue, fifo, ret);
678
679 return ret;
680}
681
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200682static bool iwl_mvm_update_txq_mapping(struct iwl_mvm *mvm, int queue,
683 int mac80211_queue, u8 sta_id, u8 tid)
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300684{
685 bool enable_queue = true;
686
687 spin_lock_bh(&mvm->queue_info_lock);
688
689 /* Make sure this TID isn't already enabled */
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200690 if (mvm->queue_info[queue].tid_bitmap & BIT(tid)) {
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300691 spin_unlock_bh(&mvm->queue_info_lock);
Liad Kaufmandf88c082016-11-24 15:31:00 +0200692 IWL_ERR(mvm, "Trying to enable TXQ %d with existing TID %d\n",
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200693 queue, tid);
694 return false;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300695 }
696
697 /* Update mappings and refcounts */
Liad Kaufman42db09c2016-05-02 14:01:14 +0300698 if (mvm->queue_info[queue].hw_queue_refcount > 0)
699 enable_queue = false;
700
Sara Sharon34e10862017-02-23 13:15:07 +0200701 mvm->hw_queue_to_mac80211[queue] |= BIT(mac80211_queue);
702
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300703 mvm->queue_info[queue].hw_queue_refcount++;
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200704 mvm->queue_info[queue].tid_bitmap |= BIT(tid);
705 mvm->queue_info[queue].ra_sta_id = sta_id;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300706
Liad Kaufman42db09c2016-05-02 14:01:14 +0300707 if (enable_queue) {
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200708 if (tid != IWL_MAX_TID_COUNT)
Liad Kaufman42db09c2016-05-02 14:01:14 +0300709 mvm->queue_info[queue].mac80211_ac =
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200710 tid_to_mac80211_ac[tid];
Liad Kaufman42db09c2016-05-02 14:01:14 +0300711 else
712 mvm->queue_info[queue].mac80211_ac = IEEE80211_AC_VO;
Liad Kaufmanedbe9612016-02-02 15:43:32 +0200713
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200714 mvm->queue_info[queue].txq_tid = tid;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300715 }
716
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300717 IWL_DEBUG_TX_QUEUES(mvm,
718 "Enabling TXQ #%d refcount=%d (mac80211 map:0x%x)\n",
719 queue, mvm->queue_info[queue].hw_queue_refcount,
Sara Sharon34e10862017-02-23 13:15:07 +0200720 mvm->hw_queue_to_mac80211[queue]);
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300721
722 spin_unlock_bh(&mvm->queue_info_lock);
723
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200724 return enable_queue;
725}
726
Sara Sharon310181e2017-01-17 14:27:48 +0200727int iwl_mvm_tvqm_enable_txq(struct iwl_mvm *mvm, int mac80211_queue,
728 u8 sta_id, u8 tid, unsigned int timeout)
729{
730 struct iwl_tx_queue_cfg_cmd cmd = {
731 .flags = cpu_to_le16(TX_QUEUE_CFG_ENABLE_QUEUE),
732 .sta_id = sta_id,
733 .tid = tid,
734 };
735 int queue;
736
737 if (cmd.tid == IWL_MAX_TID_COUNT)
738 cmd.tid = IWL_MGMT_TID;
739 queue = iwl_trans_txq_alloc(mvm->trans, (void *)&cmd,
740 SCD_QUEUE_CFG, timeout);
741
742 if (queue < 0) {
743 IWL_DEBUG_TX_QUEUES(mvm,
744 "Failed allocating TXQ for sta %d tid %d, ret: %d\n",
745 sta_id, tid, queue);
746 return queue;
747 }
748
749 IWL_DEBUG_TX_QUEUES(mvm, "Enabling TXQ #%d for sta %d tid %d\n",
750 queue, sta_id, tid);
751
Sara Sharon34e10862017-02-23 13:15:07 +0200752 mvm->hw_queue_to_mac80211[queue] |= BIT(mac80211_queue);
753 IWL_DEBUG_TX_QUEUES(mvm,
754 "Enabling TXQ #%d (mac80211 map:0x%x)\n",
755 queue, mvm->hw_queue_to_mac80211[queue]);
Sara Sharon310181e2017-01-17 14:27:48 +0200756
757 return queue;
758}
759
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300760bool iwl_mvm_enable_txq(struct iwl_mvm *mvm, int queue, int mac80211_queue,
Sara Sharon87d0e1a2017-01-11 21:33:38 +0200761 u16 ssn, const struct iwl_trans_txq_scd_cfg *cfg,
762 unsigned int wdg_timeout)
763{
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300764 struct iwl_scd_txq_cfg_cmd cmd = {
765 .scd_queue = queue,
766 .action = SCD_CFG_ENABLE_QUEUE,
767 .window = cfg->frame_limit,
768 .sta_id = cfg->sta_id,
769 .ssn = cpu_to_le16(ssn),
770 .tx_fifo = cfg->fifo,
771 .aggregate = cfg->aggregate,
772 .tid = cfg->tid,
773 };
774 bool inc_ssn;
775
Sara Sharon310181e2017-01-17 14:27:48 +0200776 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300777 return false;
Sara Sharon310181e2017-01-17 14:27:48 +0200778
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300779 /* Send the enabling command if we need to */
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300780 if (!iwl_mvm_update_txq_mapping(mvm, queue, mac80211_queue,
781 cfg->sta_id, cfg->tid))
782 return false;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300783
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300784 inc_ssn = iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn,
785 NULL, wdg_timeout);
786 if (inc_ssn)
787 le16_add_cpu(&cmd.ssn, 1);
788
789 WARN(iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd),
790 "Failed to configure queue %d on FIFO %d\n", queue, cfg->fifo);
791
792 return inc_ssn;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300793}
794
Sara Sharoncf90da32016-11-07 15:22:28 +0200795int iwl_mvm_disable_txq(struct iwl_mvm *mvm, int queue, int mac80211_queue,
796 u8 tid, u8 flags)
Avri Altman3edf8ff2014-07-30 11:41:01 +0300797{
Sara Sharon310181e2017-01-17 14:27:48 +0200798 struct iwl_scd_txq_cfg_cmd cmd = {
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +0200799 .scd_queue = queue,
Liad Kaufmanf7c692d2016-03-08 10:41:32 +0200800 .action = SCD_CFG_DISABLE_QUEUE,
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +0200801 };
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300802 bool remove_mac_queue = true;
Sara Sharon34e10862017-02-23 13:15:07 +0200803 int ret;
804
805 if (iwl_mvm_has_new_tx_api(mvm)) {
806 spin_lock_bh(&mvm->queue_info_lock);
807 mvm->hw_queue_to_mac80211[queue] &= ~BIT(mac80211_queue);
808 spin_unlock_bh(&mvm->queue_info_lock);
809
810 iwl_trans_txq_free(mvm->trans, queue);
811
812 return 0;
813 }
Avri Altman3edf8ff2014-07-30 11:41:01 +0300814
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300815 spin_lock_bh(&mvm->queue_info_lock);
816
817 if (WARN_ON(mvm->queue_info[queue].hw_queue_refcount == 0)) {
818 spin_unlock_bh(&mvm->queue_info_lock);
Sara Sharoncf90da32016-11-07 15:22:28 +0200819 return 0;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300820 }
821
822 mvm->queue_info[queue].tid_bitmap &= ~BIT(tid);
823
824 /*
825 * If there is another TID with the same AC - don't remove the MAC queue
826 * from the mapping
827 */
828 if (tid < IWL_MAX_TID_COUNT) {
829 unsigned long tid_bitmap =
830 mvm->queue_info[queue].tid_bitmap;
831 int ac = tid_to_mac80211_ac[tid];
832 int i;
833
834 for_each_set_bit(i, &tid_bitmap, IWL_MAX_TID_COUNT) {
835 if (tid_to_mac80211_ac[i] == ac)
836 remove_mac_queue = false;
837 }
838 }
839
840 if (remove_mac_queue)
Sara Sharon34e10862017-02-23 13:15:07 +0200841 mvm->hw_queue_to_mac80211[queue] &=
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300842 ~BIT(mac80211_queue);
843 mvm->queue_info[queue].hw_queue_refcount--;
844
Liad Kaufmanf7c692d2016-03-08 10:41:32 +0200845 cmd.action = mvm->queue_info[queue].hw_queue_refcount ?
846 SCD_CFG_ENABLE_QUEUE : SCD_CFG_DISABLE_QUEUE;
847 if (cmd.action == SCD_CFG_DISABLE_QUEUE)
Liad Kaufmancf961e12015-08-13 19:16:08 +0300848 mvm->queue_info[queue].status = IWL_MVM_QUEUE_FREE;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300849
850 IWL_DEBUG_TX_QUEUES(mvm,
851 "Disabling TXQ #%d refcount=%d (mac80211 map:0x%x)\n",
852 queue,
853 mvm->queue_info[queue].hw_queue_refcount,
Sara Sharon34e10862017-02-23 13:15:07 +0200854 mvm->hw_queue_to_mac80211[queue]);
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300855
856 /* If the queue is still enabled - nothing left to do in this func */
Liad Kaufmanf7c692d2016-03-08 10:41:32 +0200857 if (cmd.action == SCD_CFG_ENABLE_QUEUE) {
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300858 spin_unlock_bh(&mvm->queue_info_lock);
Sara Sharoncf90da32016-11-07 15:22:28 +0200859 return 0;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300860 }
861
Liad Kaufmanf02669b2016-02-28 16:15:07 +0200862 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
Liad Kaufmanedbe9612016-02-02 15:43:32 +0200863 cmd.tid = mvm->queue_info[queue].txq_tid;
Liad Kaufmanf02669b2016-02-28 16:15:07 +0200864
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300865 /* Make sure queue info is correct even though we overwrite it */
866 WARN(mvm->queue_info[queue].hw_queue_refcount ||
867 mvm->queue_info[queue].tid_bitmap ||
Sara Sharon34e10862017-02-23 13:15:07 +0200868 mvm->hw_queue_to_mac80211[queue],
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300869 "TXQ #%d info out-of-sync - refcount=%d, mac map=0x%x, tid=0x%x\n",
870 queue, mvm->queue_info[queue].hw_queue_refcount,
Sara Sharon34e10862017-02-23 13:15:07 +0200871 mvm->hw_queue_to_mac80211[queue],
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300872 mvm->queue_info[queue].tid_bitmap);
873
874 /* If we are here - the queue is freed and we can zero out these vals */
875 mvm->queue_info[queue].hw_queue_refcount = 0;
876 mvm->queue_info[queue].tid_bitmap = 0;
Sara Sharon34e10862017-02-23 13:15:07 +0200877 mvm->hw_queue_to_mac80211[queue] = 0;
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300878
Liad Kaufman9794c642015-08-19 17:34:28 +0300879 /* Regardless if this is a reserved TXQ for a STA - mark it as false */
880 mvm->queue_info[queue].reserved = false;
881
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300882 spin_unlock_bh(&mvm->queue_info_lock);
883
Sara Sharon34e10862017-02-23 13:15:07 +0200884 iwl_trans_txq_disable(mvm->trans, queue, false);
885 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, flags,
886 sizeof(struct iwl_scd_txq_cfg_cmd), &cmd);
Sara Sharon310181e2017-01-17 14:27:48 +0200887
Sara Sharon34e10862017-02-23 13:15:07 +0200888 if (ret)
889 IWL_ERR(mvm, "Failed to disable queue %d (ret=%d)\n",
890 queue, ret);
891 return ret;
Avri Altman3edf8ff2014-07-30 11:41:01 +0300892}
893
Johannes Berg8ca151b2013-01-24 14:25:36 +0100894/**
895 * iwl_mvm_send_lq_cmd() - Send link quality command
896 * @init: This command is sent as part of station initialization right
897 * after station has been added.
898 *
899 * The link quality command is sent as the last step of station creation.
900 * This is the special case in which init is set and we call a callback in
901 * this case to clear the state indicating that station creation is in
902 * progress.
903 */
Eyal Shapira9e680942013-11-09 00:16:16 +0200904int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq, bool init)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100905{
906 struct iwl_host_cmd cmd = {
907 .id = LQ_CMD,
908 .len = { sizeof(struct iwl_lq_cmd), },
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300909 .flags = init ? 0 : CMD_ASYNC,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100910 .data = { lq, },
911 };
912
Sara Sharon0ae98812017-01-04 14:53:58 +0200913 if (WARN_ON(lq->sta_id == IWL_MVM_INVALID_STA))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100914 return -EINVAL;
915
Johannes Berg8ca151b2013-01-24 14:25:36 +0100916 return iwl_mvm_send_cmd(mvm, &cmd);
917}
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300918
919/**
Sara Sharon0d365ae2015-03-31 12:24:05 +0300920 * iwl_mvm_update_smps - Get a request to change the SMPS mode
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300921 * @req_type: The part of the driver who call for a change.
922 * @smps_requests: The request to change the SMPS mode.
923 *
924 * Get a requst to change the SMPS mode,
925 * and change it according to all other requests in the driver.
926 */
927void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
928 enum iwl_mvm_smps_type_request req_type,
929 enum ieee80211_smps_mode smps_request)
930{
931 struct iwl_mvm_vif *mvmvif;
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200932 enum ieee80211_smps_mode smps_mode;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300933 int i;
934
935 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach710e4d02013-11-28 15:25:21 +0200936
937 /* SMPS is irrelevant for NICs that don't have at least 2 RX antenna */
Moshe Harela0544272014-12-08 21:13:14 +0200938 if (num_of_ant(iwl_mvm_get_valid_rx_ant(mvm)) == 1)
Emmanuel Grumbach710e4d02013-11-28 15:25:21 +0200939 return;
940
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200941 if (vif->type == NL80211_IFTYPE_AP)
942 smps_mode = IEEE80211_SMPS_OFF;
943 else
944 smps_mode = IEEE80211_SMPS_AUTOMATIC;
945
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300946 mvmvif = iwl_mvm_vif_from_mac80211(vif);
947 mvmvif->smps_requests[req_type] = smps_request;
948 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
949 if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC) {
950 smps_mode = IEEE80211_SMPS_STATIC;
951 break;
952 }
953 if (mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
954 smps_mode = IEEE80211_SMPS_DYNAMIC;
955 }
956
957 ieee80211_request_smps(vif, smps_mode);
958}
Johannes Berga21d7bc2013-11-12 17:30:52 +0100959
Johannes Berg33cef922015-01-21 21:41:29 +0100960int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear)
Johannes Berg91a8bcd2015-01-14 18:12:41 +0100961{
Johannes Berg33cef922015-01-21 21:41:29 +0100962 struct iwl_statistics_cmd scmd = {
963 .flags = clear ? cpu_to_le32(IWL_STATISTICS_FLG_CLEAR) : 0,
964 };
Johannes Berg91a8bcd2015-01-14 18:12:41 +0100965 struct iwl_host_cmd cmd = {
966 .id = STATISTICS_CMD,
967 .len[0] = sizeof(scmd),
968 .data[0] = &scmd,
969 .flags = CMD_WANT_SKB,
970 };
971 int ret;
972
973 ret = iwl_mvm_send_cmd(mvm, &cmd);
974 if (ret)
975 return ret;
976
977 iwl_mvm_handle_rx_statistics(mvm, cmd.resp_pkt);
978 iwl_free_resp(&cmd);
979
Johannes Berg33cef922015-01-21 21:41:29 +0100980 if (clear)
981 iwl_mvm_accu_radio_stats(mvm);
982
Johannes Berg91a8bcd2015-01-14 18:12:41 +0100983 return 0;
984}
985
986void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm)
987{
988 mvm->accu_radio_stats.rx_time += mvm->radio_stats.rx_time;
989 mvm->accu_radio_stats.tx_time += mvm->radio_stats.tx_time;
990 mvm->accu_radio_stats.on_time_rf += mvm->radio_stats.on_time_rf;
991 mvm->accu_radio_stats.on_time_scan += mvm->radio_stats.on_time_scan;
992}
993
Emmanuel Grumbach5c904222014-05-18 09:16:45 +0300994static void iwl_mvm_diversity_iter(void *_data, u8 *mac,
995 struct ieee80211_vif *vif)
996{
997 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
998 bool *result = _data;
999 int i;
1000
1001 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++) {
1002 if (mvmvif->smps_requests[i] == IEEE80211_SMPS_STATIC ||
1003 mvmvif->smps_requests[i] == IEEE80211_SMPS_DYNAMIC)
1004 *result = false;
1005 }
1006}
1007
1008bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm)
1009{
1010 bool result = true;
1011
1012 lockdep_assert_held(&mvm->mutex);
1013
Moshe Harela0544272014-12-08 21:13:14 +02001014 if (num_of_ant(iwl_mvm_get_valid_rx_ant(mvm)) == 1)
Emmanuel Grumbach5c904222014-05-18 09:16:45 +03001015 return false;
1016
Eyal Shapirac93edc62014-12-31 19:30:15 +02001017 if (mvm->cfg->rx_with_siso_diversity)
Emmanuel Grumbach5c904222014-05-18 09:16:45 +03001018 return false;
1019
1020 ieee80211_iterate_active_interfaces_atomic(
1021 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1022 iwl_mvm_diversity_iter, &result);
1023
1024 return result;
1025}
1026
Johannes Berga21d7bc2013-11-12 17:30:52 +01001027int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Johannes Bergb525d082016-01-06 10:01:41 +01001028 bool prev)
Johannes Berga21d7bc2013-11-12 17:30:52 +01001029{
1030 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berge03f9bef2013-11-13 17:16:19 +01001031 int res;
Johannes Berga21d7bc2013-11-12 17:30:52 +01001032
1033 lockdep_assert_held(&mvm->mutex);
1034
Johannes Bergb525d082016-01-06 10:01:41 +01001035 if (iwl_mvm_vif_low_latency(mvmvif) == prev)
Johannes Berg3510aea2014-03-18 10:21:02 +01001036 return 0;
1037
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001038 res = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berge03f9bef2013-11-13 17:16:19 +01001039 if (res)
1040 return res;
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +02001041
1042 iwl_mvm_bt_coex_vif_change(mvm);
1043
Arik Nemtsov999609f2014-05-15 17:31:51 +03001044 return iwl_mvm_power_update_mac(mvm);
Johannes Berga21d7bc2013-11-12 17:30:52 +01001045}
Alexander Bondar50df8a32014-03-12 20:30:51 +02001046
1047static void iwl_mvm_ll_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
1048{
1049 bool *result = _data;
1050
1051 if (iwl_mvm_vif_low_latency(iwl_mvm_vif_from_mac80211(vif)))
1052 *result = true;
1053}
1054
1055bool iwl_mvm_low_latency(struct iwl_mvm *mvm)
1056{
1057 bool result = false;
1058
1059 ieee80211_iterate_active_interfaces_atomic(
1060 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1061 iwl_mvm_ll_iter, &result);
1062
1063 return result;
1064}
David Spinadelbd5e4742014-04-24 13:15:29 +03001065
Luciano Coelho7f549e22014-10-02 15:38:04 +03001066struct iwl_bss_iter_data {
1067 struct ieee80211_vif *vif;
1068 bool error;
1069};
1070
1071static void iwl_mvm_bss_iface_iterator(void *_data, u8 *mac,
1072 struct ieee80211_vif *vif)
1073{
1074 struct iwl_bss_iter_data *data = _data;
1075
1076 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
1077 return;
1078
1079 if (data->vif) {
1080 data->error = true;
1081 return;
1082 }
1083
1084 data->vif = vif;
1085}
1086
1087struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm)
1088{
1089 struct iwl_bss_iter_data bss_iter_data = {};
1090
1091 ieee80211_iterate_active_interfaces_atomic(
1092 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1093 iwl_mvm_bss_iface_iterator, &bss_iter_data);
1094
1095 if (bss_iter_data.error) {
1096 IWL_ERR(mvm, "More than one managed interface active!\n");
1097 return ERR_PTR(-EINVAL);
1098 }
1099
1100 return bss_iter_data.vif;
1101}
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +02001102
Haim Dreyfussd4a7e7082017-02-02 14:49:50 +02001103struct iwl_sta_iter_data {
1104 bool assoc;
1105};
1106
1107static void iwl_mvm_sta_iface_iterator(void *_data, u8 *mac,
1108 struct ieee80211_vif *vif)
1109{
1110 struct iwl_sta_iter_data *data = _data;
1111
1112 if (vif->type != NL80211_IFTYPE_STATION)
1113 return;
1114
1115 if (vif->bss_conf.assoc)
1116 data->assoc = true;
1117}
1118
1119bool iwl_mvm_is_vif_assoc(struct iwl_mvm *mvm)
1120{
1121 struct iwl_sta_iter_data data = {
1122 .assoc = false,
1123 };
1124
1125 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1126 IEEE80211_IFACE_ITER_NORMAL,
1127 iwl_mvm_sta_iface_iterator,
1128 &data);
1129 return data.assoc;
1130}
1131
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +02001132unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
1133 struct ieee80211_vif *vif,
1134 bool tdls, bool cmd_q)
1135{
1136 struct iwl_fw_dbg_trigger_tlv *trigger;
1137 struct iwl_fw_dbg_trigger_txq_timer *txq_timer;
1138 unsigned int default_timeout =
1139 cmd_q ? IWL_DEF_WD_TIMEOUT : mvm->cfg->base_params->wd_timeout;
1140
1141 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TXQ_TIMERS))
1142 return iwlmvm_mod_params.tfd_q_hang_detect ?
1143 default_timeout : IWL_WATCHDOG_DISABLED;
1144
1145 trigger = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TXQ_TIMERS);
1146 txq_timer = (void *)trigger->data;
1147
1148 if (tdls)
1149 return le32_to_cpu(txq_timer->tdls);
1150
1151 if (cmd_q)
1152 return le32_to_cpu(txq_timer->command_queue);
1153
1154 if (WARN_ON(!vif))
1155 return default_timeout;
1156
1157 switch (ieee80211_vif_type_p2p(vif)) {
1158 case NL80211_IFTYPE_ADHOC:
1159 return le32_to_cpu(txq_timer->ibss);
1160 case NL80211_IFTYPE_STATION:
1161 return le32_to_cpu(txq_timer->bss);
1162 case NL80211_IFTYPE_AP:
1163 return le32_to_cpu(txq_timer->softap);
1164 case NL80211_IFTYPE_P2P_CLIENT:
1165 return le32_to_cpu(txq_timer->p2p_client);
1166 case NL80211_IFTYPE_P2P_GO:
1167 return le32_to_cpu(txq_timer->p2p_go);
1168 case NL80211_IFTYPE_P2P_DEVICE:
1169 return le32_to_cpu(txq_timer->p2p_device);
1170 default:
1171 WARN_ON(1);
1172 return mvm->cfg->base_params->wd_timeout;
1173 }
1174}
Emmanuel Grumbach31755202015-03-30 10:55:57 +03001175
1176void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1177 const char *errmsg)
1178{
1179 struct iwl_fw_dbg_trigger_tlv *trig;
1180 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
1181
1182 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
1183 goto out;
1184
1185 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
1186 trig_mlme = (void *)trig->data;
1187 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
1188 goto out;
1189
1190 if (trig_mlme->stop_connection_loss &&
1191 --trig_mlme->stop_connection_loss)
1192 goto out;
1193
1194 iwl_mvm_fw_dbg_collect_trig(mvm, trig, "%s", errmsg);
1195
1196out:
1197 ieee80211_connection_loss(vif);
1198}
Aviya Erenfeld03098262016-02-18 14:09:33 +02001199
Liad Kaufman9794c642015-08-19 17:34:28 +03001200/*
1201 * Remove inactive TIDs of a given queue.
1202 * If all queue TIDs are inactive - mark the queue as inactive
1203 * If only some the queue TIDs are inactive - unmap them from the queue
1204 */
1205static void iwl_mvm_remove_inactive_tids(struct iwl_mvm *mvm,
1206 struct iwl_mvm_sta *mvmsta, int queue,
1207 unsigned long tid_bitmap)
1208{
1209 int tid;
1210
1211 lockdep_assert_held(&mvmsta->lock);
1212 lockdep_assert_held(&mvm->queue_info_lock);
1213
Sara Sharonbb497012016-09-29 14:52:40 +03001214 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
1215 return;
1216
Liad Kaufman9794c642015-08-19 17:34:28 +03001217 /* Go over all non-active TIDs, incl. IWL_MAX_TID_COUNT (for mgmt) */
1218 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1219 /* If some TFDs are still queued - don't mark TID as inactive */
Liad Kaufmandd321622017-04-05 16:25:11 +03001220 if (iwl_mvm_tid_queued(mvm, &mvmsta->tid_data[tid]))
Liad Kaufman9794c642015-08-19 17:34:28 +03001221 tid_bitmap &= ~BIT(tid);
Emmanuel Grumbach59df97f2017-05-07 13:31:55 +03001222
1223 /* Don't mark as inactive any TID that has an active BA */
1224 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF)
1225 tid_bitmap &= ~BIT(tid);
Liad Kaufman9794c642015-08-19 17:34:28 +03001226 }
1227
1228 /* If all TIDs in the queue are inactive - mark queue as inactive. */
1229 if (tid_bitmap == mvm->queue_info[queue].tid_bitmap) {
1230 mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
1231
1232 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1)
1233 mvmsta->tid_data[tid].is_tid_active = false;
1234
1235 IWL_DEBUG_TX_QUEUES(mvm, "Queue %d marked as inactive\n",
1236 queue);
1237 return;
1238 }
1239
1240 /*
1241 * If we are here, this is a shared queue and not all TIDs timed-out.
1242 * Remove the ones that did.
1243 */
1244 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1245 int mac_queue = mvmsta->vif->hw_queue[tid_to_mac80211_ac[tid]];
1246
Sara Sharon6862fce2017-02-22 19:34:17 +02001247 mvmsta->tid_data[tid].txq_id = IWL_MVM_INVALID_QUEUE;
Sara Sharon34e10862017-02-23 13:15:07 +02001248 mvm->hw_queue_to_mac80211[queue] &= ~BIT(mac_queue);
Liad Kaufman9794c642015-08-19 17:34:28 +03001249 mvm->queue_info[queue].hw_queue_refcount--;
1250 mvm->queue_info[queue].tid_bitmap &= ~BIT(tid);
1251 mvmsta->tid_data[tid].is_tid_active = false;
1252
1253 IWL_DEBUG_TX_QUEUES(mvm,
1254 "Removing inactive TID %d from shared Q:%d\n",
1255 tid, queue);
1256 }
1257
1258 IWL_DEBUG_TX_QUEUES(mvm,
1259 "TXQ #%d left with tid bitmap 0x%x\n", queue,
1260 mvm->queue_info[queue].tid_bitmap);
1261
1262 /*
1263 * There may be different TIDs with the same mac queues, so make
1264 * sure all TIDs have existing corresponding mac queues enabled
1265 */
1266 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
1267 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
Sara Sharon34e10862017-02-23 13:15:07 +02001268 mvm->hw_queue_to_mac80211[queue] |=
Liad Kaufman9794c642015-08-19 17:34:28 +03001269 BIT(mvmsta->vif->hw_queue[tid_to_mac80211_ac[tid]]);
1270 }
1271
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001272 /* If the queue is marked as shared - "unshare" it */
1273 if (mvm->queue_info[queue].hw_queue_refcount == 1 &&
1274 mvm->queue_info[queue].status == IWL_MVM_QUEUE_SHARED) {
1275 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RECONFIGURING;
1276 IWL_DEBUG_TX_QUEUES(mvm, "Marking Q:%d for reconfig\n",
1277 queue);
1278 }
Liad Kaufman9794c642015-08-19 17:34:28 +03001279}
1280
1281void iwl_mvm_inactivity_check(struct iwl_mvm *mvm)
1282{
1283 unsigned long timeout_queues_map = 0;
1284 unsigned long now = jiffies;
1285 int i;
1286
Sara Sharonbb497012016-09-29 14:52:40 +03001287 if (iwl_mvm_has_new_tx_api(mvm))
1288 return;
1289
Liad Kaufman9794c642015-08-19 17:34:28 +03001290 spin_lock_bh(&mvm->queue_info_lock);
1291 for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
1292 if (mvm->queue_info[i].hw_queue_refcount > 0)
1293 timeout_queues_map |= BIT(i);
1294 spin_unlock_bh(&mvm->queue_info_lock);
1295
1296 rcu_read_lock();
1297
1298 /*
1299 * If a queue time outs - mark it as INACTIVE (don't remove right away
1300 * if we don't have to.) This is an optimization in case traffic comes
1301 * later, and we don't HAVE to use a currently-inactive queue
1302 */
1303 for_each_set_bit(i, &timeout_queues_map, IWL_MAX_HW_QUEUES) {
1304 struct ieee80211_sta *sta;
1305 struct iwl_mvm_sta *mvmsta;
1306 u8 sta_id;
1307 int tid;
1308 unsigned long inactive_tid_bitmap = 0;
1309 unsigned long queue_tid_bitmap;
1310
1311 spin_lock_bh(&mvm->queue_info_lock);
1312 queue_tid_bitmap = mvm->queue_info[i].tid_bitmap;
1313
1314 /* If TXQ isn't in active use anyway - nothing to do here... */
Liad Kaufman42db09c2016-05-02 14:01:14 +03001315 if (mvm->queue_info[i].status != IWL_MVM_QUEUE_READY &&
1316 mvm->queue_info[i].status != IWL_MVM_QUEUE_SHARED) {
Liad Kaufman9794c642015-08-19 17:34:28 +03001317 spin_unlock_bh(&mvm->queue_info_lock);
1318 continue;
1319 }
1320
1321 /* Check to see if there are inactive TIDs on this queue */
1322 for_each_set_bit(tid, &queue_tid_bitmap,
1323 IWL_MAX_TID_COUNT + 1) {
1324 if (time_after(mvm->queue_info[i].last_frame_time[tid] +
1325 IWL_MVM_DQA_QUEUE_TIMEOUT, now))
1326 continue;
1327
1328 inactive_tid_bitmap |= BIT(tid);
1329 }
1330 spin_unlock_bh(&mvm->queue_info_lock);
1331
1332 /* If all TIDs are active - finish check on this queue */
1333 if (!inactive_tid_bitmap)
1334 continue;
1335
1336 /*
1337 * If we are here - the queue hadn't been served recently and is
1338 * in use
1339 */
1340
1341 sta_id = mvm->queue_info[i].ra_sta_id;
1342 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1343
1344 /*
1345 * If the STA doesn't exist anymore, it isn't an error. It could
1346 * be that it was removed since getting the queues, and in this
1347 * case it should've inactivated its queues anyway.
1348 */
1349 if (IS_ERR_OR_NULL(sta))
1350 continue;
1351
1352 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1353
1354 spin_lock_bh(&mvmsta->lock);
1355 spin_lock(&mvm->queue_info_lock);
1356 iwl_mvm_remove_inactive_tids(mvm, mvmsta, i,
1357 inactive_tid_bitmap);
1358 spin_unlock(&mvm->queue_info_lock);
1359 spin_unlock_bh(&mvmsta->lock);
1360 }
1361
1362 rcu_read_unlock();
1363}
1364
Roee Zamirb3bee582016-08-02 13:55:13 +03001365void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, u32 *gp2, u64 *boottime)
1366{
1367 bool ps_disabled;
1368
1369 lockdep_assert_held(&mvm->mutex);
1370
1371 /* Disable power save when reading GP2 */
1372 ps_disabled = mvm->ps_disabled;
1373 if (!ps_disabled) {
1374 mvm->ps_disabled = true;
1375 iwl_mvm_power_update_device(mvm);
1376 }
1377
1378 *gp2 = iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG);
1379 *boottime = ktime_get_boot_ns();
1380
1381 if (!ps_disabled) {
1382 mvm->ps_disabled = ps_disabled;
1383 iwl_mvm_power_update_device(mvm);
1384 }
1385}
1386
Aviya Erenfeld03098262016-02-18 14:09:33 +02001387int iwl_mvm_send_lqm_cmd(struct ieee80211_vif *vif,
1388 enum iwl_lqm_cmd_operatrions operation,
1389 u32 duration, u32 timeout)
1390{
1391 struct iwl_mvm_vif *mvm_vif = iwl_mvm_vif_from_mac80211(vif);
1392 struct iwl_link_qual_msrmnt_cmd cmd = {
1393 .cmd_operation = cpu_to_le32(operation),
1394 .mac_id = cpu_to_le32(mvm_vif->id),
1395 .measurement_time = cpu_to_le32(duration),
1396 .timeout = cpu_to_le32(timeout),
1397 };
1398 u32 cmdid =
1399 iwl_cmd_id(LINK_QUALITY_MEASUREMENT_CMD, MAC_CONF_GROUP, 0);
1400 int ret;
1401
1402 if (!fw_has_capa(&mvm_vif->mvm->fw->ucode_capa,
1403 IWL_UCODE_TLV_CAPA_LQM_SUPPORT))
1404 return -EOPNOTSUPP;
1405
1406 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
1407 return -EINVAL;
1408
1409 switch (operation) {
1410 case LQM_CMD_OPERATION_START_MEASUREMENT:
1411 if (iwl_mvm_lqm_active(mvm_vif->mvm))
1412 return -EBUSY;
1413 if (!vif->bss_conf.assoc)
1414 return -EINVAL;
1415 mvm_vif->lqm_active = true;
1416 break;
1417 case LQM_CMD_OPERATION_STOP_MEASUREMENT:
1418 if (!iwl_mvm_lqm_active(mvm_vif->mvm))
1419 return -EINVAL;
1420 break;
1421 default:
1422 return -EINVAL;
1423 }
1424
1425 ret = iwl_mvm_send_cmd_pdu(mvm_vif->mvm, cmdid, 0, sizeof(cmd),
1426 &cmd);
1427
1428 /* command failed - roll back lqm_active state */
1429 if (ret) {
1430 mvm_vif->lqm_active =
1431 operation == LQM_CMD_OPERATION_STOP_MEASUREMENT;
1432 }
1433
1434 return ret;
1435}
1436
1437static void iwl_mvm_lqm_active_iterator(void *_data, u8 *mac,
1438 struct ieee80211_vif *vif)
1439{
1440 struct iwl_mvm_vif *mvm_vif = iwl_mvm_vif_from_mac80211(vif);
1441 bool *lqm_active = _data;
1442
1443 *lqm_active = *lqm_active || mvm_vif->lqm_active;
1444}
1445
1446bool iwl_mvm_lqm_active(struct iwl_mvm *mvm)
1447{
1448 bool ret = false;
1449
1450 lockdep_assert_held(&mvm->mutex);
1451 ieee80211_iterate_active_interfaces_atomic(
1452 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1453 iwl_mvm_lqm_active_iterator, &ret);
1454
1455 return ret;
1456}