iwlwifi: mvm: add support for negative temperatures
[deliverable/linux.git] / drivers / net / wireless / intel / iwlwifi / mvm / ops.c
CommitLineData
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.
4fb06283 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
8ca151b5
JB
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
410dc5aa 26 * in the file called COPYING.
8ca151b5
JB
27 *
28 * Contact Information:
cb2f8277 29 * Intel Linux Wireless <linuxwifi@intel.com>
8ca151b5
JB
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
51368bf7 34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
4fb06283 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
8ca151b5
JB
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <linux/module.h>
1bd3cbc1 66#include <linux/vmalloc.h>
8ca151b5
JB
67#include <net/mac80211.h>
68
69#include "iwl-notif-wait.h"
70#include "iwl-trans.h"
71#include "iwl-op-mode.h"
72#include "iwl-fw.h"
73#include "iwl-debug.h"
74#include "iwl-drv.h"
75#include "iwl-modparams.h"
76#include "mvm.h"
77#include "iwl-phy-db.h"
78#include "iwl-eeprom-parse.h"
79#include "iwl-csr.h"
80#include "iwl-io.h"
81#include "iwl-prph.h"
82#include "rs.h"
83#include "fw-api-scan.h"
84#include "time-event.h"
2f89a5d7 85#include "fw-dbg.h"
39bdb17e
SD
86#include "fw-api.h"
87#include "fw-api-scan.h"
8ca151b5 88
8ca151b5 89#define DRV_DESCRIPTION "The new Intel(R) wireless AGN driver for Linux"
8ca151b5 90MODULE_DESCRIPTION(DRV_DESCRIPTION);
8ca151b5
JB
91MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
92MODULE_LICENSE("GPL");
93
94static const struct iwl_op_mode_ops iwl_mvm_ops;
0316d30e 95static const struct iwl_op_mode_ops iwl_mvm_ops_mq;
8ca151b5
JB
96
97struct iwl_mvm_mod_params iwlmvm_mod_params = {
98 .power_scheme = IWL_POWER_SCHEME_BPS,
ce71c2f7 99 .tfd_q_hang_detect = true
8ca151b5
JB
100 /* rest of fields are 0 by default */
101};
102
103module_param_named(init_dbg, iwlmvm_mod_params.init_dbg, bool, S_IRUGO);
104MODULE_PARM_DESC(init_dbg,
105 "set to true to debug an ASSERT in INIT fw (default: false");
106module_param_named(power_scheme, iwlmvm_mod_params.power_scheme, int, S_IRUGO);
107MODULE_PARM_DESC(power_scheme,
108 "power management scheme: 1-active, 2-balanced, 3-low power, default: 2");
ce71c2f7
EG
109module_param_named(tfd_q_hang_detect, iwlmvm_mod_params.tfd_q_hang_detect,
110 bool, S_IRUGO);
111MODULE_PARM_DESC(tfd_q_hang_detect,
112 "TFD queues hang detection (default: true");
8ca151b5
JB
113
114/*
115 * module init and exit functions
116 */
117static int __init iwl_mvm_init(void)
118{
119 int ret;
120
121 ret = iwl_mvm_rate_control_register();
122 if (ret) {
123 pr_err("Unable to register rate control algorithm: %d\n", ret);
124 return ret;
125 }
126
127 ret = iwl_opmode_register("iwlmvm", &iwl_mvm_ops);
128
129 if (ret) {
130 pr_err("Unable to register MVM op_mode: %d\n", ret);
131 iwl_mvm_rate_control_unregister();
132 }
133
134 return ret;
135}
136module_init(iwl_mvm_init);
137
138static void __exit iwl_mvm_exit(void)
139{
140 iwl_opmode_deregister("iwlmvm");
141 iwl_mvm_rate_control_unregister();
142}
143module_exit(iwl_mvm_exit);
144
145static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode)
146{
147 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
148 u8 radio_cfg_type, radio_cfg_step, radio_cfg_dash;
149 u32 reg_val = 0;
a0544272
MH
150 u32 phy_config = iwl_mvm_get_phy_config(mvm);
151
152 radio_cfg_type = (phy_config & FW_PHY_CFG_RADIO_TYPE) >>
153 FW_PHY_CFG_RADIO_TYPE_POS;
154 radio_cfg_step = (phy_config & FW_PHY_CFG_RADIO_STEP) >>
155 FW_PHY_CFG_RADIO_STEP_POS;
156 radio_cfg_dash = (phy_config & FW_PHY_CFG_RADIO_DASH) >>
157 FW_PHY_CFG_RADIO_DASH_POS;
8ca151b5
JB
158
159 /* SKU control */
160 reg_val |= CSR_HW_REV_STEP(mvm->trans->hw_rev) <<
161 CSR_HW_IF_CONFIG_REG_POS_MAC_STEP;
162 reg_val |= CSR_HW_REV_DASH(mvm->trans->hw_rev) <<
163 CSR_HW_IF_CONFIG_REG_POS_MAC_DASH;
164
165 /* radio configuration */
166 reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE;
167 reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP;
168 reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
169
170 WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) &
171 ~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE);
172
9b1fcc11
LK
173 /*
174 * TODO: Bits 7-8 of CSR in 8000 HW family set the ADC sampling, and
175 * shouldn't be set to any non-zero value. The same is supposed to be
176 * true of the other HW, but unsetting them (such as the 7260) causes
177 * automatic tests to fail on seemingly unrelated errors. Need to
178 * further investigate this, but for now we'll separate cases.
179 */
180 if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
181 reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI;
8ca151b5 182
e139dc4a
LE
183 iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG,
184 CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
185 CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP |
186 CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
187 CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
188 CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH |
189 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
190 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI,
191 reg_val);
8ca151b5
JB
192
193 IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,
194 radio_cfg_step, radio_cfg_dash);
195
196 /*
197 * W/A : NIC is stuck in a reset state after Early PCIe power off
198 * (PCIe power is lost before PERST# is asserted), causing ME FW
199 * to lose ownership and not being able to obtain it back.
200 */
95411d04 201 if (!mvm->trans->cfg->apmg_not_supported)
3073d8c0
EH
202 iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG,
203 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
204 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
8ca151b5
JB
205}
206
207struct iwl_rx_handlers {
1230b16b 208 u16 cmd_id;
8ca151b5 209 bool async;
0416841d 210 void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
8ca151b5
JB
211};
212
213#define RX_HANDLER(_cmd_id, _fn, _async) \
214 { .cmd_id = _cmd_id , .fn = _fn , .async = _async }
1230b16b
AS
215#define RX_HANDLER_GRP(_grp, _cmd, _fn, _async) \
216 { .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .async = _async }
8ca151b5
JB
217
218/*
219 * Handlers for fw notifications
220 * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME
221 * This list should be in order of frequency for performance purposes.
222 *
223 * The handler can be SYNC - this means that it will be called in the Rx path
224 * which can't acquire mvm->mutex. If the handler needs to hold mvm->mutex (and
225 * only in this case!), it should be set as ASYNC. In that case, it will be
226 * called from a worker with mvm->mutex held.
227 */
228static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {
8ca151b5
JB
229 RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, false),
230 RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, false),
8ca151b5 231
f421f9c3 232 RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif, true),
bd3398e2 233 RX_HANDLER(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif, true),
9ee718aa 234 RX_HANDLER(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics, true),
b9fae2d5
EG
235 RX_HANDLER(ANTENNA_COUPLING_NOTIFICATION,
236 iwl_mvm_rx_ant_coupling_notif, true),
f421f9c3 237
497b49d2 238 RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif, false),
8ba2d7a1 239 RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc, true),
497b49d2 240
3e56eadf
JB
241 RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, false),
242
e5d74646 243 RX_HANDLER(SCAN_ITERATION_COMPLETE,
6e56f01d 244 iwl_mvm_rx_lmac_scan_iter_complete_notif, false),
35a000b7 245 RX_HANDLER(SCAN_OFFLOAD_COMPLETE,
6e56f01d
LC
246 iwl_mvm_rx_lmac_scan_complete_notif, true),
247 RX_HANDLER(MATCH_FOUND_NOTIFICATION, iwl_mvm_rx_scan_match_found,
35a000b7 248 false),
d2496221
DS
249 RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif,
250 true),
ee9219b2
AS
251 RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC,
252 iwl_mvm_rx_umac_scan_iter_complete_notif, false),
497b49d2 253
8ca151b5
JB
254 RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif, false),
255
d64048ed
HG
256 RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif,
257 false),
258
8ca151b5 259 RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, false),
175a70b7
AB
260 RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION,
261 iwl_mvm_power_uapsd_misbehaving_ap_notif, false),
ea9af24d 262 RX_HANDLER(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif, true),
09eef330
AE
263 RX_HANDLER_GRP(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE,
264 iwl_mvm_temp_notif, true),
ea9af24d 265
1d3c3f63
AN
266 RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif,
267 true),
30269c12 268 RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif, false),
ce792918 269 RX_HANDLER(TOF_NOTIFICATION, iwl_mvm_tof_resp_handler, true),
1d3c3f63 270
8ca151b5
JB
271};
272#undef RX_HANDLER
1230b16b 273#undef RX_HANDLER_GRP
39bdb17e
SD
274
275/* Please keep this array *SORTED* by hex value.
276 * Access is done through binary search
277 */
278static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {
279 HCMD_NAME(MVM_ALIVE),
280 HCMD_NAME(REPLY_ERROR),
281 HCMD_NAME(ECHO_CMD),
282 HCMD_NAME(INIT_COMPLETE_NOTIF),
283 HCMD_NAME(PHY_CONTEXT_CMD),
284 HCMD_NAME(DBG_CFG),
285 HCMD_NAME(ANTENNA_COUPLING_NOTIFICATION),
286 HCMD_NAME(SCAN_CFG_CMD),
287 HCMD_NAME(SCAN_REQ_UMAC),
288 HCMD_NAME(SCAN_ABORT_UMAC),
289 HCMD_NAME(SCAN_COMPLETE_UMAC),
290 HCMD_NAME(TOF_CMD),
291 HCMD_NAME(TOF_NOTIFICATION),
292 HCMD_NAME(ADD_STA_KEY),
293 HCMD_NAME(ADD_STA),
294 HCMD_NAME(REMOVE_STA),
295 HCMD_NAME(FW_GET_ITEM_CMD),
296 HCMD_NAME(TX_CMD),
297 HCMD_NAME(SCD_QUEUE_CFG),
298 HCMD_NAME(TXPATH_FLUSH),
299 HCMD_NAME(MGMT_MCAST_KEY),
300 HCMD_NAME(WEP_KEY),
301 HCMD_NAME(SHARED_MEM_CFG),
302 HCMD_NAME(TDLS_CHANNEL_SWITCH_CMD),
303 HCMD_NAME(MAC_CONTEXT_CMD),
304 HCMD_NAME(TIME_EVENT_CMD),
305 HCMD_NAME(TIME_EVENT_NOTIFICATION),
306 HCMD_NAME(BINDING_CONTEXT_CMD),
307 HCMD_NAME(TIME_QUOTA_CMD),
308 HCMD_NAME(NON_QOS_TX_COUNTER_CMD),
309 HCMD_NAME(LQ_CMD),
310 HCMD_NAME(FW_PAGING_BLOCK_CMD),
311 HCMD_NAME(SCAN_OFFLOAD_REQUEST_CMD),
312 HCMD_NAME(SCAN_OFFLOAD_ABORT_CMD),
313 HCMD_NAME(HOT_SPOT_CMD),
314 HCMD_NAME(SCAN_OFFLOAD_PROFILES_QUERY_CMD),
315 HCMD_NAME(SCAN_OFFLOAD_HOTSPOTS_CONFIG_CMD),
316 HCMD_NAME(SCAN_OFFLOAD_HOTSPOTS_QUERY_CMD),
317 HCMD_NAME(BT_COEX_UPDATE_SW_BOOST),
318 HCMD_NAME(BT_COEX_UPDATE_CORUN_LUT),
319 HCMD_NAME(BT_COEX_UPDATE_REDUCED_TXP),
320 HCMD_NAME(BT_COEX_CI),
321 HCMD_NAME(PHY_CONFIGURATION_CMD),
322 HCMD_NAME(CALIB_RES_NOTIF_PHY_DB),
323 HCMD_NAME(SCAN_OFFLOAD_COMPLETE),
324 HCMD_NAME(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),
325 HCMD_NAME(SCAN_OFFLOAD_CONFIG_CMD),
326 HCMD_NAME(POWER_TABLE_CMD),
327 HCMD_NAME(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION),
328 HCMD_NAME(REPLY_THERMAL_MNG_BACKOFF),
329 HCMD_NAME(DC2DC_CONFIG_CMD),
330 HCMD_NAME(NVM_ACCESS_CMD),
331 HCMD_NAME(SET_CALIB_DEFAULT_CMD),
332 HCMD_NAME(BEACON_NOTIFICATION),
333 HCMD_NAME(BEACON_TEMPLATE_CMD),
334 HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
335 HCMD_NAME(BT_CONFIG),
336 HCMD_NAME(STATISTICS_CMD),
337 HCMD_NAME(STATISTICS_NOTIFICATION),
338 HCMD_NAME(EOSP_NOTIFICATION),
339 HCMD_NAME(REDUCE_TX_POWER_CMD),
340 HCMD_NAME(CARD_STATE_CMD),
341 HCMD_NAME(CARD_STATE_NOTIFICATION),
342 HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
343 HCMD_NAME(TDLS_CONFIG_CMD),
344 HCMD_NAME(MAC_PM_POWER_TABLE),
345 HCMD_NAME(TDLS_CHANNEL_SWITCH_NOTIFICATION),
346 HCMD_NAME(MFUART_LOAD_NOTIFICATION),
347 HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC),
348 HCMD_NAME(REPLY_RX_PHY_CMD),
349 HCMD_NAME(REPLY_RX_MPDU_CMD),
350 HCMD_NAME(BA_NOTIF),
351 HCMD_NAME(MCC_UPDATE_CMD),
352 HCMD_NAME(MCC_CHUB_UPDATE_CMD),
353 HCMD_NAME(MARKER_CMD),
354 HCMD_NAME(BT_COEX_PRIO_TABLE),
355 HCMD_NAME(BT_COEX_PROT_ENV),
356 HCMD_NAME(BT_PROFILE_NOTIFICATION),
357 HCMD_NAME(BCAST_FILTER_CMD),
358 HCMD_NAME(MCAST_FILTER_CMD),
359 HCMD_NAME(REPLY_SF_CFG_CMD),
360 HCMD_NAME(REPLY_BEACON_FILTERING_CMD),
361 HCMD_NAME(D3_CONFIG_CMD),
362 HCMD_NAME(PROT_OFFLOAD_CONFIG_CMD),
363 HCMD_NAME(OFFLOADS_QUERY_CMD),
364 HCMD_NAME(REMOTE_WAKE_CONFIG_CMD),
365 HCMD_NAME(MATCH_FOUND_NOTIFICATION),
366 HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER),
367 HCMD_NAME(DTS_MEASUREMENT_NOTIFICATION),
368 HCMD_NAME(WOWLAN_PATTERNS),
369 HCMD_NAME(WOWLAN_CONFIGURATION),
370 HCMD_NAME(WOWLAN_TSC_RSC_PARAM),
371 HCMD_NAME(WOWLAN_TKIP_PARAM),
372 HCMD_NAME(WOWLAN_KEK_KCK_MATERIAL),
373 HCMD_NAME(WOWLAN_GET_STATUSES),
374 HCMD_NAME(WOWLAN_TX_POWER_PER_DB),
375 HCMD_NAME(SCAN_ITERATION_COMPLETE),
376 HCMD_NAME(D0I3_END_CMD),
377 HCMD_NAME(LTR_CONFIG),
378 HCMD_NAME(REPLY_DEBUG_CMD),
8ca151b5 379};
39bdb17e
SD
380
381/* Please keep this array *SORTED* by hex value.
382 * Access is done through binary search
383 */
384static const struct iwl_hcmd_names iwl_mvm_phy_names[] = {
385 HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE),
386 HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE),
387};
388
389static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
390 [LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
391 [LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
392 [PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names),
393};
394
8ca151b5
JB
395/* this forward declaration can avoid to export the function */
396static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
37577fe2 397static void iwl_mvm_d0i3_exit_work(struct work_struct *wk);
8ca151b5 398
0c0e2c71
IY
399static u32 calc_min_backoff(struct iwl_trans *trans, const struct iwl_cfg *cfg)
400{
401 const struct iwl_pwr_tx_backoff *pwr_tx_backoff = cfg->pwr_tx_backoffs;
402
403 if (!pwr_tx_backoff)
404 return 0;
405
406 while (pwr_tx_backoff->pwr) {
407 if (trans->dflt_pwr_limit >= pwr_tx_backoff->pwr)
408 return pwr_tx_backoff->backoff;
409
410 pwr_tx_backoff++;
411 }
412
413 return 0;
414}
415
4bfa47f3
EG
416static void iwl_mvm_fw_error_dump_wk(struct work_struct *work);
417
8ca151b5
JB
418static struct iwl_op_mode *
419iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
420 const struct iwl_fw *fw, struct dentry *dbgfs_dir)
421{
422 struct ieee80211_hw *hw;
423 struct iwl_op_mode *op_mode;
424 struct iwl_mvm *mvm;
425 struct iwl_trans_config trans_cfg = {};
426 static const u8 no_reclaim_cmds[] = {
427 TX_CMD,
428 };
429 int err, scan_size;
0c0e2c71 430 u32 min_backoff;
8ca151b5 431
c4d83271
EG
432 /*
433 * We use IWL_MVM_STATION_COUNT to check the validity of the station
434 * index all over the driver - check that its value corresponds to the
435 * array size.
436 */
437 BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) != IWL_MVM_STATION_COUNT);
438
8ca151b5
JB
439 /********************************
440 * 1. Allocating and configuring HW data
441 ********************************/
442 hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
443 sizeof(struct iwl_mvm),
444 &iwl_mvm_hw_ops);
445 if (!hw)
446 return NULL;
447
745160ee
OG
448 if (cfg->max_rx_agg_size)
449 hw->max_rx_aggregation_subframes = cfg->max_rx_agg_size;
450
77d96730
GG
451 if (cfg->max_tx_agg_size)
452 hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
453
8ca151b5 454 op_mode = hw->priv;
8ca151b5
JB
455
456 mvm = IWL_OP_MODE_GET_MVM(op_mode);
457 mvm->dev = trans->dev;
458 mvm->trans = trans;
459 mvm->cfg = cfg;
460 mvm->fw = fw;
461 mvm->hw = hw;
462
0316d30e
JB
463 if (iwl_mvm_has_new_rx_api(mvm)) {
464 op_mode->ops = &iwl_mvm_ops_mq;
465 } else {
466 op_mode->ops = &iwl_mvm_ops;
467
468 if (WARN_ON(trans->num_rx_queues > 1))
469 goto out_free;
470 }
471
291aa7c4
EH
472 mvm->restart_fw = iwlwifi_mod_params.restart_fw ? -1 : 0;
473
19e737c9
EL
474 mvm->aux_queue = 15;
475 mvm->first_agg_queue = 16;
476 mvm->last_agg_queue = mvm->cfg->base_params->num_of_queues - 1;
477 if (mvm->cfg->base_params->num_of_queues == 16) {
478 mvm->aux_queue = 11;
479 mvm->first_agg_queue = 12;
480 }
1f3b0ff8 481 mvm->sf_state = SF_UNINIT;
7b358f06 482 mvm->cur_ucode = IWL_UCODE_INIT;
19e737c9 483
8ca151b5 484 mutex_init(&mvm->mutex);
d15a747f 485 mutex_init(&mvm->d0i3_suspend_mutex);
8ca151b5
JB
486 spin_lock_init(&mvm->async_handlers_lock);
487 INIT_LIST_HEAD(&mvm->time_event_list);
b112889c 488 INIT_LIST_HEAD(&mvm->aux_roc_te_list);
8ca151b5
JB
489 INIT_LIST_HEAD(&mvm->async_handlers_list);
490 spin_lock_init(&mvm->time_event_lock);
4ecafae9 491 spin_lock_init(&mvm->queue_info_lock);
8ca151b5
JB
492
493 INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
494 INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
495 INIT_WORK(&mvm->sta_drained_wk, iwl_mvm_sta_drained_wk);
37577fe2 496 INIT_WORK(&mvm->d0i3_exit_work, iwl_mvm_d0i3_exit_work);
d2709ad7 497 INIT_DELAYED_WORK(&mvm->fw_dump_wk, iwl_mvm_fw_error_dump_wk);
1d3c3f63 498 INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
8ca151b5 499
b2492501 500 spin_lock_init(&mvm->d0i3_tx_lock);
576eeee9 501 spin_lock_init(&mvm->refs_lock);
b2492501
AN
502 skb_queue_head_init(&mvm->d0i3_tx);
503 init_waitqueue_head(&mvm->d0i3_exit_waitq);
504
8ca151b5
JB
505 SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
506
507 /*
508 * Populate the state variables that the transport layer needs
509 * to know about.
510 */
511 trans_cfg.op_mode = op_mode;
512 trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
513 trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
6c4fbcbc
EG
514 switch (iwlwifi_mod_params.amsdu_size) {
515 case IWL_AMSDU_4K:
516 trans_cfg.rx_buf_size = IWL_AMSDU_4K;
517 break;
518 case IWL_AMSDU_8K:
519 trans_cfg.rx_buf_size = IWL_AMSDU_8K;
520 break;
521 case IWL_AMSDU_12K:
522 trans_cfg.rx_buf_size = IWL_AMSDU_12K;
523 break;
524 default:
525 pr_err("%s: Unsupported amsdu_size: %d\n", KBUILD_MODNAME,
526 iwlwifi_mod_params.amsdu_size);
527 trans_cfg.rx_buf_size = IWL_AMSDU_4K;
528 }
ab02165c
AE
529 trans_cfg.wide_cmd_header = fw_has_api(&mvm->fw->ucode_capa,
530 IWL_UCODE_TLV_API_WIDE_CMD_HDR);
8ca151b5 531
25b9ea5c 532 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DW_BC_TABLE)
8ca151b5
JB
533 trans_cfg.bc_table_dword = true;
534
39bdb17e
SD
535 trans_cfg.command_groups = iwl_mvm_groups;
536 trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);
8ca151b5
JB
537
538 trans_cfg.cmd_queue = IWL_MVM_CMD_QUEUE;
b2d81db7 539 trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
3a736bcb 540 trans_cfg.scd_set_active = true;
8ca151b5 541
b4821767 542 trans_cfg.sdio_adma_addr = fw->sdio_adma_addr;
41837ca9 543 trans_cfg.sw_csum_tx = IWL_MVM_SW_TX_CSUM_OFFLOAD;
b4821767 544
4cf677fd
EG
545 /* Set a short watchdog for the command queue */
546 trans_cfg.cmd_q_wdg_timeout =
5d42e7b2 547 iwl_mvm_get_wd_timeout(mvm, NULL, false, true);
4cf677fd 548
8ca151b5
JB
549 snprintf(mvm->hw->wiphy->fw_version,
550 sizeof(mvm->hw->wiphy->fw_version),
551 "%s", fw->fw_version);
552
553 /* Configure transport layer */
554 iwl_trans_configure(mvm->trans, &trans_cfg);
555
556 trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
557 trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
09e350f7
LK
558 trans->dbg_dest_tlv = mvm->fw->dbg_dest_tlv;
559 trans->dbg_dest_reg_num = mvm->fw->dbg_dest_reg_num;
560 memcpy(trans->dbg_conf_tlv, mvm->fw->dbg_conf_tlv,
561 sizeof(trans->dbg_conf_tlv));
d2709ad7 562 trans->dbg_trigger_tlv = mvm->fw->dbg_trigger_tlv;
8ca151b5
JB
563
564 /* set up notification wait support */
565 iwl_notification_wait_init(&mvm->notif_wait);
566
567 /* Init phy db */
568 mvm->phy_db = iwl_phy_db_init(trans);
569 if (!mvm->phy_db) {
570 IWL_ERR(mvm, "Cannot init phy_db\n");
571 goto out_free;
572 }
573
574 IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
575 mvm->cfg->name, mvm->trans->hw_rev);
576
0c0e2c71
IY
577 min_backoff = calc_min_backoff(trans, cfg);
578 iwl_mvm_tt_initialize(mvm, min_backoff);
4fb06283
EH
579
580 if (iwlwifi_mod_params.nvm_file)
e02a9d60 581 mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
4fb06283
EH
582 else
583 IWL_DEBUG_EEPROM(mvm->trans->dev,
584 "working without external nvm file\n");
9ee718aa 585
e02a9d60 586 if (WARN(cfg->no_power_up_nic_in_init && !mvm->nvm_file_name,
14b485f0
EH
587 "not allowing power-up and not having nvm_file\n"))
588 goto out_free;
589
81a67e32 590 /*
0ade579c 591 * Even if nvm exists in the nvm_file driver should read again the nvm
14b485f0
EH
592 * from the nic because there might be entries that exist in the OTP
593 * and not in the file.
594 * for nics with no_power_up_nic_in_init: rely completley on nvm_file
81a67e32 595 */
e02a9d60 596 if (cfg->no_power_up_nic_in_init && mvm->nvm_file_name) {
14b485f0 597 err = iwl_nvm_init(mvm, false);
8c678ed4
EP
598 if (err)
599 goto out_free;
81a67e32
EL
600 } else {
601 err = iwl_trans_start_hw(mvm->trans);
602 if (err)
603 goto out_free;
604
605 mutex_lock(&mvm->mutex);
08f0d23d 606 iwl_mvm_ref(mvm, IWL_MVM_REF_INIT_UCODE);
81a67e32 607 err = iwl_run_init_mvm_ucode(mvm, true);
b93b1fe3
LK
608 if (!err || !iwlmvm_mod_params.init_dbg)
609 iwl_trans_stop_device(trans);
08f0d23d 610 iwl_mvm_unref(mvm, IWL_MVM_REF_INIT_UCODE);
81a67e32
EL
611 mutex_unlock(&mvm->mutex);
612 /* returns 0 if successful, 1 if success but in rfkill */
613 if (err < 0 && !iwlmvm_mod_params.init_dbg) {
614 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", err);
615 goto out_free;
616 }
8ca151b5
JB
617 }
618
d2496221 619 scan_size = iwl_mvm_scan_size(mvm);
fb98be5e 620
8ca151b5
JB
621 mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
622 if (!mvm->scan_cmd)
623 goto out_free;
624
5a4b2afa
HD
625 /* Set EBS as successful as long as not stated otherwise by the FW. */
626 mvm->last_ebs_successful = true;
627
8ca151b5
JB
628 err = iwl_mvm_mac_setup_register(mvm);
629 if (err)
630 goto out_free;
631
632 err = iwl_mvm_dbgfs_register(mvm, dbgfs_dir);
633 if (err)
634 goto out_unregister;
635
3848ab66
MG
636 memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
637
a42b2af3
LC
638 /* rpm starts with a taken reference, we can release it now */
639 iwl_trans_unref(mvm->trans);
7498cf4c 640
ce792918
GG
641 iwl_mvm_tof_init(mvm);
642
8ca151b5
JB
643 return op_mode;
644
645 out_unregister:
646 ieee80211_unregister_hw(mvm->hw);
91b0d119 647 iwl_mvm_leds_exit(mvm);
8ca151b5 648 out_free:
dbf73d4a 649 flush_delayed_work(&mvm->fw_dump_wk);
8ca151b5
JB
650 iwl_phy_db_free(mvm->phy_db);
651 kfree(mvm->scan_cmd);
e02a9d60 652 if (!cfg->no_power_up_nic_in_init || !mvm->nvm_file_name)
a4082843 653 iwl_trans_op_mode_leave(trans);
8ca151b5
JB
654 ieee80211_free_hw(mvm->hw);
655 return NULL;
656}
657
658static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
659{
660 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
661 int i;
662
663 iwl_mvm_leds_exit(mvm);
664
9ee718aa
EL
665 iwl_mvm_tt_exit(mvm);
666
8ca151b5
JB
667 ieee80211_unregister_hw(mvm->hw);
668
669 kfree(mvm->scan_cmd);
e59647ea
EP
670 kfree(mvm->mcast_filter_cmd);
671 mvm->mcast_filter_cmd = NULL;
8ca151b5 672
afc66bb7
JB
673#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS)
674 kfree(mvm->d3_resume_sram);
675#endif
676
a4082843 677 iwl_trans_op_mode_leave(mvm->trans);
8ca151b5
JB
678
679 iwl_phy_db_free(mvm->phy_db);
680 mvm->phy_db = NULL;
681
8ca151b5 682 iwl_free_nvm_data(mvm->nvm_data);
ae2b21b0 683 for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
8ca151b5
JB
684 kfree(mvm->nvm_sections[i].data);
685
ce792918
GG
686 iwl_mvm_tof_clean(mvm);
687
8ca151b5
JB
688 ieee80211_free_hw(mvm->hw);
689}
690
691struct iwl_async_handler_entry {
692 struct list_head list;
693 struct iwl_rx_cmd_buffer rxb;
0416841d 694 void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
8ca151b5
JB
695};
696
697void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
698{
699 struct iwl_async_handler_entry *entry, *tmp;
700
701 spin_lock_bh(&mvm->async_handlers_lock);
702 list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
703 iwl_free_rxb(&entry->rxb);
704 list_del(&entry->list);
705 kfree(entry);
706 }
707 spin_unlock_bh(&mvm->async_handlers_lock);
708}
709
710static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
711{
712 struct iwl_mvm *mvm =
713 container_of(wk, struct iwl_mvm, async_handlers_wk);
714 struct iwl_async_handler_entry *entry, *tmp;
715 struct list_head local_list;
716
717 INIT_LIST_HEAD(&local_list);
718
719 /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
720 mutex_lock(&mvm->mutex);
721
722 /*
723 * Sync with Rx path with a lock. Remove all the entries from this list,
724 * add them to a local one (lock free), and then handle them.
725 */
726 spin_lock_bh(&mvm->async_handlers_lock);
727 list_splice_init(&mvm->async_handlers_list, &local_list);
728 spin_unlock_bh(&mvm->async_handlers_lock);
729
730 list_for_each_entry_safe(entry, tmp, &local_list, list) {
0416841d 731 entry->fn(mvm, &entry->rxb);
8ca151b5
JB
732 iwl_free_rxb(&entry->rxb);
733 list_del(&entry->list);
734 kfree(entry);
735 }
736 mutex_unlock(&mvm->mutex);
737}
738
917f39bb
EG
739static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
740 struct iwl_rx_packet *pkt)
741{
742 struct iwl_fw_dbg_trigger_tlv *trig;
743 struct iwl_fw_dbg_trigger_cmd *cmds_trig;
917f39bb
EG
744 int i;
745
746 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF))
747 return;
748
749 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF);
750 cmds_trig = (void *)trig->data;
751
752 if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
753 return;
754
755 for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {
756 /* don't collect on CMD 0 */
757 if (!cmds_trig->cmds[i].cmd_id)
758 break;
759
0ab66e6d
SS
760 if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||
761 cmds_trig->cmds[i].group_id != pkt->hdr.group_id)
917f39bb
EG
762 continue;
763
5d4f929e 764 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
0ab66e6d
SS
765 "CMD 0x%02x.%02x received",
766 pkt->hdr.group_id, pkt->hdr.cmd);
917f39bb
EG
767 break;
768 }
769}
770
0316d30e
JB
771static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
772 struct iwl_rx_cmd_buffer *rxb,
773 struct iwl_rx_packet *pkt)
8ca151b5 774{
0316d30e 775 int i;
1738d60b 776
917f39bb
EG
777 iwl_mvm_rx_check_trigger(mvm, pkt);
778
8ca151b5
JB
779 /*
780 * Do the notification wait before RX handlers so
781 * even if the RX handler consumes the RXB we have
782 * access to it in the notification wait entry.
783 */
784 iwl_notification_wait_notify(&mvm->notif_wait, pkt);
785
786 for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
787 const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
36eed56a
EG
788 struct iwl_async_handler_entry *entry;
789
1230b16b 790 if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
36eed56a
EG
791 continue;
792
0416841d
JB
793 if (!rx_h->async) {
794 rx_h->fn(mvm, rxb);
f7e6469f 795 return;
0416841d 796 }
36eed56a
EG
797
798 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
799 /* we can't do much... */
800 if (!entry)
f7e6469f 801 return;
36eed56a
EG
802
803 entry->rxb._page = rxb_steal_page(rxb);
804 entry->rxb._offset = rxb->_offset;
805 entry->rxb._rx_page_order = rxb->_rx_page_order;
806 entry->fn = rx_h->fn;
807 spin_lock(&mvm->async_handlers_lock);
808 list_add_tail(&entry->list, &mvm->async_handlers_list);
809 spin_unlock(&mvm->async_handlers_lock);
810 schedule_work(&mvm->async_handlers_wk);
811 break;
8ca151b5 812 }
8ca151b5
JB
813}
814
0316d30e
JB
815static void iwl_mvm_rx(struct iwl_op_mode *op_mode,
816 struct napi_struct *napi,
817 struct iwl_rx_cmd_buffer *rxb)
818{
819 struct iwl_rx_packet *pkt = rxb_addr(rxb);
820 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
821
822 if (likely(pkt->hdr.cmd == REPLY_RX_MPDU_CMD))
823 iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);
585a6fcc
SS
824 else if (pkt->hdr.cmd == FRAME_RELEASE)
825 iwl_mvm_rx_frame_release(mvm, rxb, 0);
0316d30e
JB
826 else if (pkt->hdr.cmd == REPLY_RX_PHY_CMD)
827 iwl_mvm_rx_rx_phy_cmd(mvm, rxb);
828 else
829 iwl_mvm_rx_common(mvm, rxb, pkt);
830}
831
832static void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
833 struct napi_struct *napi,
834 struct iwl_rx_cmd_buffer *rxb)
835{
836 struct iwl_rx_packet *pkt = rxb_addr(rxb);
837 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
838
839 if (likely(pkt->hdr.cmd == REPLY_RX_MPDU_CMD))
780e87c2 840 iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);
0316d30e 841 else if (pkt->hdr.cmd == REPLY_RX_PHY_CMD)
780e87c2 842 iwl_mvm_rx_phy_cmd_mq(mvm, rxb);
0316d30e
JB
843 else
844 iwl_mvm_rx_common(mvm, rxb, pkt);
845}
846
8ca151b5
JB
847static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
848{
849 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
4ecafae9
LK
850 unsigned long mq;
851 int q;
8ca151b5 852
4ecafae9
LK
853 spin_lock_bh(&mvm->queue_info_lock);
854 mq = mvm->queue_info[queue].hw_queue_to_mac80211;
855 spin_unlock_bh(&mvm->queue_info_lock);
8ca151b5 856
4ecafae9 857 if (WARN_ON_ONCE(!mq))
8ca151b5 858 return;
8ca151b5 859
4ecafae9
LK
860 for_each_set_bit(q, &mq, IEEE80211_MAX_QUEUES) {
861 if (atomic_inc_return(&mvm->mac80211_queue_stop_count[q]) > 1) {
862 IWL_DEBUG_TX_QUEUES(mvm,
863 "queue %d (mac80211 %d) already stopped\n",
864 queue, q);
865 continue;
866 }
867
868 ieee80211_stop_queue(mvm->hw, q);
869 }
8ca151b5
JB
870}
871
156f92f2
EG
872static void iwl_mvm_async_cb(struct iwl_op_mode *op_mode,
873 const struct iwl_device_cmd *cmd)
874{
875 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
876
877 /*
878 * For now, we only set the CMD_WANT_ASYNC_CALLBACK for ADD_STA
879 * commands that need to block the Tx queues.
880 */
881 iwl_trans_block_txq_ptrs(mvm->trans, false);
882}
883
8ca151b5
JB
884static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
885{
886 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
4ecafae9
LK
887 unsigned long mq;
888 int q;
8ca151b5 889
4ecafae9
LK
890 spin_lock_bh(&mvm->queue_info_lock);
891 mq = mvm->queue_info[queue].hw_queue_to_mac80211;
892 spin_unlock_bh(&mvm->queue_info_lock);
8ca151b5 893
4ecafae9 894 if (WARN_ON_ONCE(!mq))
8ca151b5 895 return;
8ca151b5 896
4ecafae9
LK
897 for_each_set_bit(q, &mq, IEEE80211_MAX_QUEUES) {
898 if (atomic_dec_return(&mvm->mac80211_queue_stop_count[q]) > 0) {
899 IWL_DEBUG_TX_QUEUES(mvm,
900 "queue %d (mac80211 %d) still stopped\n",
901 queue, q);
902 continue;
903 }
904
905 ieee80211_wake_queue(mvm->hw, q);
906 }
8ca151b5
JB
907}
908
9ee718aa
EL
909void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
910{
911 if (state)
912 set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
913 else
914 clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
915
916 wiphy_rfkill_set_hw_state(mvm->hw->wiphy, iwl_mvm_is_radio_killed(mvm));
917}
918
14cfca71 919static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
8ca151b5
JB
920{
921 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
31b8b343 922 bool calibrating = ACCESS_ONCE(mvm->calibrating);
8ca151b5
JB
923
924 if (state)
925 set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
926 else
927 clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
928
9ee718aa 929 wiphy_rfkill_set_hw_state(mvm->hw->wiphy, iwl_mvm_is_radio_killed(mvm));
14cfca71 930
31b8b343
EG
931 /* iwl_run_init_mvm_ucode is waiting for results, abort it */
932 if (calibrating)
933 iwl_abort_notification_waits(&mvm->notif_wait);
934
935 /*
936 * Stop the device if we run OPERATIONAL firmware or if we are in the
937 * middle of the calibrations.
938 */
939 return state && (mvm->cur_ucode != IWL_UCODE_INIT || calibrating);
8ca151b5
JB
940}
941
942static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
943{
944 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
945 struct ieee80211_tx_info *info;
946
947 info = IEEE80211_SKB_CB(skb);
948 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
949 ieee80211_free_txskb(mvm->hw, skb);
950}
951
ac1ed416
JB
952struct iwl_mvm_reprobe {
953 struct device *dev;
954 struct work_struct work;
955};
956
957static void iwl_mvm_reprobe_wk(struct work_struct *wk)
958{
959 struct iwl_mvm_reprobe *reprobe;
960
961 reprobe = container_of(wk, struct iwl_mvm_reprobe, work);
962 if (device_reprobe(reprobe->dev))
963 dev_err(reprobe->dev, "reprobe failed!\n");
964 kfree(reprobe);
965 module_put(THIS_MODULE);
966}
967
4bfa47f3
EG
968static void iwl_mvm_fw_error_dump_wk(struct work_struct *work)
969{
970 struct iwl_mvm *mvm =
d2709ad7 971 container_of(work, struct iwl_mvm, fw_dump_wk.work);
4bfa47f3 972
fb2380a2
LK
973 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_FW_DBG_COLLECT))
974 return;
975
4bfa47f3 976 mutex_lock(&mvm->mutex);
145d90b6
EG
977
978 /* stop recording */
979 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
980 iwl_set_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
981 } else {
982 iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 0);
983 /* wait before we collect the data till the DBGC stop */
984 udelay(100);
985 }
986
4bfa47f3 987 iwl_mvm_fw_error_dump(mvm);
e66e0b70
EG
988
989 /* start recording again if the firmware is not crashed */
990 WARN_ON_ONCE((!test_bit(STATUS_FW_ERROR, &mvm->trans->status)) &&
9beda940
EG
991 mvm->fw->dbg_dest_tlv &&
992 iwl_mvm_start_fw_dbg_conf(mvm, mvm->fw_dbg_conf));
e66e0b70 993
4bfa47f3 994 mutex_unlock(&mvm->mutex);
fb2380a2
LK
995
996 iwl_mvm_unref(mvm, IWL_MVM_REF_FW_DBG_COLLECT);
4bfa47f3
EG
997}
998
b08c1d97 999void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error)
8ca151b5 1000{
8ca151b5
JB
1001 iwl_abort_notification_waits(&mvm->notif_wait);
1002
992f81fc
DS
1003 /*
1004 * This is a bit racy, but worst case we tell mac80211 about
1005 * a stopped/aborted scan when that was already done which
1006 * is not a problem. It is necessary to abort any os scan
1007 * here because mac80211 requires having the scan cleared
1008 * before restarting.
1009 * We'll reset the scan_status to NONE in restart cleanup in
1010 * the next start() call from mac80211. If restart isn't called
1011 * (no fw restart) scan status will stay busy.
1012 */
4ffb3650 1013 iwl_mvm_report_scan_aborted(mvm);
992f81fc 1014
8ca151b5
JB
1015 /*
1016 * If we're restarting already, don't cycle restarts.
1017 * If INIT fw asserted, it will likely fail again.
1018 * If WoWLAN fw asserted, don't restart either, mac80211
1019 * can't recover this since we're already half suspended.
1020 */
60f1071c 1021 if (!mvm->restart_fw && fw_error) {
36fb9017
OG
1022 iwl_mvm_fw_dbg_collect_desc(mvm, &iwl_mvm_dump_desc_assert,
1023 NULL);
60f1071c
LC
1024 } else if (test_and_set_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1025 &mvm->status)) {
ac1ed416
JB
1026 struct iwl_mvm_reprobe *reprobe;
1027
1028 IWL_ERR(mvm,
1029 "Firmware error during reconfiguration - reprobe!\n");
1030
1031 /*
1032 * get a module reference to avoid doing this while unloading
1033 * anyway and to avoid scheduling a work with code that's
1034 * being removed.
1035 */
1036 if (!try_module_get(THIS_MODULE)) {
1037 IWL_ERR(mvm, "Module is being unloaded - abort\n");
1038 return;
1039 }
1040
1041 reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC);
1042 if (!reprobe) {
1043 module_put(THIS_MODULE);
1044 return;
1045 }
1046 reprobe->dev = mvm->trans->dev;
1047 INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk);
1048 schedule_work(&reprobe->work);
60f1071c 1049 } else if (mvm->cur_ucode == IWL_UCODE_REGULAR) {
7498cf4c
EP
1050 /* don't let the transport/FW power down */
1051 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1052
b08c1d97 1053 if (fw_error && mvm->restart_fw > 0)
291aa7c4 1054 mvm->restart_fw--;
8ca151b5
JB
1055 ieee80211_restart_hw(mvm->hw);
1056 }
1057}
1058
715c998f
EG
1059static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode)
1060{
1061 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1062
1063 iwl_mvm_dump_nic_error_log(mvm);
1bd3cbc1 1064
b08c1d97 1065 iwl_mvm_nic_restart(mvm, true);
715c998f
EG
1066}
1067
8ca151b5
JB
1068static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
1069{
715c998f
EG
1070 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1071
8ca151b5 1072 WARN_ON(1);
b08c1d97 1073 iwl_mvm_nic_restart(mvm, true);
8ca151b5
JB
1074}
1075
37577fe2
EP
1076struct iwl_d0i3_iter_data {
1077 struct iwl_mvm *mvm;
a3f7ba5c 1078 struct ieee80211_vif *connected_vif;
37577fe2
EP
1079 u8 ap_sta_id;
1080 u8 vif_count;
b2492501
AN
1081 u8 offloading_tid;
1082 bool disable_offloading;
37577fe2
EP
1083};
1084
b2492501
AN
1085static bool iwl_mvm_disallow_offloading(struct iwl_mvm *mvm,
1086 struct ieee80211_vif *vif,
1087 struct iwl_d0i3_iter_data *iter_data)
1088{
1089 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1090 struct ieee80211_sta *ap_sta;
1091 struct iwl_mvm_sta *mvmsta;
1092 u32 available_tids = 0;
1093 u8 tid;
1094
1095 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION ||
1096 mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT))
1097 return false;
1098
1099 ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id]);
1100 if (IS_ERR_OR_NULL(ap_sta))
1101 return false;
1102
1103 mvmsta = iwl_mvm_sta_from_mac80211(ap_sta);
1104 spin_lock_bh(&mvmsta->lock);
1105 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1106 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1107
1108 /*
1109 * in case of pending tx packets, don't use this tid
1110 * for offloading in order to prevent reuse of the same
1111 * qos seq counters.
1112 */
1113 if (iwl_mvm_tid_queued(tid_data))
1114 continue;
1115
1116 if (tid_data->state != IWL_AGG_OFF)
1117 continue;
1118
1119 available_tids |= BIT(tid);
1120 }
1121 spin_unlock_bh(&mvmsta->lock);
1122
1123 /*
1124 * disallow protocol offloading if we have no available tid
1125 * (with no pending frames and no active aggregation,
1126 * as we don't handle "holes" properly - the scheduler needs the
1127 * frame's seq number and TFD index to match)
1128 */
1129 if (!available_tids)
1130 return true;
1131
1132 /* for simplicity, just use the first available tid */
1133 iter_data->offloading_tid = ffs(available_tids) - 1;
1134 return false;
1135}
1136
d6230972
EP
1137static void iwl_mvm_enter_d0i3_iterator(void *_data, u8 *mac,
1138 struct ieee80211_vif *vif)
1139{
37577fe2
EP
1140 struct iwl_d0i3_iter_data *data = _data;
1141 struct iwl_mvm *mvm = data->mvm;
1142 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
d6230972
EP
1143 u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE;
1144
1145 IWL_DEBUG_RPM(mvm, "entering D0i3 - vif %pM\n", vif->addr);
1146 if (vif->type != NL80211_IFTYPE_STATION ||
1147 !vif->bss_conf.assoc)
1148 return;
1149
b2492501
AN
1150 /*
1151 * in case of pending tx packets or active aggregations,
1152 * avoid offloading features in order to prevent reuse of
1153 * the same qos seq counters.
1154 */
1155 if (iwl_mvm_disallow_offloading(mvm, vif, data))
1156 data->disable_offloading = true;
1157
d6230972 1158 iwl_mvm_update_d0i3_power_mode(mvm, vif, true, flags);
c97dab40
SS
1159 iwl_mvm_send_proto_offload(mvm, vif, data->disable_offloading,
1160 false, flags);
d6230972
EP
1161
1162 /*
1163 * on init/association, mvm already configures POWER_TABLE_CMD
1164 * and REPLY_MCAST_FILTER_CMD, so currently don't
1165 * reconfigure them (we might want to use different
1166 * params later on, though).
1167 */
37577fe2
EP
1168 data->ap_sta_id = mvmvif->ap_sta_id;
1169 data->vif_count++;
a3f7ba5c
EP
1170
1171 /*
1172 * no new commands can be sent at this stage, so it's safe
1173 * to save the vif pointer during d0i3 entrance.
1174 */
1175 data->connected_vif = vif;
d6230972
EP
1176}
1177
1a95c8df 1178static void iwl_mvm_set_wowlan_data(struct iwl_mvm *mvm,
c8b06a99 1179 struct iwl_wowlan_config_cmd *cmd,
1a95c8df
EP
1180 struct iwl_d0i3_iter_data *iter_data)
1181{
1182 struct ieee80211_sta *ap_sta;
1183 struct iwl_mvm_sta *mvm_ap_sta;
1184
1185 if (iter_data->ap_sta_id == IWL_MVM_STATION_COUNT)
1186 return;
1187
1188 rcu_read_lock();
1189
1190 ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[iter_data->ap_sta_id]);
1191 if (IS_ERR_OR_NULL(ap_sta))
1192 goto out;
1193
1194 mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
c8b06a99 1195 cmd->is_11n_connection = ap_sta->ht_cap.ht_supported;
b2492501 1196 cmd->offloading_tid = iter_data->offloading_tid;
70b4c536
SS
1197 cmd->flags = ENABLE_L3_FILTERING | ENABLE_NBNS_FILTERING |
1198 ENABLE_DHCP_FILTERING;
1a95c8df
EP
1199 /*
1200 * The d0i3 uCode takes care of the nonqos counters,
1201 * so configure only the qos seq ones.
1202 */
c8b06a99 1203 iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, cmd);
1a95c8df
EP
1204out:
1205 rcu_read_unlock();
1206}
6735943f
EP
1207
1208int iwl_mvm_enter_d0i3(struct iwl_op_mode *op_mode)
b3370d47
EP
1209{
1210 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
98ee7783 1211 u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE;
b77f06d9 1212 int ret;
37577fe2
EP
1213 struct iwl_d0i3_iter_data d0i3_iter_data = {
1214 .mvm = mvm,
1215 };
c8b06a99
EG
1216 struct iwl_wowlan_config_cmd wowlan_config_cmd = {
1217 .wakeup_filter = cpu_to_le32(IWL_WOWLAN_WAKEUP_RX_FRAME |
1218 IWL_WOWLAN_WAKEUP_BEACON_MISS |
1219 IWL_WOWLAN_WAKEUP_LINK_CHANGE |
1220 IWL_WOWLAN_WAKEUP_BCN_FILTERING),
b77f06d9 1221 };
98ee7783
AN
1222 struct iwl_d3_manager_config d3_cfg_cmd = {
1223 .min_sleep_time = cpu_to_le32(1000),
d9f1fc20 1224 .wakeup_flags = cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR),
98ee7783 1225 };
b3370d47
EP
1226
1227 IWL_DEBUG_RPM(mvm, "MVM entering D0i3\n");
98ee7783 1228
08f0d23d
EP
1229 if (WARN_ON_ONCE(mvm->cur_ucode != IWL_UCODE_REGULAR))
1230 return -EINVAL;
1231
b2492501 1232 set_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
b2492501 1233
f4cf8680
EP
1234 /*
1235 * iwl_mvm_ref_sync takes a reference before checking the flag.
1236 * so by checking there is no held reference we prevent a state
1237 * in which iwl_mvm_ref_sync continues successfully while we
1238 * configure the firmware to enter d0i3
1239 */
1240 if (iwl_mvm_ref_taken(mvm)) {
1241 IWL_DEBUG_RPM(mvm->trans, "abort d0i3 due to taken ref\n");
1242 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
caf1578a 1243 wake_up(&mvm->d0i3_exit_waitq);
f4cf8680
EP
1244 return 1;
1245 }
1246
d6230972
EP
1247 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1248 IEEE80211_IFACE_ITER_NORMAL,
1249 iwl_mvm_enter_d0i3_iterator,
37577fe2
EP
1250 &d0i3_iter_data);
1251 if (d0i3_iter_data.vif_count == 1) {
1252 mvm->d0i3_ap_sta_id = d0i3_iter_data.ap_sta_id;
b2492501 1253 mvm->d0i3_offloading = !d0i3_iter_data.disable_offloading;
37577fe2
EP
1254 } else {
1255 WARN_ON_ONCE(d0i3_iter_data.vif_count > 1);
1256 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
b2492501 1257 mvm->d0i3_offloading = false;
37577fe2 1258 }
d6230972 1259
ecc7c518
EG
1260 /* make sure we have no running tx while configuring the seqno */
1261 synchronize_net();
1262
eb3908d3
LC
1263 /* Flush the hw queues, in case something got queued during entry */
1264 ret = iwl_mvm_flush_tx_path(mvm, iwl_mvm_flushable_queues(mvm), flags);
1265 if (ret)
1266 return ret;
1267
183edd84
EP
1268 /* configure wowlan configuration only if needed */
1269 if (mvm->d0i3_ap_sta_id != IWL_MVM_STATION_COUNT) {
a3f7ba5c
EP
1270 iwl_mvm_wowlan_config_key_params(mvm,
1271 d0i3_iter_data.connected_vif,
1272 true, flags);
1273
183edd84
EP
1274 iwl_mvm_set_wowlan_data(mvm, &wowlan_config_cmd,
1275 &d0i3_iter_data);
1276
1277 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, flags,
1278 sizeof(wowlan_config_cmd),
1279 &wowlan_config_cmd);
1280 if (ret)
1281 return ret;
1282 }
b77f06d9 1283
98ee7783
AN
1284 return iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD,
1285 flags | CMD_MAKE_TRANS_IDLE,
1286 sizeof(d3_cfg_cmd), &d3_cfg_cmd);
b3370d47
EP
1287}
1288
d6230972
EP
1289static void iwl_mvm_exit_d0i3_iterator(void *_data, u8 *mac,
1290 struct ieee80211_vif *vif)
1291{
1292 struct iwl_mvm *mvm = _data;
1293 u32 flags = CMD_ASYNC | CMD_HIGH_PRIO;
1294
1295 IWL_DEBUG_RPM(mvm, "exiting D0i3 - vif %pM\n", vif->addr);
1296 if (vif->type != NL80211_IFTYPE_STATION ||
1297 !vif->bss_conf.assoc)
1298 return;
1299
1300 iwl_mvm_update_d0i3_power_mode(mvm, vif, false, flags);
1301}
1302
a3f7ba5c 1303struct iwl_mvm_d0i3_exit_work_iter_data {
b3df2247 1304 struct iwl_mvm *mvm;
a3f7ba5c 1305 struct iwl_wowlan_status *status;
b3df2247
DS
1306 u32 wakeup_reasons;
1307};
1308
a3f7ba5c
EP
1309static void iwl_mvm_d0i3_exit_work_iter(void *_data, u8 *mac,
1310 struct ieee80211_vif *vif)
37577fe2 1311{
a3f7ba5c 1312 struct iwl_mvm_d0i3_exit_work_iter_data *data = _data;
37577fe2 1313 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
a3f7ba5c 1314 u32 reasons = data->wakeup_reasons;
37577fe2 1315
a3f7ba5c
EP
1316 /* consider only the relevant station interface */
1317 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1318 data->mvm->d0i3_ap_sta_id != mvmvif->ap_sta_id)
1319 return;
1320
1321 if (reasons & IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH)
1322 iwl_mvm_connection_loss(data->mvm, vif, "D0i3");
1323 else if (reasons & IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON)
1324 ieee80211_beacon_loss(vif);
1325 else
1326 iwl_mvm_d0i3_update_keys(data->mvm, vif, data->status);
37577fe2
EP
1327}
1328
b2492501
AN
1329void iwl_mvm_d0i3_enable_tx(struct iwl_mvm *mvm, __le16 *qos_seq)
1330{
1331 struct ieee80211_sta *sta = NULL;
1332 struct iwl_mvm_sta *mvm_ap_sta;
1333 int i;
1334 bool wake_queues = false;
1335
1336 lockdep_assert_held(&mvm->mutex);
1337
1338 spin_lock_bh(&mvm->d0i3_tx_lock);
1339
1340 if (mvm->d0i3_ap_sta_id == IWL_MVM_STATION_COUNT)
1341 goto out;
1342
1343 IWL_DEBUG_RPM(mvm, "re-enqueue packets\n");
1344
1345 /* get the sta in order to update seq numbers and re-enqueue skbs */
1346 sta = rcu_dereference_protected(
1347 mvm->fw_id_to_mac_id[mvm->d0i3_ap_sta_id],
1348 lockdep_is_held(&mvm->mutex));
1349
1350 if (IS_ERR_OR_NULL(sta)) {
1351 sta = NULL;
1352 goto out;
1353 }
1354
1355 if (mvm->d0i3_offloading && qos_seq) {
1356 /* update qos seq numbers if offloading was enabled */
9d8ce6af 1357 mvm_ap_sta = iwl_mvm_sta_from_mac80211(sta);
b2492501
AN
1358 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
1359 u16 seq = le16_to_cpu(qos_seq[i]);
1360 /* firmware stores last-used one, we store next one */
1361 seq += 0x10;
1362 mvm_ap_sta->tid_data[i].seq_number = seq;
1363 }
1364 }
1365out:
1366 /* re-enqueue (or drop) all packets */
1367 while (!skb_queue_empty(&mvm->d0i3_tx)) {
1368 struct sk_buff *skb = __skb_dequeue(&mvm->d0i3_tx);
1369
1370 if (!sta || iwl_mvm_tx_skb(mvm, skb, sta))
1371 ieee80211_free_txskb(mvm->hw, skb);
1372
1373 /* if the skb_queue is not empty, we need to wake queues */
1374 wake_queues = true;
1375 }
1376 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1377 wake_up(&mvm->d0i3_exit_waitq);
1378 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1379 if (wake_queues)
1380 ieee80211_wake_queues(mvm->hw);
1381
1382 spin_unlock_bh(&mvm->d0i3_tx_lock);
1383}
1384
37577fe2
EP
1385static void iwl_mvm_d0i3_exit_work(struct work_struct *wk)
1386{
1387 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, d0i3_exit_work);
1388 struct iwl_host_cmd get_status_cmd = {
1389 .id = WOWLAN_GET_STATUSES,
a1022927 1390 .flags = CMD_HIGH_PRIO | CMD_WANT_SKB,
37577fe2 1391 };
a3f7ba5c
EP
1392 struct iwl_mvm_d0i3_exit_work_iter_data iter_data = {
1393 .mvm = mvm,
1394 };
1395
3afec639 1396 struct iwl_wowlan_status *status;
37577fe2 1397 int ret;
a3f7ba5c 1398 u32 wakeup_reasons = 0;
b2492501 1399 __le16 *qos_seq = NULL;
37577fe2
EP
1400
1401 mutex_lock(&mvm->mutex);
1402 ret = iwl_mvm_send_cmd(mvm, &get_status_cmd);
1403 if (ret)
1404 goto out;
1405
1406 if (!get_status_cmd.resp_pkt)
1407 goto out;
1408
1409 status = (void *)get_status_cmd.resp_pkt->data;
1410 wakeup_reasons = le32_to_cpu(status->wakeup_reasons);
b2492501 1411 qos_seq = status->qos_seq_ctr;
37577fe2
EP
1412
1413 IWL_DEBUG_RPM(mvm, "wakeup reasons: 0x%x\n", wakeup_reasons);
1414
a3f7ba5c
EP
1415 iter_data.wakeup_reasons = wakeup_reasons;
1416 iter_data.status = status;
1417 ieee80211_iterate_active_interfaces(mvm->hw,
1418 IEEE80211_IFACE_ITER_NORMAL,
1419 iwl_mvm_d0i3_exit_work_iter,
1420 &iter_data);
37577fe2 1421out:
b2492501 1422 iwl_mvm_d0i3_enable_tx(mvm, qos_seq);
47c8b154 1423
7c014e35
EP
1424 IWL_DEBUG_INFO(mvm, "d0i3 exit completed (wakeup reasons: 0x%x)\n",
1425 wakeup_reasons);
1426
e5629be7
EP
1427 /* qos_seq might point inside resp_pkt, so free it only now */
1428 if (get_status_cmd.resp_pkt)
1429 iwl_free_resp(&get_status_cmd);
1430
47c8b154
JD
1431 /* the FW might have updated the regdomain */
1432 iwl_mvm_update_changed_regdom(mvm);
1433
d15a747f 1434 iwl_mvm_unref(mvm, IWL_MVM_REF_EXIT_WORK);
37577fe2
EP
1435 mutex_unlock(&mvm->mutex);
1436}
1437
d15a747f 1438int _iwl_mvm_exit_d0i3(struct iwl_mvm *mvm)
b3370d47 1439{
98ee7783
AN
1440 u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE |
1441 CMD_WAKE_UP_TRANS;
d6230972 1442 int ret;
b3370d47
EP
1443
1444 IWL_DEBUG_RPM(mvm, "MVM exiting D0i3\n");
98ee7783 1445
08f0d23d
EP
1446 if (WARN_ON_ONCE(mvm->cur_ucode != IWL_UCODE_REGULAR))
1447 return -EINVAL;
1448
d15a747f
EP
1449 mutex_lock(&mvm->d0i3_suspend_mutex);
1450 if (test_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags)) {
1451 IWL_DEBUG_RPM(mvm, "Deferring d0i3 exit until resume\n");
1452 __set_bit(D0I3_PENDING_WAKEUP, &mvm->d0i3_suspend_flags);
1453 mutex_unlock(&mvm->d0i3_suspend_mutex);
1454 return 0;
1455 }
1456 mutex_unlock(&mvm->d0i3_suspend_mutex);
1457
d6230972
EP
1458 ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, flags, 0, NULL);
1459 if (ret)
37577fe2 1460 goto out;
d6230972
EP
1461
1462 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1463 IEEE80211_IFACE_ITER_NORMAL,
1464 iwl_mvm_exit_d0i3_iterator,
1465 mvm);
37577fe2
EP
1466out:
1467 schedule_work(&mvm->d0i3_exit_work);
1468 return ret;
b3370d47
EP
1469}
1470
6735943f 1471int iwl_mvm_exit_d0i3(struct iwl_op_mode *op_mode)
d15a747f
EP
1472{
1473 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1474
1475 iwl_mvm_ref(mvm, IWL_MVM_REF_EXIT_WORK);
1476 return _iwl_mvm_exit_d0i3(mvm);
1477}
1478
0316d30e
JB
1479#define IWL_MVM_COMMON_OPS \
1480 /* these could be differentiated */ \
156f92f2 1481 .async_cb = iwl_mvm_async_cb, \
0316d30e
JB
1482 .queue_full = iwl_mvm_stop_sw_queue, \
1483 .queue_not_full = iwl_mvm_wake_sw_queue, \
1484 .hw_rf_kill = iwl_mvm_set_hw_rfkill_state, \
1485 .free_skb = iwl_mvm_free_skb, \
1486 .nic_error = iwl_mvm_nic_error, \
1487 .cmd_queue_full = iwl_mvm_cmd_queue_full, \
1488 .nic_config = iwl_mvm_nic_config, \
1489 .enter_d0i3 = iwl_mvm_enter_d0i3, \
1490 .exit_d0i3 = iwl_mvm_exit_d0i3, \
1491 /* as we only register one, these MUST be common! */ \
1492 .start = iwl_op_mode_mvm_start, \
1493 .stop = iwl_op_mode_mvm_stop
1494
8ca151b5 1495static const struct iwl_op_mode_ops iwl_mvm_ops = {
0316d30e
JB
1496 IWL_MVM_COMMON_OPS,
1497 .rx = iwl_mvm_rx,
1498};
1499
1500static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,
1501 struct napi_struct *napi,
1502 struct iwl_rx_cmd_buffer *rxb,
1503 unsigned int queue)
1504{
1505 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
585a6fcc 1506 struct iwl_rx_packet *pkt = rxb_addr(rxb);
0316d30e 1507
585a6fcc
SS
1508 if (unlikely(pkt->hdr.cmd == FRAME_RELEASE))
1509 iwl_mvm_rx_frame_release(mvm, rxb, queue);
1510 else
1511 iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);
0316d30e
JB
1512}
1513
1514static const struct iwl_op_mode_ops iwl_mvm_ops_mq = {
1515 IWL_MVM_COMMON_OPS,
1516 .rx = iwl_mvm_rx_mq,
1517 .rx_rss = iwl_mvm_rx_mq_rss,
8ca151b5 1518};
This page took 0.360121 seconds and 5 git commands to generate.