Commit | Line | Data |
---|---|---|
8e99ea8d JB |
1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
2 | /* | |
3 | * Copyright (C) 2012-2014, 2018-2020 Intel Corporation | |
4 | * Copyright (C) 2013-2015 Intel Mobile Communications GmbH | |
5 | * Copyright (C) 2016-2017 Intel Deutschland GmbH | |
6 | */ | |
8ca151b5 | 7 | #include <linux/module.h> |
1bd3cbc1 | 8 | #include <linux/vmalloc.h> |
8ca151b5 JB |
9 | #include <net/mac80211.h> |
10 | ||
9fca9d5c | 11 | #include "fw/notif-wait.h" |
8ca151b5 JB |
12 | #include "iwl-trans.h" |
13 | #include "iwl-op-mode.h" | |
d962f9b1 | 14 | #include "fw/img.h" |
8ca151b5 JB |
15 | #include "iwl-debug.h" |
16 | #include "iwl-drv.h" | |
17 | #include "iwl-modparams.h" | |
18 | #include "mvm.h" | |
19 | #include "iwl-phy-db.h" | |
20 | #include "iwl-eeprom-parse.h" | |
21 | #include "iwl-csr.h" | |
22 | #include "iwl-io.h" | |
23 | #include "iwl-prph.h" | |
24 | #include "rs.h" | |
d172a5ef | 25 | #include "fw/api/scan.h" |
8ca151b5 | 26 | #include "time-event.h" |
39bdb17e | 27 | #include "fw-api.h" |
f2abcfa6 | 28 | #include "fw/acpi.h" |
8ca151b5 | 29 | |
8ca151b5 | 30 | #define DRV_DESCRIPTION "The new Intel(R) wireless AGN driver for Linux" |
8ca151b5 | 31 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
e9a7f025 | 32 | MODULE_AUTHOR(DRV_AUTHOR); |
8ca151b5 JB |
33 | MODULE_LICENSE("GPL"); |
34 | ||
35 | static const struct iwl_op_mode_ops iwl_mvm_ops; | |
0316d30e | 36 | static const struct iwl_op_mode_ops iwl_mvm_ops_mq; |
8ca151b5 JB |
37 | |
38 | struct iwl_mvm_mod_params iwlmvm_mod_params = { | |
39 | .power_scheme = IWL_POWER_SCHEME_BPS, | |
40 | /* rest of fields are 0 by default */ | |
41 | }; | |
42 | ||
2ef00c53 | 43 | module_param_named(init_dbg, iwlmvm_mod_params.init_dbg, bool, 0444); |
8ca151b5 JB |
44 | MODULE_PARM_DESC(init_dbg, |
45 | "set to true to debug an ASSERT in INIT fw (default: false"); | |
2ef00c53 | 46 | module_param_named(power_scheme, iwlmvm_mod_params.power_scheme, int, 0444); |
8ca151b5 JB |
47 | MODULE_PARM_DESC(power_scheme, |
48 | "power management scheme: 1-active, 2-balanced, 3-low power, default: 2"); | |
49 | ||
50 | /* | |
51 | * module init and exit functions | |
52 | */ | |
53 | static int __init iwl_mvm_init(void) | |
54 | { | |
55 | int ret; | |
56 | ||
57 | ret = iwl_mvm_rate_control_register(); | |
58 | if (ret) { | |
59 | pr_err("Unable to register rate control algorithm: %d\n", ret); | |
60 | return ret; | |
61 | } | |
62 | ||
63 | ret = iwl_opmode_register("iwlmvm", &iwl_mvm_ops); | |
9f66a397 | 64 | if (ret) |
8ca151b5 | 65 | pr_err("Unable to register MVM op_mode: %d\n", ret); |
8ca151b5 JB |
66 | |
67 | return ret; | |
68 | } | |
69 | module_init(iwl_mvm_init); | |
70 | ||
71 | static void __exit iwl_mvm_exit(void) | |
72 | { | |
73 | iwl_opmode_deregister("iwlmvm"); | |
74 | iwl_mvm_rate_control_unregister(); | |
75 | } | |
76 | module_exit(iwl_mvm_exit); | |
77 | ||
78 | static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode) | |
79 | { | |
80 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
16b2afe0 | 81 | struct iwl_trans_debug *dbg = &mvm->trans->dbg; |
8ca151b5 JB |
82 | u8 radio_cfg_type, radio_cfg_step, radio_cfg_dash; |
83 | u32 reg_val = 0; | |
a0544272 MH |
84 | u32 phy_config = iwl_mvm_get_phy_config(mvm); |
85 | ||
86 | radio_cfg_type = (phy_config & FW_PHY_CFG_RADIO_TYPE) >> | |
87 | FW_PHY_CFG_RADIO_TYPE_POS; | |
88 | radio_cfg_step = (phy_config & FW_PHY_CFG_RADIO_STEP) >> | |
89 | FW_PHY_CFG_RADIO_STEP_POS; | |
90 | radio_cfg_dash = (phy_config & FW_PHY_CFG_RADIO_DASH) >> | |
91 | FW_PHY_CFG_RADIO_DASH_POS; | |
8ca151b5 JB |
92 | |
93 | /* SKU control */ | |
94 | reg_val |= CSR_HW_REV_STEP(mvm->trans->hw_rev) << | |
95 | CSR_HW_IF_CONFIG_REG_POS_MAC_STEP; | |
96 | reg_val |= CSR_HW_REV_DASH(mvm->trans->hw_rev) << | |
97 | CSR_HW_IF_CONFIG_REG_POS_MAC_DASH; | |
98 | ||
99 | /* radio configuration */ | |
100 | reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE; | |
101 | reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP; | |
102 | reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH; | |
103 | ||
104 | WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) & | |
105 | ~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE); | |
106 | ||
9b1fcc11 | 107 | /* |
6e584873 SS |
108 | * TODO: Bits 7-8 of CSR in 8000 HW family and higher set the ADC |
109 | * sampling, and shouldn't be set to any non-zero value. | |
110 | * The same is supposed to be true of the other HW, but unsetting | |
111 | * them (such as the 7260) causes automatic tests to fail on seemingly | |
112 | * unrelated errors. Need to further investigate this, but for now | |
113 | * we'll separate cases. | |
9b1fcc11 | 114 | */ |
286ca8eb | 115 | if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000) |
9b1fcc11 | 116 | reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI; |
8ca151b5 | 117 | |
16b2afe0 MG |
118 | if (iwl_fw_dbg_is_d3_debug_enabled(&mvm->fwrt) || |
119 | (iwl_trans_dbg_ini_valid(mvm->trans) && | |
120 | dbg->fw_mon_cfg[IWL_FW_INI_ALLOCATION_ID_INTERNAL].buf_location) | |
121 | ) | |
2d8c2615 SM |
122 | reg_val |= CSR_HW_IF_CONFIG_REG_D3_DEBUG; |
123 | ||
e139dc4a LE |
124 | iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG, |
125 | CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH | | |
126 | CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP | | |
127 | CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE | | |
128 | CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP | | |
129 | CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH | | |
130 | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | | |
2d8c2615 SM |
131 | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI | |
132 | CSR_HW_IF_CONFIG_REG_D3_DEBUG, | |
e139dc4a | 133 | reg_val); |
8ca151b5 JB |
134 | |
135 | IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type, | |
136 | radio_cfg_step, radio_cfg_dash); | |
137 | ||
138 | /* | |
139 | * W/A : NIC is stuck in a reset state after Early PCIe power off | |
140 | * (PCIe power is lost before PERST# is asserted), causing ME FW | |
141 | * to lose ownership and not being able to obtain it back. | |
142 | */ | |
95411d04 | 143 | if (!mvm->trans->cfg->apmg_not_supported) |
3073d8c0 EH |
144 | iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG, |
145 | APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, | |
146 | ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); | |
8ca151b5 JB |
147 | } |
148 | ||
c9cb14a6 CRI |
149 | /** |
150 | * enum iwl_rx_handler_context context for Rx handler | |
151 | * @RX_HANDLER_SYNC : this means that it will be called in the Rx path | |
152 | * which can't acquire mvm->mutex. | |
153 | * @RX_HANDLER_ASYNC_LOCKED : If the handler needs to hold mvm->mutex | |
154 | * (and only in this case!), it should be set as ASYNC. In that case, | |
155 | * it will be called from a worker with mvm->mutex held. | |
156 | * @RX_HANDLER_ASYNC_UNLOCKED : in case the handler needs to lock the | |
157 | * mutex itself, it will be called from a worker without mvm->mutex held. | |
158 | */ | |
159 | enum iwl_rx_handler_context { | |
160 | RX_HANDLER_SYNC, | |
161 | RX_HANDLER_ASYNC_LOCKED, | |
162 | RX_HANDLER_ASYNC_UNLOCKED, | |
163 | }; | |
164 | ||
165 | /** | |
166 | * struct iwl_rx_handlers handler for FW notification | |
167 | * @cmd_id: command id | |
168 | * @context: see &iwl_rx_handler_context | |
169 | * @fn: the function is called when notification is received | |
170 | */ | |
8ca151b5 | 171 | struct iwl_rx_handlers { |
1230b16b | 172 | u16 cmd_id; |
c9cb14a6 | 173 | enum iwl_rx_handler_context context; |
0416841d | 174 | void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb); |
8ca151b5 JB |
175 | }; |
176 | ||
c9cb14a6 CRI |
177 | #define RX_HANDLER(_cmd_id, _fn, _context) \ |
178 | { .cmd_id = _cmd_id, .fn = _fn, .context = _context } | |
179 | #define RX_HANDLER_GRP(_grp, _cmd, _fn, _context) \ | |
180 | { .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .context = _context } | |
8ca151b5 JB |
181 | |
182 | /* | |
183 | * Handlers for fw notifications | |
184 | * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME | |
185 | * This list should be in order of frequency for performance purposes. | |
186 | * | |
c9cb14a6 | 187 | * The handler can be one from three contexts, see &iwl_rx_handler_context |
8ca151b5 JB |
188 | */ |
189 | static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = { | |
c9cb14a6 CRI |
190 | RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, RX_HANDLER_SYNC), |
191 | RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, RX_HANDLER_SYNC), | |
192 | ||
84226ca1 GG |
193 | RX_HANDLER_GRP(DATA_PATH_GROUP, TLC_MNG_UPDATE_NOTIF, |
194 | iwl_mvm_tlc_update_notif, RX_HANDLER_SYNC), | |
195 | ||
c9cb14a6 CRI |
196 | RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif, |
197 | RX_HANDLER_ASYNC_LOCKED), | |
198 | RX_HANDLER(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif, | |
199 | RX_HANDLER_ASYNC_LOCKED), | |
200 | RX_HANDLER(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics, | |
201 | RX_HANDLER_ASYNC_LOCKED), | |
f421f9c3 | 202 | |
3af512d6 | 203 | RX_HANDLER(BA_WINDOW_STATUS_NOTIFICATION_ID, |
c9cb14a6 | 204 | iwl_mvm_window_status_notif, RX_HANDLER_SYNC), |
3af512d6 | 205 | |
c9cb14a6 CRI |
206 | RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif, |
207 | RX_HANDLER_SYNC), | |
fe959c7b EG |
208 | RX_HANDLER_GRP(MAC_CONF_GROUP, SESSION_PROTECTION_NOTIF, |
209 | iwl_mvm_rx_session_protect_notif, RX_HANDLER_SYNC), | |
c9cb14a6 CRI |
210 | RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc, |
211 | RX_HANDLER_ASYNC_LOCKED), | |
497b49d2 | 212 | |
c9cb14a6 | 213 | RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, RX_HANDLER_SYNC), |
3e56eadf | 214 | |
e5d74646 | 215 | RX_HANDLER(SCAN_ITERATION_COMPLETE, |
c9cb14a6 | 216 | iwl_mvm_rx_lmac_scan_iter_complete_notif, RX_HANDLER_SYNC), |
35a000b7 | 217 | RX_HANDLER(SCAN_OFFLOAD_COMPLETE, |
c9cb14a6 CRI |
218 | iwl_mvm_rx_lmac_scan_complete_notif, |
219 | RX_HANDLER_ASYNC_LOCKED), | |
6e56f01d | 220 | RX_HANDLER(MATCH_FOUND_NOTIFICATION, iwl_mvm_rx_scan_match_found, |
c9cb14a6 | 221 | RX_HANDLER_SYNC), |
d2496221 | 222 | RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif, |
c9cb14a6 | 223 | RX_HANDLER_ASYNC_LOCKED), |
ee9219b2 | 224 | RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC, |
c9cb14a6 | 225 | iwl_mvm_rx_umac_scan_iter_complete_notif, RX_HANDLER_SYNC), |
497b49d2 | 226 | |
c9cb14a6 CRI |
227 | RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif, |
228 | RX_HANDLER_SYNC), | |
8ca151b5 | 229 | |
d64048ed | 230 | RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif, |
c9cb14a6 | 231 | RX_HANDLER_SYNC), |
d64048ed | 232 | |
c9cb14a6 | 233 | RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, RX_HANDLER_SYNC), |
175a70b7 | 234 | RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION, |
c9cb14a6 CRI |
235 | iwl_mvm_power_uapsd_misbehaving_ap_notif, RX_HANDLER_SYNC), |
236 | RX_HANDLER(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif, | |
237 | RX_HANDLER_ASYNC_LOCKED), | |
09eef330 | 238 | RX_HANDLER_GRP(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE, |
ec77a33e | 239 | iwl_mvm_temp_notif, RX_HANDLER_ASYNC_UNLOCKED), |
0a3b7119 | 240 | RX_HANDLER_GRP(PHY_OPS_GROUP, CT_KILL_NOTIFICATION, |
c9cb14a6 | 241 | iwl_mvm_ct_kill_notif, RX_HANDLER_SYNC), |
ea9af24d | 242 | |
1d3c3f63 | 243 | RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif, |
c9cb14a6 CRI |
244 | RX_HANDLER_ASYNC_LOCKED), |
245 | RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif, | |
246 | RX_HANDLER_SYNC), | |
b73f9a4a JB |
247 | RX_HANDLER_GRP(LOCATION_GROUP, TOF_RESPONDER_STATS, |
248 | iwl_mvm_ftm_responder_stats, RX_HANDLER_ASYNC_LOCKED), | |
fc36ffda JB |
249 | |
250 | RX_HANDLER_GRP(LOCATION_GROUP, TOF_RANGE_RESPONSE_NOTIF, | |
251 | iwl_mvm_ftm_range_resp, RX_HANDLER_ASYNC_LOCKED), | |
252 | RX_HANDLER_GRP(LOCATION_GROUP, TOF_LC_NOTIF, | |
253 | iwl_mvm_ftm_lc_notif, RX_HANDLER_ASYNC_LOCKED), | |
254 | ||
bdccdb85 GBA |
255 | RX_HANDLER_GRP(DEBUG_GROUP, MFU_ASSERT_DUMP_NTF, |
256 | iwl_mvm_mfu_assert_dump_notif, RX_HANDLER_SYNC), | |
0db056d3 | 257 | RX_HANDLER_GRP(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF, |
c9cb14a6 | 258 | iwl_mvm_rx_stored_beacon_notif, RX_HANDLER_SYNC), |
f92659a1 | 259 | RX_HANDLER_GRP(DATA_PATH_GROUP, MU_GROUP_MGMT_NOTIF, |
c9cb14a6 | 260 | iwl_mvm_mu_mimo_grp_notif, RX_HANDLER_SYNC), |
65e25482 JB |
261 | RX_HANDLER_GRP(DATA_PATH_GROUP, STA_PM_NOTIF, |
262 | iwl_mvm_sta_pm_notif, RX_HANDLER_SYNC), | |
8ca151b5 JB |
263 | }; |
264 | #undef RX_HANDLER | |
1230b16b | 265 | #undef RX_HANDLER_GRP |
39bdb17e SD |
266 | |
267 | /* Please keep this array *SORTED* by hex value. | |
268 | * Access is done through binary search | |
269 | */ | |
270 | static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = { | |
9422b978 | 271 | HCMD_NAME(UCODE_ALIVE_NTFY), |
39bdb17e SD |
272 | HCMD_NAME(REPLY_ERROR), |
273 | HCMD_NAME(ECHO_CMD), | |
274 | HCMD_NAME(INIT_COMPLETE_NOTIF), | |
275 | HCMD_NAME(PHY_CONTEXT_CMD), | |
276 | HCMD_NAME(DBG_CFG), | |
39bdb17e SD |
277 | HCMD_NAME(SCAN_CFG_CMD), |
278 | HCMD_NAME(SCAN_REQ_UMAC), | |
279 | HCMD_NAME(SCAN_ABORT_UMAC), | |
280 | HCMD_NAME(SCAN_COMPLETE_UMAC), | |
3af512d6 | 281 | HCMD_NAME(BA_WINDOW_STATUS_NOTIFICATION_ID), |
39bdb17e SD |
282 | HCMD_NAME(ADD_STA_KEY), |
283 | HCMD_NAME(ADD_STA), | |
284 | HCMD_NAME(REMOVE_STA), | |
285 | HCMD_NAME(FW_GET_ITEM_CMD), | |
286 | HCMD_NAME(TX_CMD), | |
287 | HCMD_NAME(SCD_QUEUE_CFG), | |
288 | HCMD_NAME(TXPATH_FLUSH), | |
289 | HCMD_NAME(MGMT_MCAST_KEY), | |
290 | HCMD_NAME(WEP_KEY), | |
291 | HCMD_NAME(SHARED_MEM_CFG), | |
292 | HCMD_NAME(TDLS_CHANNEL_SWITCH_CMD), | |
293 | HCMD_NAME(MAC_CONTEXT_CMD), | |
294 | HCMD_NAME(TIME_EVENT_CMD), | |
295 | HCMD_NAME(TIME_EVENT_NOTIFICATION), | |
296 | HCMD_NAME(BINDING_CONTEXT_CMD), | |
297 | HCMD_NAME(TIME_QUOTA_CMD), | |
298 | HCMD_NAME(NON_QOS_TX_COUNTER_CMD), | |
7089ae63 | 299 | HCMD_NAME(LEDS_CMD), |
39bdb17e SD |
300 | HCMD_NAME(LQ_CMD), |
301 | HCMD_NAME(FW_PAGING_BLOCK_CMD), | |
302 | HCMD_NAME(SCAN_OFFLOAD_REQUEST_CMD), | |
303 | HCMD_NAME(SCAN_OFFLOAD_ABORT_CMD), | |
304 | HCMD_NAME(HOT_SPOT_CMD), | |
305 | HCMD_NAME(SCAN_OFFLOAD_PROFILES_QUERY_CMD), | |
39bdb17e SD |
306 | HCMD_NAME(BT_COEX_UPDATE_REDUCED_TXP), |
307 | HCMD_NAME(BT_COEX_CI), | |
308 | HCMD_NAME(PHY_CONFIGURATION_CMD), | |
309 | HCMD_NAME(CALIB_RES_NOTIF_PHY_DB), | |
176aa60b | 310 | HCMD_NAME(PHY_DB_CMD), |
39bdb17e SD |
311 | HCMD_NAME(SCAN_OFFLOAD_COMPLETE), |
312 | HCMD_NAME(SCAN_OFFLOAD_UPDATE_PROFILES_CMD), | |
39bdb17e SD |
313 | HCMD_NAME(POWER_TABLE_CMD), |
314 | HCMD_NAME(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION), | |
315 | HCMD_NAME(REPLY_THERMAL_MNG_BACKOFF), | |
316 | HCMD_NAME(DC2DC_CONFIG_CMD), | |
317 | HCMD_NAME(NVM_ACCESS_CMD), | |
39bdb17e SD |
318 | HCMD_NAME(BEACON_NOTIFICATION), |
319 | HCMD_NAME(BEACON_TEMPLATE_CMD), | |
320 | HCMD_NAME(TX_ANT_CONFIGURATION_CMD), | |
321 | HCMD_NAME(BT_CONFIG), | |
322 | HCMD_NAME(STATISTICS_CMD), | |
323 | HCMD_NAME(STATISTICS_NOTIFICATION), | |
324 | HCMD_NAME(EOSP_NOTIFICATION), | |
325 | HCMD_NAME(REDUCE_TX_POWER_CMD), | |
39bdb17e SD |
326 | HCMD_NAME(CARD_STATE_NOTIFICATION), |
327 | HCMD_NAME(MISSED_BEACONS_NOTIFICATION), | |
328 | HCMD_NAME(TDLS_CONFIG_CMD), | |
329 | HCMD_NAME(MAC_PM_POWER_TABLE), | |
330 | HCMD_NAME(TDLS_CHANNEL_SWITCH_NOTIFICATION), | |
331 | HCMD_NAME(MFUART_LOAD_NOTIFICATION), | |
43413a97 | 332 | HCMD_NAME(RSS_CONFIG_CMD), |
39bdb17e SD |
333 | HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC), |
334 | HCMD_NAME(REPLY_RX_PHY_CMD), | |
335 | HCMD_NAME(REPLY_RX_MPDU_CMD), | |
fe69b7d1 | 336 | HCMD_NAME(BAR_FRAME_RELEASE), |
3e73aa3b | 337 | HCMD_NAME(FRAME_RELEASE), |
39bdb17e SD |
338 | HCMD_NAME(BA_NOTIF), |
339 | HCMD_NAME(MCC_UPDATE_CMD), | |
340 | HCMD_NAME(MCC_CHUB_UPDATE_CMD), | |
341 | HCMD_NAME(MARKER_CMD), | |
39bdb17e SD |
342 | HCMD_NAME(BT_PROFILE_NOTIFICATION), |
343 | HCMD_NAME(BCAST_FILTER_CMD), | |
344 | HCMD_NAME(MCAST_FILTER_CMD), | |
345 | HCMD_NAME(REPLY_SF_CFG_CMD), | |
346 | HCMD_NAME(REPLY_BEACON_FILTERING_CMD), | |
347 | HCMD_NAME(D3_CONFIG_CMD), | |
348 | HCMD_NAME(PROT_OFFLOAD_CONFIG_CMD), | |
349 | HCMD_NAME(OFFLOADS_QUERY_CMD), | |
350 | HCMD_NAME(REMOTE_WAKE_CONFIG_CMD), | |
351 | HCMD_NAME(MATCH_FOUND_NOTIFICATION), | |
39bdb17e SD |
352 | HCMD_NAME(DTS_MEASUREMENT_NOTIFICATION), |
353 | HCMD_NAME(WOWLAN_PATTERNS), | |
354 | HCMD_NAME(WOWLAN_CONFIGURATION), | |
355 | HCMD_NAME(WOWLAN_TSC_RSC_PARAM), | |
356 | HCMD_NAME(WOWLAN_TKIP_PARAM), | |
357 | HCMD_NAME(WOWLAN_KEK_KCK_MATERIAL), | |
358 | HCMD_NAME(WOWLAN_GET_STATUSES), | |
39bdb17e SD |
359 | HCMD_NAME(SCAN_ITERATION_COMPLETE), |
360 | HCMD_NAME(D0I3_END_CMD), | |
361 | HCMD_NAME(LTR_CONFIG), | |
60ced797 | 362 | HCMD_NAME(LDBG_CONFIG_CMD), |
8ca151b5 | 363 | }; |
39bdb17e | 364 | |
5b086414 GBA |
365 | /* Please keep this array *SORTED* by hex value. |
366 | * Access is done through binary search | |
367 | */ | |
368 | static const struct iwl_hcmd_names iwl_mvm_system_names[] = { | |
369 | HCMD_NAME(SHARED_MEM_CFG_CMD), | |
4399caaa | 370 | HCMD_NAME(INIT_EXTENDED_CFG_CMD), |
f130bb75 | 371 | HCMD_NAME(FW_ERROR_RECOVERY_CMD), |
5b086414 GBA |
372 | }; |
373 | ||
03098268 AE |
374 | /* Please keep this array *SORTED* by hex value. |
375 | * Access is done through binary search | |
376 | */ | |
377 | static const struct iwl_hcmd_names iwl_mvm_mac_conf_names[] = { | |
74a10252 | 378 | HCMD_NAME(CHANNEL_SWITCH_TIME_EVENT_CMD), |
fe959c7b EG |
379 | HCMD_NAME(SESSION_PROTECTION_CMD), |
380 | HCMD_NAME(SESSION_PROTECTION_NOTIF), | |
d3a108a4 | 381 | HCMD_NAME(CHANNEL_SWITCH_NOA_NOTIF), |
03098268 AE |
382 | }; |
383 | ||
39bdb17e SD |
384 | /* Please keep this array *SORTED* by hex value. |
385 | * Access is done through binary search | |
386 | */ | |
387 | static const struct iwl_hcmd_names iwl_mvm_phy_names[] = { | |
388 | HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE), | |
5c89e7bc | 389 | HCMD_NAME(CTDP_CONFIG_CMD), |
c221daf2 | 390 | HCMD_NAME(TEMP_REPORTING_THRESHOLDS_CMD), |
a6bff3cb | 391 | HCMD_NAME(GEO_TX_POWER_LIMIT), |
0a3b7119 | 392 | HCMD_NAME(CT_KILL_NOTIFICATION), |
39bdb17e SD |
393 | HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE), |
394 | }; | |
395 | ||
e0d8fdec SS |
396 | /* Please keep this array *SORTED* by hex value. |
397 | * Access is done through binary search | |
398 | */ | |
399 | static const struct iwl_hcmd_names iwl_mvm_data_path_names[] = { | |
ddef2f98 | 400 | HCMD_NAME(DQA_ENABLE_CMD), |
e0d8fdec | 401 | HCMD_NAME(UPDATE_MU_GROUPS_CMD), |
94bb4481 | 402 | HCMD_NAME(TRIGGER_RX_QUEUES_NOTIF_CMD), |
514c3069 | 403 | HCMD_NAME(STA_HE_CTXT_CMD), |
8edbfaa1 | 404 | HCMD_NAME(RFH_QUEUE_CONFIG_CMD), |
f4056d71 | 405 | HCMD_NAME(TLC_MNG_CONFIG_CMD), |
5213e8a8 | 406 | HCMD_NAME(CHEST_COLLECTOR_FILTER_CONFIG_CMD), |
65e25482 | 407 | HCMD_NAME(STA_PM_NOTIF), |
f92659a1 | 408 | HCMD_NAME(MU_GROUP_MGMT_NOTIF), |
94bb4481 | 409 | HCMD_NAME(RX_QUEUES_NOTIFICATION), |
e0d8fdec SS |
410 | }; |
411 | ||
6c161980 JB |
412 | /* Please keep this array *SORTED* by hex value. |
413 | * Access is done through binary search | |
414 | */ | |
415 | static const struct iwl_hcmd_names iwl_mvm_location_names[] = { | |
416 | HCMD_NAME(TOF_RANGE_REQ_CMD), | |
417 | HCMD_NAME(TOF_CONFIG_CMD), | |
418 | HCMD_NAME(TOF_RANGE_ABORT_CMD), | |
419 | HCMD_NAME(TOF_RANGE_REQ_EXT_CMD), | |
420 | HCMD_NAME(TOF_RESPONDER_CONFIG_CMD), | |
421 | HCMD_NAME(TOF_RESPONDER_DYN_CONFIG_CMD), | |
422 | HCMD_NAME(TOF_LC_NOTIF), | |
423 | HCMD_NAME(TOF_RESPONDER_STATS), | |
424 | HCMD_NAME(TOF_MCSI_DEBUG_NOTIF), | |
425 | HCMD_NAME(TOF_RANGE_RESPONSE_NOTIF), | |
426 | }; | |
427 | ||
0db056d3 SS |
428 | /* Please keep this array *SORTED* by hex value. |
429 | * Access is done through binary search | |
430 | */ | |
431 | static const struct iwl_hcmd_names iwl_mvm_prot_offload_names[] = { | |
432 | HCMD_NAME(STORED_BEACON_NTF), | |
433 | }; | |
434 | ||
1f370650 SS |
435 | /* Please keep this array *SORTED* by hex value. |
436 | * Access is done through binary search | |
437 | */ | |
438 | static const struct iwl_hcmd_names iwl_mvm_regulatory_and_nvm_names[] = { | |
439 | HCMD_NAME(NVM_ACCESS_COMPLETE), | |
e9e1ba3d | 440 | HCMD_NAME(NVM_GET_INFO), |
28dd7ccd | 441 | HCMD_NAME(TAS_CONFIG), |
1f370650 SS |
442 | }; |
443 | ||
39bdb17e SD |
444 | static const struct iwl_hcmd_arr iwl_mvm_groups[] = { |
445 | [LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names), | |
446 | [LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names), | |
5b086414 | 447 | [SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names), |
03098268 | 448 | [MAC_CONF_GROUP] = HCMD_ARR(iwl_mvm_mac_conf_names), |
39bdb17e | 449 | [PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names), |
e0d8fdec | 450 | [DATA_PATH_GROUP] = HCMD_ARR(iwl_mvm_data_path_names), |
6c161980 | 451 | [LOCATION_GROUP] = HCMD_ARR(iwl_mvm_location_names), |
0db056d3 | 452 | [PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mvm_prot_offload_names), |
1f370650 SS |
453 | [REGULATORY_AND_NVM_GROUP] = |
454 | HCMD_ARR(iwl_mvm_regulatory_and_nvm_names), | |
39bdb17e SD |
455 | }; |
456 | ||
8ca151b5 JB |
457 | /* this forward declaration can avoid to export the function */ |
458 | static void iwl_mvm_async_handlers_wk(struct work_struct *wk); | |
459 | ||
f2abcfa6 | 460 | static u32 iwl_mvm_min_backoff(struct iwl_mvm *mvm) |
0c0e2c71 | 461 | { |
f2abcfa6 LC |
462 | const struct iwl_pwr_tx_backoff *backoff = mvm->cfg->pwr_tx_backoffs; |
463 | u64 dflt_pwr_limit; | |
0c0e2c71 | 464 | |
f2abcfa6 | 465 | if (!backoff) |
0c0e2c71 IY |
466 | return 0; |
467 | ||
f2abcfa6 | 468 | dflt_pwr_limit = iwl_acpi_get_pwr_limit(mvm->dev); |
0c0e2c71 | 469 | |
f2abcfa6 LC |
470 | while (backoff->pwr) { |
471 | if (dflt_pwr_limit >= backoff->pwr) | |
472 | return backoff->backoff; | |
473 | ||
474 | backoff++; | |
0c0e2c71 IY |
475 | } |
476 | ||
477 | return 0; | |
478 | } | |
479 | ||
d3a108a4 AO |
480 | static void iwl_mvm_tx_unblock_dwork(struct work_struct *work) |
481 | { | |
482 | struct iwl_mvm *mvm = | |
483 | container_of(work, struct iwl_mvm, cs_tx_unblock_dwork.work); | |
484 | struct ieee80211_vif *tx_blocked_vif; | |
485 | struct iwl_mvm_vif *mvmvif; | |
486 | ||
487 | mutex_lock(&mvm->mutex); | |
488 | ||
489 | tx_blocked_vif = | |
490 | rcu_dereference_protected(mvm->csa_tx_blocked_vif, | |
491 | lockdep_is_held(&mvm->mutex)); | |
492 | ||
493 | if (!tx_blocked_vif) | |
494 | goto unlock; | |
495 | ||
496 | mvmvif = iwl_mvm_vif_from_mac80211(tx_blocked_vif); | |
497 | iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false); | |
498 | RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); | |
499 | unlock: | |
500 | mutex_unlock(&mvm->mutex); | |
501 | } | |
502 | ||
7174beb6 JB |
503 | static int iwl_mvm_fwrt_dump_start(void *ctx) |
504 | { | |
505 | struct iwl_mvm *mvm = ctx; | |
c7ab138e SM |
506 | |
507 | mutex_lock(&mvm->mutex); | |
7174beb6 | 508 | |
58d3bef4 | 509 | return 0; |
7174beb6 JB |
510 | } |
511 | ||
512 | static void iwl_mvm_fwrt_dump_end(void *ctx) | |
513 | { | |
514 | struct iwl_mvm *mvm = ctx; | |
515 | ||
c7ab138e | 516 | mutex_unlock(&mvm->mutex); |
7174beb6 JB |
517 | } |
518 | ||
8745f12a ST |
519 | static bool iwl_mvm_fwrt_fw_running(void *ctx) |
520 | { | |
521 | return iwl_mvm_firmware_running(ctx); | |
522 | } | |
523 | ||
d3f4b6de SM |
524 | static int iwl_mvm_fwrt_send_hcmd(void *ctx, struct iwl_host_cmd *host_cmd) |
525 | { | |
526 | struct iwl_mvm *mvm = (struct iwl_mvm *)ctx; | |
527 | int ret; | |
528 | ||
529 | mutex_lock(&mvm->mutex); | |
530 | ret = iwl_mvm_send_cmd(mvm, host_cmd); | |
531 | mutex_unlock(&mvm->mutex); | |
532 | ||
533 | return ret; | |
534 | } | |
535 | ||
971377e6 SM |
536 | static bool iwl_mvm_d3_debug_enable(void *ctx) |
537 | { | |
538 | return IWL_MVM_D3_DEBUG; | |
539 | } | |
540 | ||
7174beb6 JB |
541 | static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = { |
542 | .dump_start = iwl_mvm_fwrt_dump_start, | |
543 | .dump_end = iwl_mvm_fwrt_dump_end, | |
8745f12a | 544 | .fw_running = iwl_mvm_fwrt_fw_running, |
d3f4b6de | 545 | .send_hcmd = iwl_mvm_fwrt_send_hcmd, |
971377e6 | 546 | .d3_debug_enable = iwl_mvm_d3_debug_enable, |
7174beb6 JB |
547 | }; |
548 | ||
8ca151b5 JB |
549 | static struct iwl_op_mode * |
550 | iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg, | |
551 | const struct iwl_fw *fw, struct dentry *dbgfs_dir) | |
552 | { | |
553 | struct ieee80211_hw *hw; | |
554 | struct iwl_op_mode *op_mode; | |
555 | struct iwl_mvm *mvm; | |
556 | struct iwl_trans_config trans_cfg = {}; | |
557 | static const u8 no_reclaim_cmds[] = { | |
558 | TX_CMD, | |
559 | }; | |
560 | int err, scan_size; | |
0c0e2c71 | 561 | u32 min_backoff; |
034925cb | 562 | enum iwl_amsdu_size rb_size_default; |
8ca151b5 | 563 | |
c4d83271 | 564 | /* |
be9ae34e | 565 | * We use IWL_MVM_STATION_COUNT_MAX to check the validity of the station |
c4d83271 EG |
566 | * index all over the driver - check that its value corresponds to the |
567 | * array size. | |
568 | */ | |
be9ae34e NE |
569 | BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) != |
570 | IWL_MVM_STATION_COUNT_MAX); | |
c4d83271 | 571 | |
8ca151b5 JB |
572 | /******************************** |
573 | * 1. Allocating and configuring HW data | |
574 | ********************************/ | |
575 | hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) + | |
576 | sizeof(struct iwl_mvm), | |
577 | &iwl_mvm_hw_ops); | |
578 | if (!hw) | |
579 | return NULL; | |
580 | ||
49b7b35c | 581 | hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; |
745160ee | 582 | |
77d96730 GG |
583 | if (cfg->max_tx_agg_size) |
584 | hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size; | |
1eda295f JB |
585 | else |
586 | hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; | |
77d96730 | 587 | |
8ca151b5 | 588 | op_mode = hw->priv; |
8ca151b5 JB |
589 | |
590 | mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
591 | mvm->dev = trans->dev; | |
592 | mvm->trans = trans; | |
593 | mvm->cfg = cfg; | |
594 | mvm->fw = fw; | |
595 | mvm->hw = hw; | |
596 | ||
93b167c1 MG |
597 | iwl_fw_runtime_init(&mvm->fwrt, trans, fw, &iwl_mvm_fwrt_ops, mvm, |
598 | dbgfs_dir); | |
235acb18 | 599 | |
de8ba41b LK |
600 | mvm->init_status = 0; |
601 | ||
0316d30e JB |
602 | if (iwl_mvm_has_new_rx_api(mvm)) { |
603 | op_mode->ops = &iwl_mvm_ops_mq; | |
18ead597 | 604 | trans->rx_mpdu_cmd_hdr_size = |
286ca8eb | 605 | (trans->trans_cfg->device_family >= |
3681021f | 606 | IWL_DEVICE_FAMILY_AX210) ? |
18ead597 GBA |
607 | sizeof(struct iwl_rx_mpdu_desc) : |
608 | IWL_RX_DESC_SIZE_V1; | |
0316d30e JB |
609 | } else { |
610 | op_mode->ops = &iwl_mvm_ops; | |
25c2b22c SS |
611 | trans->rx_mpdu_cmd_hdr_size = |
612 | sizeof(struct iwl_rx_mpdu_res_start); | |
0316d30e JB |
613 | |
614 | if (WARN_ON(trans->num_rx_queues > 1)) | |
615 | goto out_free; | |
616 | } | |
617 | ||
3b37f4c9 | 618 | mvm->fw_restart = iwlwifi_mod_params.fw_restart ? -1 : 0; |
291aa7c4 | 619 | |
c8f54701 | 620 | mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE; |
b13f43a4 | 621 | mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE; |
c8f54701 JB |
622 | mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; |
623 | mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; | |
624 | ||
1f3b0ff8 | 625 | mvm->sf_state = SF_UNINIT; |
7d6222e2 | 626 | if (iwl_mvm_has_unified_ucode(mvm)) |
702e975d | 627 | iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_REGULAR); |
1f370650 | 628 | else |
702e975d | 629 | iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_INIT); |
c89e333d | 630 | mvm->drop_bcn_ap_mode = true; |
19e737c9 | 631 | |
8ca151b5 JB |
632 | mutex_init(&mvm->mutex); |
633 | spin_lock_init(&mvm->async_handlers_lock); | |
634 | INIT_LIST_HEAD(&mvm->time_event_list); | |
b112889c | 635 | INIT_LIST_HEAD(&mvm->aux_roc_te_list); |
8ca151b5 JB |
636 | INIT_LIST_HEAD(&mvm->async_handlers_list); |
637 | spin_lock_init(&mvm->time_event_lock); | |
fc36ffda | 638 | INIT_LIST_HEAD(&mvm->ftm_initiator.loc_list); |
0739a7d7 | 639 | INIT_LIST_HEAD(&mvm->ftm_initiator.pasn_list); |
be82ecd3 | 640 | INIT_LIST_HEAD(&mvm->resp_pasn_list); |
8ca151b5 JB |
641 | |
642 | INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk); | |
643 | INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk); | |
1d3c3f63 | 644 | INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work); |
69e04642 | 645 | INIT_DELAYED_WORK(&mvm->scan_timeout_dwork, iwl_mvm_scan_timeout_wk); |
24afba76 | 646 | INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk); |
cfbc6c4c | 647 | INIT_LIST_HEAD(&mvm->add_stream_txqs); |
8ca151b5 | 648 | |
3a732c65 | 649 | init_waitqueue_head(&mvm->rx_sync_waitq); |
b2492501 | 650 | |
2f7a04c7 | 651 | mvm->queue_sync_state = 0; |
0636b938 | 652 | |
8ca151b5 JB |
653 | SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev); |
654 | ||
7d9d0d56 LC |
655 | spin_lock_init(&mvm->tcm.lock); |
656 | INIT_DELAYED_WORK(&mvm->tcm.work, iwl_mvm_tcm_work); | |
657 | mvm->tcm.ts = jiffies; | |
658 | mvm->tcm.ll_ts = jiffies; | |
659 | mvm->tcm.uapsd_nonagg_ts = jiffies; | |
660 | ||
d3a108a4 AO |
661 | INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork); |
662 | ||
d3b4dc01 | 663 | mvm->cmd_ver.d0i3_resp = |
4af11950 MG |
664 | iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, D0I3_END_CMD, |
665 | 0); | |
d3b4dc01 HD |
666 | /* we only support version 1 */ |
667 | if (WARN_ON_ONCE(mvm->cmd_ver.d0i3_resp > 1)) | |
668 | goto out_free; | |
669 | ||
1c096d89 AS |
670 | mvm->cmd_ver.range_resp = |
671 | iwl_fw_lookup_notif_ver(mvm->fw, LOCATION_GROUP, | |
672 | TOF_RANGE_RESPONSE_NOTIF, 5); | |
673 | /* we only support up to version 8 */ | |
674 | if (WARN_ON_ONCE(mvm->cmd_ver.range_resp > 8)) | |
675 | goto out_free; | |
676 | ||
8ca151b5 JB |
677 | /* |
678 | * Populate the state variables that the transport layer needs | |
679 | * to know about. | |
680 | */ | |
681 | trans_cfg.op_mode = op_mode; | |
682 | trans_cfg.no_reclaim_cmds = no_reclaim_cmds; | |
683 | trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds); | |
034925cb | 684 | |
3681021f | 685 | if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) |
034925cb ST |
686 | rb_size_default = IWL_AMSDU_2K; |
687 | else | |
688 | rb_size_default = IWL_AMSDU_4K; | |
689 | ||
6c4fbcbc | 690 | switch (iwlwifi_mod_params.amsdu_size) { |
4bdd4dfe | 691 | case IWL_AMSDU_DEF: |
034925cb ST |
692 | trans_cfg.rx_buf_size = rb_size_default; |
693 | break; | |
6c4fbcbc EG |
694 | case IWL_AMSDU_4K: |
695 | trans_cfg.rx_buf_size = IWL_AMSDU_4K; | |
696 | break; | |
697 | case IWL_AMSDU_8K: | |
698 | trans_cfg.rx_buf_size = IWL_AMSDU_8K; | |
699 | break; | |
700 | case IWL_AMSDU_12K: | |
701 | trans_cfg.rx_buf_size = IWL_AMSDU_12K; | |
702 | break; | |
703 | default: | |
704 | pr_err("%s: Unsupported amsdu_size: %d\n", KBUILD_MODNAME, | |
705 | iwlwifi_mod_params.amsdu_size); | |
034925cb | 706 | trans_cfg.rx_buf_size = rb_size_default; |
6c4fbcbc | 707 | } |
4bdd4dfe | 708 | |
b7d96bca | 709 | trans->wide_cmd_header = true; |
2a182fbb | 710 | trans_cfg.bc_table_dword = |
3681021f | 711 | mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210; |
8ca151b5 | 712 | |
39bdb17e SD |
713 | trans_cfg.command_groups = iwl_mvm_groups; |
714 | trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups); | |
8ca151b5 | 715 | |
c8f54701 | 716 | trans_cfg.cmd_queue = IWL_MVM_DQA_CMD_QUEUE; |
b2d81db7 | 717 | trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD; |
3a736bcb | 718 | trans_cfg.scd_set_active = true; |
8ca151b5 | 719 | |
21cb3222 JB |
720 | trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info, |
721 | driver_data[2]); | |
722 | ||
4cf677fd EG |
723 | /* Set a short watchdog for the command queue */ |
724 | trans_cfg.cmd_q_wdg_timeout = | |
5d42e7b2 | 725 | iwl_mvm_get_wd_timeout(mvm, NULL, false, true); |
4cf677fd | 726 | |
8ca151b5 JB |
727 | snprintf(mvm->hw->wiphy->fw_version, |
728 | sizeof(mvm->hw->wiphy->fw_version), | |
729 | "%s", fw->fw_version); | |
730 | ||
906d4eb8 JB |
731 | trans_cfg.fw_reset_handshake = fw_has_capa(&mvm->fw->ucode_capa, |
732 | IWL_UCODE_TLV_CAPA_FW_RESET_HANDSHAKE); | |
733 | ||
8ca151b5 JB |
734 | /* Configure transport layer */ |
735 | iwl_trans_configure(mvm->trans, &trans_cfg); | |
736 | ||
737 | trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD; | |
91c28b83 SM |
738 | trans->dbg.dest_tlv = mvm->fw->dbg.dest_tlv; |
739 | trans->dbg.n_dest_reg = mvm->fw->dbg.n_dest_reg; | |
740 | memcpy(trans->dbg.conf_tlv, mvm->fw->dbg.conf_tlv, | |
741 | sizeof(trans->dbg.conf_tlv)); | |
742 | trans->dbg.trigger_tlv = mvm->fw->dbg.trigger_tlv; | |
8ca151b5 | 743 | |
132db31c GBA |
744 | trans->iml = mvm->fw->iml; |
745 | trans->iml_len = mvm->fw->iml_len; | |
746 | ||
8ca151b5 JB |
747 | /* set up notification wait support */ |
748 | iwl_notification_wait_init(&mvm->notif_wait); | |
749 | ||
750 | /* Init phy db */ | |
751 | mvm->phy_db = iwl_phy_db_init(trans); | |
752 | if (!mvm->phy_db) { | |
753 | IWL_ERR(mvm, "Cannot init phy_db\n"); | |
754 | goto out_free; | |
755 | } | |
756 | ||
757 | IWL_INFO(mvm, "Detected %s, REV=0x%X\n", | |
0b295a1e | 758 | mvm->trans->name, mvm->trans->hw_rev); |
8ca151b5 | 759 | |
4fb06283 | 760 | if (iwlwifi_mod_params.nvm_file) |
e02a9d60 | 761 | mvm->nvm_file_name = iwlwifi_mod_params.nvm_file; |
4fb06283 EH |
762 | else |
763 | IWL_DEBUG_EEPROM(mvm->trans->dev, | |
764 | "working without external nvm file\n"); | |
9ee718aa | 765 | |
56f2929b SS |
766 | err = iwl_trans_start_hw(mvm->trans); |
767 | if (err) | |
14b485f0 EH |
768 | goto out_free; |
769 | ||
56f2929b | 770 | mutex_lock(&mvm->mutex); |
3b25f1af | 771 | err = iwl_run_init_mvm_ucode(mvm); |
72d3c7bb | 772 | if (err && err != -ERFKILL) |
700b3799 | 773 | iwl_fw_dbg_error_collect(&mvm->fwrt, FW_DBG_TRIGGER_DRIVER); |
f4744258 | 774 | if (!iwlmvm_mod_params.init_dbg || !err) |
56f2929b | 775 | iwl_mvm_stop_device(mvm); |
56f2929b | 776 | mutex_unlock(&mvm->mutex); |
de8ba41b | 777 | if (err < 0) { |
56f2929b SS |
778 | IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", err); |
779 | goto out_free; | |
8ca151b5 JB |
780 | } |
781 | ||
d2496221 | 782 | scan_size = iwl_mvm_scan_size(mvm); |
fb98be5e | 783 | |
8ca151b5 JB |
784 | mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL); |
785 | if (!mvm->scan_cmd) | |
786 | goto out_free; | |
787 | ||
5a4b2afa HD |
788 | /* Set EBS as successful as long as not stated otherwise by the FW. */ |
789 | mvm->last_ebs_successful = true; | |
790 | ||
8ca151b5 JB |
791 | err = iwl_mvm_mac_setup_register(mvm); |
792 | if (err) | |
793 | goto out_free; | |
1f370650 | 794 | mvm->hw_registered = true; |
8ca151b5 | 795 | |
f2abcfa6 | 796 | min_backoff = iwl_mvm_min_backoff(mvm); |
04ddc2aa CRI |
797 | iwl_mvm_thermal_initialize(mvm, min_backoff); |
798 | ||
c9af7528 | 799 | iwl_mvm_dbgfs_register(mvm, dbgfs_dir); |
8ca151b5 | 800 | |
678d9b6d LK |
801 | if (!iwl_mvm_has_new_rx_stats_api(mvm)) |
802 | memset(&mvm->rx_stats_v3, 0, | |
803 | sizeof(struct mvm_statistics_rx_v3)); | |
804 | else | |
805 | memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx)); | |
3848ab66 | 806 | |
656fca00 AS |
807 | iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx); |
808 | ||
8ca151b5 JB |
809 | return op_mode; |
810 | ||
8ca151b5 | 811 | out_free: |
c7ab138e | 812 | iwl_fw_flush_dumps(&mvm->fwrt); |
54f3f994 | 813 | iwl_fw_runtime_free(&mvm->fwrt); |
de8ba41b LK |
814 | |
815 | if (iwlmvm_mod_params.init_dbg) | |
816 | return op_mode; | |
8ca151b5 JB |
817 | iwl_phy_db_free(mvm->phy_db); |
818 | kfree(mvm->scan_cmd); | |
56f2929b SS |
819 | iwl_trans_op_mode_leave(trans); |
820 | ||
8ca151b5 JB |
821 | ieee80211_free_hw(mvm->hw); |
822 | return NULL; | |
823 | } | |
824 | ||
cf5b4627 JB |
825 | void iwl_mvm_stop_device(struct iwl_mvm *mvm) |
826 | { | |
827 | lockdep_assert_held(&mvm->mutex); | |
828 | ||
829 | iwl_fw_cancel_timestamp(&mvm->fwrt); | |
830 | ||
831 | clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); | |
832 | ||
833 | iwl_fw_dbg_stop_sync(&mvm->fwrt); | |
834 | iwl_trans_stop_device(mvm->trans); | |
835 | iwl_free_fw_paging(&mvm->fwrt); | |
836 | iwl_fw_dump_conf_clear(&mvm->fwrt); | |
837 | } | |
838 | ||
8ca151b5 JB |
839 | static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode) |
840 | { | |
841 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
842 | int i; | |
843 | ||
844 | iwl_mvm_leds_exit(mvm); | |
845 | ||
c221daf2 | 846 | iwl_mvm_thermal_exit(mvm); |
9ee718aa | 847 | |
cad7eb75 | 848 | ieee80211_unregister_hw(mvm->hw); |
8ca151b5 JB |
849 | |
850 | kfree(mvm->scan_cmd); | |
e59647ea EP |
851 | kfree(mvm->mcast_filter_cmd); |
852 | mvm->mcast_filter_cmd = NULL; | |
8ca151b5 | 853 | |
f130bb75 MG |
854 | kfree(mvm->error_recovery_buf); |
855 | mvm->error_recovery_buf = NULL; | |
856 | ||
a4082843 | 857 | iwl_trans_op_mode_leave(mvm->trans); |
8ca151b5 JB |
858 | |
859 | iwl_phy_db_free(mvm->phy_db); | |
860 | mvm->phy_db = NULL; | |
861 | ||
1dad3e0a | 862 | kfree(mvm->nvm_data); |
ae2b21b0 | 863 | for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++) |
8ca151b5 JB |
864 | kfree(mvm->nvm_sections[i].data); |
865 | ||
7d9d0d56 LC |
866 | cancel_delayed_work_sync(&mvm->tcm.work); |
867 | ||
54f3f994 | 868 | iwl_fw_runtime_free(&mvm->fwrt); |
a2a57a35 | 869 | mutex_destroy(&mvm->mutex); |
a2a57a35 | 870 | |
8ca151b5 JB |
871 | ieee80211_free_hw(mvm->hw); |
872 | } | |
873 | ||
874 | struct iwl_async_handler_entry { | |
875 | struct list_head list; | |
876 | struct iwl_rx_cmd_buffer rxb; | |
c9cb14a6 | 877 | enum iwl_rx_handler_context context; |
0416841d | 878 | void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb); |
8ca151b5 JB |
879 | }; |
880 | ||
881 | void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm) | |
882 | { | |
883 | struct iwl_async_handler_entry *entry, *tmp; | |
884 | ||
885 | spin_lock_bh(&mvm->async_handlers_lock); | |
886 | list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) { | |
887 | iwl_free_rxb(&entry->rxb); | |
888 | list_del(&entry->list); | |
889 | kfree(entry); | |
890 | } | |
891 | spin_unlock_bh(&mvm->async_handlers_lock); | |
892 | } | |
893 | ||
894 | static void iwl_mvm_async_handlers_wk(struct work_struct *wk) | |
895 | { | |
896 | struct iwl_mvm *mvm = | |
897 | container_of(wk, struct iwl_mvm, async_handlers_wk); | |
898 | struct iwl_async_handler_entry *entry, *tmp; | |
8098203f | 899 | LIST_HEAD(local_list); |
8ca151b5 JB |
900 | |
901 | /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */ | |
8ca151b5 JB |
902 | |
903 | /* | |
904 | * Sync with Rx path with a lock. Remove all the entries from this list, | |
905 | * add them to a local one (lock free), and then handle them. | |
906 | */ | |
907 | spin_lock_bh(&mvm->async_handlers_lock); | |
908 | list_splice_init(&mvm->async_handlers_list, &local_list); | |
909 | spin_unlock_bh(&mvm->async_handlers_lock); | |
910 | ||
911 | list_for_each_entry_safe(entry, tmp, &local_list, list) { | |
c9cb14a6 CRI |
912 | if (entry->context == RX_HANDLER_ASYNC_LOCKED) |
913 | mutex_lock(&mvm->mutex); | |
0416841d | 914 | entry->fn(mvm, &entry->rxb); |
8ca151b5 JB |
915 | iwl_free_rxb(&entry->rxb); |
916 | list_del(&entry->list); | |
c9cb14a6 CRI |
917 | if (entry->context == RX_HANDLER_ASYNC_LOCKED) |
918 | mutex_unlock(&mvm->mutex); | |
8ca151b5 JB |
919 | kfree(entry); |
920 | } | |
8ca151b5 JB |
921 | } |
922 | ||
917f39bb EG |
923 | static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm, |
924 | struct iwl_rx_packet *pkt) | |
925 | { | |
926 | struct iwl_fw_dbg_trigger_tlv *trig; | |
927 | struct iwl_fw_dbg_trigger_cmd *cmds_trig; | |
917f39bb EG |
928 | int i; |
929 | ||
6c042d75 SS |
930 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL, |
931 | FW_DBG_TRIGGER_FW_NOTIF); | |
932 | if (!trig) | |
917f39bb EG |
933 | return; |
934 | ||
917f39bb EG |
935 | cmds_trig = (void *)trig->data; |
936 | ||
917f39bb EG |
937 | for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) { |
938 | /* don't collect on CMD 0 */ | |
939 | if (!cmds_trig->cmds[i].cmd_id) | |
940 | break; | |
941 | ||
0ab66e6d SS |
942 | if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd || |
943 | cmds_trig->cmds[i].group_id != pkt->hdr.group_id) | |
917f39bb EG |
944 | continue; |
945 | ||
7174beb6 JB |
946 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, |
947 | "CMD 0x%02x.%02x received", | |
948 | pkt->hdr.group_id, pkt->hdr.cmd); | |
917f39bb EG |
949 | break; |
950 | } | |
951 | } | |
952 | ||
0316d30e JB |
953 | static void iwl_mvm_rx_common(struct iwl_mvm *mvm, |
954 | struct iwl_rx_cmd_buffer *rxb, | |
955 | struct iwl_rx_packet *pkt) | |
8ca151b5 | 956 | { |
0316d30e | 957 | int i; |
b108d8c7 | 958 | union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt }; |
1738d60b | 959 | |
b108d8c7 SM |
960 | iwl_dbg_tlv_time_point(&mvm->fwrt, |
961 | IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF, &tp_data); | |
917f39bb EG |
962 | iwl_mvm_rx_check_trigger(mvm, pkt); |
963 | ||
8ca151b5 JB |
964 | /* |
965 | * Do the notification wait before RX handlers so | |
966 | * even if the RX handler consumes the RXB we have | |
967 | * access to it in the notification wait entry. | |
968 | */ | |
969 | iwl_notification_wait_notify(&mvm->notif_wait, pkt); | |
970 | ||
971 | for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) { | |
972 | const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i]; | |
36eed56a EG |
973 | struct iwl_async_handler_entry *entry; |
974 | ||
1230b16b | 975 | if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd)) |
36eed56a EG |
976 | continue; |
977 | ||
c9cb14a6 | 978 | if (rx_h->context == RX_HANDLER_SYNC) { |
0416841d | 979 | rx_h->fn(mvm, rxb); |
f7e6469f | 980 | return; |
0416841d | 981 | } |
36eed56a EG |
982 | |
983 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); | |
984 | /* we can't do much... */ | |
985 | if (!entry) | |
f7e6469f | 986 | return; |
36eed56a EG |
987 | |
988 | entry->rxb._page = rxb_steal_page(rxb); | |
989 | entry->rxb._offset = rxb->_offset; | |
990 | entry->rxb._rx_page_order = rxb->_rx_page_order; | |
991 | entry->fn = rx_h->fn; | |
c9cb14a6 | 992 | entry->context = rx_h->context; |
36eed56a EG |
993 | spin_lock(&mvm->async_handlers_lock); |
994 | list_add_tail(&entry->list, &mvm->async_handlers_list); | |
995 | spin_unlock(&mvm->async_handlers_lock); | |
996 | schedule_work(&mvm->async_handlers_wk); | |
07fb3299 | 997 | break; |
8ca151b5 | 998 | } |
8ca151b5 JB |
999 | } |
1000 | ||
0316d30e JB |
1001 | static void iwl_mvm_rx(struct iwl_op_mode *op_mode, |
1002 | struct napi_struct *napi, | |
1003 | struct iwl_rx_cmd_buffer *rxb) | |
1004 | { | |
1005 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
1006 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
61b0f5d7 | 1007 | u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd); |
0316d30e | 1008 | |
61b0f5d7 | 1009 | if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))) |
0316d30e | 1010 | iwl_mvm_rx_rx_mpdu(mvm, napi, rxb); |
61b0f5d7 | 1011 | else if (cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_PHY_CMD)) |
0316d30e JB |
1012 | iwl_mvm_rx_rx_phy_cmd(mvm, rxb); |
1013 | else | |
1014 | iwl_mvm_rx_common(mvm, rxb, pkt); | |
1015 | } | |
1016 | ||
1017 | static void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode, | |
1018 | struct napi_struct *napi, | |
1019 | struct iwl_rx_cmd_buffer *rxb) | |
1020 | { | |
1021 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
1022 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
61b0f5d7 | 1023 | u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd); |
0316d30e | 1024 | |
61b0f5d7 | 1025 | if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))) |
780e87c2 | 1026 | iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0); |
61b0f5d7 JB |
1027 | else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP, |
1028 | RX_QUEUES_NOTIFICATION))) | |
c61b655a | 1029 | iwl_mvm_rx_queue_notif(mvm, napi, rxb, 0); |
61b0f5d7 | 1030 | else if (cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)) |
58035432 | 1031 | iwl_mvm_rx_frame_release(mvm, napi, rxb, 0); |
fe69b7d1 JB |
1032 | else if (cmd == WIDE_ID(LEGACY_GROUP, BAR_FRAME_RELEASE)) |
1033 | iwl_mvm_rx_bar_frame_release(mvm, napi, rxb, 0); | |
bf9dfeda | 1034 | else if (cmd == WIDE_ID(DATA_PATH_GROUP, RX_NO_DATA_NOTIF)) |
d47cdb88 | 1035 | iwl_mvm_rx_monitor_no_data(mvm, napi, rxb, 0); |
0316d30e JB |
1036 | else |
1037 | iwl_mvm_rx_common(mvm, rxb, pkt); | |
1038 | } | |
1039 | ||
156f92f2 EG |
1040 | static void iwl_mvm_async_cb(struct iwl_op_mode *op_mode, |
1041 | const struct iwl_device_cmd *cmd) | |
1042 | { | |
1043 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
1044 | ||
1045 | /* | |
1046 | * For now, we only set the CMD_WANT_ASYNC_CALLBACK for ADD_STA | |
1047 | * commands that need to block the Tx queues. | |
1048 | */ | |
1049 | iwl_trans_block_txq_ptrs(mvm->trans, false); | |
1050 | } | |
1051 | ||
99944b73 AS |
1052 | static int iwl_mvm_is_static_queue(struct iwl_mvm *mvm, int queue) |
1053 | { | |
1054 | return queue == mvm->aux_queue || queue == mvm->probe_queue || | |
1055 | queue == mvm->p2p_dev_queue || queue == mvm->snif_queue; | |
1056 | } | |
1057 | ||
cfbc6c4c SS |
1058 | static void iwl_mvm_queue_state_change(struct iwl_op_mode *op_mode, |
1059 | int hw_queue, bool start) | |
8ca151b5 JB |
1060 | { |
1061 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
cfbc6c4c SS |
1062 | struct ieee80211_sta *sta; |
1063 | struct ieee80211_txq *txq; | |
1064 | struct iwl_mvm_txq *mvmtxq; | |
1065 | int i; | |
1066 | unsigned long tid_bitmap; | |
1067 | struct iwl_mvm_sta *mvmsta; | |
1068 | u8 sta_id; | |
b4f7a9d1 | 1069 | |
cfbc6c4c SS |
1070 | sta_id = iwl_mvm_has_new_tx_api(mvm) ? |
1071 | mvm->tvqm_info[hw_queue].sta_id : | |
1072 | mvm->queue_info[hw_queue].ra_sta_id; | |
b4f7a9d1 | 1073 | |
be9ae34e | 1074 | if (WARN_ON_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations)) |
8ca151b5 | 1075 | return; |
8ca151b5 | 1076 | |
cfbc6c4c SS |
1077 | rcu_read_lock(); |
1078 | ||
1079 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
1080 | if (IS_ERR_OR_NULL(sta)) | |
1081 | goto out; | |
1082 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
1083 | ||
99944b73 AS |
1084 | if (iwl_mvm_is_static_queue(mvm, hw_queue)) { |
1085 | if (!start) | |
1086 | ieee80211_stop_queues(mvm->hw); | |
1087 | else if (mvmsta->sta_state != IEEE80211_STA_NOTEXIST) | |
1088 | ieee80211_wake_queues(mvm->hw); | |
1089 | ||
1090 | goto out; | |
1091 | } | |
1092 | ||
cfbc6c4c SS |
1093 | if (iwl_mvm_has_new_tx_api(mvm)) { |
1094 | int tid = mvm->tvqm_info[hw_queue].txq_tid; | |
1095 | ||
1096 | tid_bitmap = BIT(tid); | |
1097 | } else { | |
1098 | tid_bitmap = mvm->queue_info[hw_queue].tid_bitmap; | |
1099 | } | |
1100 | ||
1101 | for_each_set_bit(i, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { | |
1102 | int tid = i; | |
1103 | ||
1104 | if (tid == IWL_MAX_TID_COUNT) | |
1105 | tid = IEEE80211_NUM_TIDS; | |
4ecafae9 | 1106 | |
cfbc6c4c SS |
1107 | txq = sta->txq[tid]; |
1108 | mvmtxq = iwl_mvm_txq_from_mac80211(txq); | |
1109 | mvmtxq->stopped = !start; | |
1110 | ||
1111 | if (start && mvmsta->sta_state != IEEE80211_STA_NOTEXIST) | |
1112 | iwl_mvm_mac_itxq_xmit(mvm->hw, txq); | |
4ecafae9 | 1113 | } |
cfbc6c4c SS |
1114 | |
1115 | out: | |
1116 | rcu_read_unlock(); | |
8ca151b5 JB |
1117 | } |
1118 | ||
cfbc6c4c | 1119 | static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue) |
b4f7a9d1 | 1120 | { |
cfbc6c4c SS |
1121 | iwl_mvm_queue_state_change(op_mode, hw_queue, false); |
1122 | } | |
b4f7a9d1 | 1123 | |
cfbc6c4c SS |
1124 | static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue) |
1125 | { | |
1126 | iwl_mvm_queue_state_change(op_mode, hw_queue, true); | |
b4f7a9d1 LK |
1127 | } |
1128 | ||
6ad04359 JB |
1129 | static void iwl_mvm_set_rfkill_state(struct iwl_mvm *mvm) |
1130 | { | |
1131 | bool state = iwl_mvm_is_radio_killed(mvm); | |
1132 | ||
1133 | if (state) | |
1134 | wake_up(&mvm->rx_sync_waitq); | |
1135 | ||
1136 | wiphy_rfkill_set_hw_state(mvm->hw->wiphy, state); | |
1137 | } | |
1138 | ||
9ee718aa EL |
1139 | void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state) |
1140 | { | |
1141 | if (state) | |
1142 | set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status); | |
1143 | else | |
1144 | clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status); | |
1145 | ||
6ad04359 | 1146 | iwl_mvm_set_rfkill_state(mvm); |
9ee718aa EL |
1147 | } |
1148 | ||
14cfca71 | 1149 | static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state) |
8ca151b5 JB |
1150 | { |
1151 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
b3500b47 EG |
1152 | bool rfkill_safe_init_done = READ_ONCE(mvm->rfkill_safe_init_done); |
1153 | bool unified = iwl_mvm_has_unified_ucode(mvm); | |
8ca151b5 JB |
1154 | |
1155 | if (state) | |
1156 | set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status); | |
1157 | else | |
1158 | clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status); | |
1159 | ||
6ad04359 | 1160 | iwl_mvm_set_rfkill_state(mvm); |
14cfca71 | 1161 | |
b3500b47 EG |
1162 | /* iwl_run_init_mvm_ucode is waiting for results, abort it. */ |
1163 | if (rfkill_safe_init_done) | |
31b8b343 EG |
1164 | iwl_abort_notification_waits(&mvm->notif_wait); |
1165 | ||
b3500b47 EG |
1166 | /* |
1167 | * Don't ask the transport to stop the firmware. We'll do it | |
1168 | * after cfg80211 takes us down. | |
1169 | */ | |
1170 | if (unified) | |
1171 | return false; | |
1172 | ||
31b8b343 EG |
1173 | /* |
1174 | * Stop the device if we run OPERATIONAL firmware or if we are in the | |
1175 | * middle of the calibrations. | |
1176 | */ | |
07c89a60 | 1177 | return state && rfkill_safe_init_done; |
8ca151b5 JB |
1178 | } |
1179 | ||
1180 | static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb) | |
1181 | { | |
1182 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
1183 | struct ieee80211_tx_info *info; | |
1184 | ||
1185 | info = IEEE80211_SKB_CB(skb); | |
1186 | iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); | |
1187 | ieee80211_free_txskb(mvm->hw, skb); | |
1188 | } | |
1189 | ||
ac1ed416 JB |
1190 | struct iwl_mvm_reprobe { |
1191 | struct device *dev; | |
1192 | struct work_struct work; | |
1193 | }; | |
1194 | ||
1195 | static void iwl_mvm_reprobe_wk(struct work_struct *wk) | |
1196 | { | |
1197 | struct iwl_mvm_reprobe *reprobe; | |
1198 | ||
1199 | reprobe = container_of(wk, struct iwl_mvm_reprobe, work); | |
1200 | if (device_reprobe(reprobe->dev)) | |
1201 | dev_err(reprobe->dev, "reprobe failed!\n"); | |
1202 | kfree(reprobe); | |
1203 | module_put(THIS_MODULE); | |
1204 | } | |
1205 | ||
b08c1d97 | 1206 | void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error) |
8ca151b5 | 1207 | { |
8ca151b5 | 1208 | iwl_abort_notification_waits(&mvm->notif_wait); |
9b1bcfcc | 1209 | iwl_dbg_tlv_del_timers(mvm->trans); |
8ca151b5 | 1210 | |
992f81fc DS |
1211 | /* |
1212 | * This is a bit racy, but worst case we tell mac80211 about | |
1213 | * a stopped/aborted scan when that was already done which | |
1214 | * is not a problem. It is necessary to abort any os scan | |
1215 | * here because mac80211 requires having the scan cleared | |
1216 | * before restarting. | |
1217 | * We'll reset the scan_status to NONE in restart cleanup in | |
1218 | * the next start() call from mac80211. If restart isn't called | |
1219 | * (no fw restart) scan status will stay busy. | |
1220 | */ | |
4ffb3650 | 1221 | iwl_mvm_report_scan_aborted(mvm); |
992f81fc | 1222 | |
8ca151b5 JB |
1223 | /* |
1224 | * If we're restarting already, don't cycle restarts. | |
1225 | * If INIT fw asserted, it will likely fail again. | |
1226 | * If WoWLAN fw asserted, don't restart either, mac80211 | |
1227 | * can't recover this since we're already half suspended. | |
1228 | */ | |
3b37f4c9 | 1229 | if (!mvm->fw_restart && fw_error) { |
4b1831e4 | 1230 | iwl_fw_error_collect(&mvm->fwrt); |
bf8b286f | 1231 | } else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
ac1ed416 JB |
1232 | struct iwl_mvm_reprobe *reprobe; |
1233 | ||
1234 | IWL_ERR(mvm, | |
1235 | "Firmware error during reconfiguration - reprobe!\n"); | |
1236 | ||
1237 | /* | |
1238 | * get a module reference to avoid doing this while unloading | |
1239 | * anyway and to avoid scheduling a work with code that's | |
1240 | * being removed. | |
1241 | */ | |
1242 | if (!try_module_get(THIS_MODULE)) { | |
1243 | IWL_ERR(mvm, "Module is being unloaded - abort\n"); | |
1244 | return; | |
1245 | } | |
1246 | ||
1247 | reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC); | |
1248 | if (!reprobe) { | |
1249 | module_put(THIS_MODULE); | |
1250 | return; | |
1251 | } | |
1252 | reprobe->dev = mvm->trans->dev; | |
1253 | INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk); | |
1254 | schedule_work(&reprobe->work); | |
1e78e759 IP |
1255 | } else if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, |
1256 | &mvm->status)) { | |
1257 | IWL_ERR(mvm, "HW restart already requested, but not started\n"); | |
702e975d | 1258 | } else if (mvm->fwrt.cur_fw_img == IWL_UCODE_REGULAR && |
f60c9e59 EG |
1259 | mvm->hw_registered && |
1260 | !test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) { | |
861bae42 MG |
1261 | /* This should be first thing before trying to collect any |
1262 | * data to avoid endless loops if any HW error happens while | |
1263 | * collecting debug data. | |
1264 | */ | |
1265 | set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); | |
1266 | ||
f130bb75 MG |
1267 | if (mvm->fw->ucode_capa.error_log_size) { |
1268 | u32 src_size = mvm->fw->ucode_capa.error_log_size; | |
1269 | u32 src_addr = mvm->fw->ucode_capa.error_log_addr; | |
1270 | u8 *recover_buf = kzalloc(src_size, GFP_ATOMIC); | |
1271 | ||
1272 | if (recover_buf) { | |
1273 | mvm->error_recovery_buf = recover_buf; | |
1274 | iwl_trans_read_mem_bytes(mvm->trans, | |
1275 | src_addr, | |
1276 | recover_buf, | |
1277 | src_size); | |
1278 | } | |
1279 | } | |
1280 | ||
4b1831e4 SM |
1281 | iwl_fw_error_collect(&mvm->fwrt); |
1282 | ||
3b37f4c9 JB |
1283 | if (fw_error && mvm->fw_restart > 0) |
1284 | mvm->fw_restart--; | |
8ca151b5 JB |
1285 | ieee80211_restart_hw(mvm->hw); |
1286 | } | |
1287 | } | |
1288 | ||
715c998f EG |
1289 | static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode) |
1290 | { | |
1291 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
1292 | ||
f60c9e59 EG |
1293 | if (!test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) |
1294 | iwl_mvm_dump_nic_error_log(mvm); | |
1bd3cbc1 | 1295 | |
b08c1d97 | 1296 | iwl_mvm_nic_restart(mvm, true); |
715c998f EG |
1297 | } |
1298 | ||
8ca151b5 JB |
1299 | static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode) |
1300 | { | |
715c998f EG |
1301 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); |
1302 | ||
8ca151b5 | 1303 | WARN_ON(1); |
b08c1d97 | 1304 | iwl_mvm_nic_restart(mvm, true); |
8ca151b5 JB |
1305 | } |
1306 | ||
0316d30e JB |
1307 | #define IWL_MVM_COMMON_OPS \ |
1308 | /* these could be differentiated */ \ | |
156f92f2 | 1309 | .async_cb = iwl_mvm_async_cb, \ |
0316d30e JB |
1310 | .queue_full = iwl_mvm_stop_sw_queue, \ |
1311 | .queue_not_full = iwl_mvm_wake_sw_queue, \ | |
1312 | .hw_rf_kill = iwl_mvm_set_hw_rfkill_state, \ | |
1313 | .free_skb = iwl_mvm_free_skb, \ | |
1314 | .nic_error = iwl_mvm_nic_error, \ | |
1315 | .cmd_queue_full = iwl_mvm_cmd_queue_full, \ | |
1316 | .nic_config = iwl_mvm_nic_config, \ | |
0316d30e JB |
1317 | /* as we only register one, these MUST be common! */ \ |
1318 | .start = iwl_op_mode_mvm_start, \ | |
1319 | .stop = iwl_op_mode_mvm_stop | |
1320 | ||
8ca151b5 | 1321 | static const struct iwl_op_mode_ops iwl_mvm_ops = { |
0316d30e JB |
1322 | IWL_MVM_COMMON_OPS, |
1323 | .rx = iwl_mvm_rx, | |
1324 | }; | |
1325 | ||
1326 | static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode, | |
1327 | struct napi_struct *napi, | |
1328 | struct iwl_rx_cmd_buffer *rxb, | |
1329 | unsigned int queue) | |
1330 | { | |
1331 | struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); | |
585a6fcc | 1332 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
61b0f5d7 | 1333 | u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd); |
0316d30e | 1334 | |
61b0f5d7 | 1335 | if (unlikely(cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))) |
a338384b | 1336 | iwl_mvm_rx_frame_release(mvm, napi, rxb, queue); |
61b0f5d7 JB |
1337 | else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP, |
1338 | RX_QUEUES_NOTIFICATION))) | |
c61b655a | 1339 | iwl_mvm_rx_queue_notif(mvm, napi, rxb, queue); |
61b0f5d7 | 1340 | else if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))) |
585a6fcc | 1341 | iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue); |
0316d30e JB |
1342 | } |
1343 | ||
1344 | static const struct iwl_op_mode_ops iwl_mvm_ops_mq = { | |
1345 | IWL_MVM_COMMON_OPS, | |
1346 | .rx = iwl_mvm_rx_mq, | |
1347 | .rx_rss = iwl_mvm_rx_mq_rss, | |
8ca151b5 | 1348 | }; |