1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3 * Copyright (C) 2024-2025 Intel Corporation
4 */
5 #include <linux/rtnetlink.h>
6 #include <net/mac80211.h>
7
8 #include "fw/api/rx.h"
9 #include "fw/api/datapath.h"
10 #include "fw/api/commands.h"
11 #include "fw/api/offload.h"
12 #include "fw/api/coex.h"
13 #include "fw/dbg.h"
14 #include "fw/uefi.h"
15
16 #include "mld.h"
17 #include "mlo.h"
18 #include "mac80211.h"
19 #include "led.h"
20 #include "scan.h"
21 #include "tx.h"
22 #include "sta.h"
23 #include "regulatory.h"
24 #include "thermal.h"
25 #include "low_latency.h"
26 #include "hcmd.h"
27 #include "fw/api/location.h"
28
29 #include "iwl-nvm-parse.h"
30
31 #define DRV_DESCRIPTION "Intel(R) MLD wireless driver for Linux"
32 MODULE_DESCRIPTION(DRV_DESCRIPTION);
33 MODULE_LICENSE("GPL");
34 MODULE_IMPORT_NS("IWLWIFI");
35
36 static const struct iwl_op_mode_ops iwl_mld_ops;
37
iwl_mld_init(void)38 static int __init iwl_mld_init(void)
39 {
40 int ret = iwl_opmode_register("iwlmld", &iwl_mld_ops);
41
42 if (ret)
43 pr_err("Unable to register MLD op_mode: %d\n", ret);
44
45 return ret;
46 }
47 module_init(iwl_mld_init);
48
iwl_mld_exit(void)49 static void __exit iwl_mld_exit(void)
50 {
51 iwl_opmode_deregister("iwlmld");
52 }
53 module_exit(iwl_mld_exit);
54
iwl_mld_hw_set_regulatory(struct iwl_mld * mld)55 static void iwl_mld_hw_set_regulatory(struct iwl_mld *mld)
56 {
57 struct wiphy *wiphy = mld->wiphy;
58
59 wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
60 wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
61 }
62
63 VISIBLE_IF_IWLWIFI_KUNIT
iwl_construct_mld(struct iwl_mld * mld,struct iwl_trans * trans,const struct iwl_rf_cfg * cfg,const struct iwl_fw * fw,struct ieee80211_hw * hw,struct dentry * dbgfs_dir)64 void iwl_construct_mld(struct iwl_mld *mld, struct iwl_trans *trans,
65 const struct iwl_rf_cfg *cfg, const struct iwl_fw *fw,
66 struct ieee80211_hw *hw, struct dentry *dbgfs_dir)
67 {
68 mld->dev = trans->dev;
69 mld->trans = trans;
70 mld->cfg = cfg;
71 mld->fw = fw;
72 mld->hw = hw;
73 mld->wiphy = hw->wiphy;
74 mld->debugfs_dir = dbgfs_dir;
75
76 iwl_notification_wait_init(&mld->notif_wait);
77
78 /* Setup async RX handling */
79 spin_lock_init(&mld->async_handlers_lock);
80 INIT_LIST_HEAD(&mld->async_handlers_list);
81 wiphy_work_init(&mld->async_handlers_wk,
82 iwl_mld_async_handlers_wk);
83
84 /* Dynamic Queue Allocation */
85 spin_lock_init(&mld->add_txqs_lock);
86 INIT_LIST_HEAD(&mld->txqs_to_add);
87 wiphy_work_init(&mld->add_txqs_wk, iwl_mld_add_txqs_wk);
88
89 /* Setup RX queues sync wait queue */
90 init_waitqueue_head(&mld->rxq_sync.waitq);
91 }
92 EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_construct_mld);
93
94 static void __acquires(&mld->wiphy->mtx)
iwl_mld_fwrt_dump_start(void * ctx)95 iwl_mld_fwrt_dump_start(void *ctx)
96 {
97 struct iwl_mld *mld = ctx;
98
99 wiphy_lock(mld->wiphy);
100 }
101
102 static void __releases(&mld->wiphy->mtx)
iwl_mld_fwrt_dump_end(void * ctx)103 iwl_mld_fwrt_dump_end(void *ctx)
104 {
105 struct iwl_mld *mld = ctx;
106
107 wiphy_unlock(mld->wiphy);
108 }
109
iwl_mld_d3_debug_enable(void * ctx)110 static bool iwl_mld_d3_debug_enable(void *ctx)
111 {
112 return IWL_MLD_D3_DEBUG;
113 }
114
iwl_mld_fwrt_send_hcmd(void * ctx,struct iwl_host_cmd * host_cmd)115 static int iwl_mld_fwrt_send_hcmd(void *ctx, struct iwl_host_cmd *host_cmd)
116 {
117 struct iwl_mld *mld = (struct iwl_mld *)ctx;
118 int ret;
119
120 wiphy_lock(mld->wiphy);
121 ret = iwl_mld_send_cmd(mld, host_cmd);
122 wiphy_unlock(mld->wiphy);
123
124 return ret;
125 }
126
127 static const struct iwl_fw_runtime_ops iwl_mld_fwrt_ops = {
128 .dump_start = iwl_mld_fwrt_dump_start,
129 .dump_end = iwl_mld_fwrt_dump_end,
130 .send_hcmd = iwl_mld_fwrt_send_hcmd,
131 .d3_debug_enable = iwl_mld_d3_debug_enable,
132 };
133
134 static void
iwl_mld_construct_fw_runtime(struct iwl_mld * mld,struct iwl_trans * trans,const struct iwl_fw * fw,struct dentry * debugfs_dir)135 iwl_mld_construct_fw_runtime(struct iwl_mld *mld, struct iwl_trans *trans,
136 const struct iwl_fw *fw,
137 struct dentry *debugfs_dir)
138 {
139 iwl_fw_runtime_init(&mld->fwrt, trans, fw, &iwl_mld_fwrt_ops, mld,
140 NULL, NULL, debugfs_dir);
141
142 iwl_fw_set_current_image(&mld->fwrt, IWL_UCODE_REGULAR);
143 }
144
145 /* Please keep this array *SORTED* by hex value.
146 * Access is done through binary search
147 */
148 static const struct iwl_hcmd_names iwl_mld_legacy_names[] = {
149 HCMD_NAME(UCODE_ALIVE_NTFY),
150 HCMD_NAME(INIT_COMPLETE_NOTIF),
151 HCMD_NAME(PHY_CONTEXT_CMD),
152 HCMD_NAME(SCAN_CFG_CMD),
153 HCMD_NAME(SCAN_REQ_UMAC),
154 HCMD_NAME(SCAN_ABORT_UMAC),
155 HCMD_NAME(SCAN_COMPLETE_UMAC),
156 HCMD_NAME(TX_CMD),
157 HCMD_NAME(TXPATH_FLUSH),
158 HCMD_NAME(LEDS_CMD),
159 HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_NOTIFICATION),
160 HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_CONFIRM_NOTIFICATION),
161 HCMD_NAME(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),
162 HCMD_NAME(POWER_TABLE_CMD),
163 HCMD_NAME(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION),
164 HCMD_NAME(BEACON_NOTIFICATION),
165 HCMD_NAME(BEACON_TEMPLATE_CMD),
166 HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
167 HCMD_NAME(REDUCE_TX_POWER_CMD),
168 HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
169 HCMD_NAME(MAC_PM_POWER_TABLE),
170 HCMD_NAME(MFUART_LOAD_NOTIFICATION),
171 HCMD_NAME(RSS_CONFIG_CMD),
172 HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC),
173 HCMD_NAME(REPLY_RX_MPDU_CMD),
174 HCMD_NAME(BA_NOTIF),
175 HCMD_NAME(MCC_UPDATE_CMD),
176 HCMD_NAME(MCC_CHUB_UPDATE_CMD),
177 HCMD_NAME(MCAST_FILTER_CMD),
178 HCMD_NAME(REPLY_BEACON_FILTERING_CMD),
179 HCMD_NAME(PROT_OFFLOAD_CONFIG_CMD),
180 HCMD_NAME(MATCH_FOUND_NOTIFICATION),
181 HCMD_NAME(WOWLAN_PATTERNS),
182 HCMD_NAME(WOWLAN_CONFIGURATION),
183 HCMD_NAME(WOWLAN_TSC_RSC_PARAM),
184 HCMD_NAME(WOWLAN_KEK_KCK_MATERIAL),
185 HCMD_NAME(DEBUG_HOST_COMMAND),
186 HCMD_NAME(LDBG_CONFIG_CMD),
187 };
188
189 /* Please keep this array *SORTED* by hex value.
190 * Access is done through binary search
191 */
192 static const struct iwl_hcmd_names iwl_mld_system_names[] = {
193 HCMD_NAME(SHARED_MEM_CFG_CMD),
194 HCMD_NAME(SOC_CONFIGURATION_CMD),
195 HCMD_NAME(INIT_EXTENDED_CFG_CMD),
196 HCMD_NAME(FW_ERROR_RECOVERY_CMD),
197 HCMD_NAME(RFI_CONFIG_CMD),
198 HCMD_NAME(RFI_GET_FREQ_TABLE_CMD),
199 HCMD_NAME(SYSTEM_STATISTICS_CMD),
200 HCMD_NAME(SYSTEM_STATISTICS_END_NOTIF),
201 };
202
203 /* Please keep this array *SORTED* by hex value.
204 * Access is done through binary search
205 */
206 static const struct iwl_hcmd_names iwl_mld_reg_and_nvm_names[] = {
207 HCMD_NAME(LARI_CONFIG_CHANGE),
208 HCMD_NAME(NVM_GET_INFO),
209 HCMD_NAME(TAS_CONFIG),
210 HCMD_NAME(SAR_OFFSET_MAPPING_TABLE_CMD),
211 HCMD_NAME(MCC_ALLOWED_AP_TYPE_CMD),
212 };
213
214 /* Please keep this array *SORTED* by hex value.
215 * Access is done through binary search
216 */
217 static const struct iwl_hcmd_names iwl_mld_debug_names[] = {
218 HCMD_NAME(HOST_EVENT_CFG),
219 HCMD_NAME(DBGC_SUSPEND_RESUME),
220 };
221
222 /* Please keep this array *SORTED* by hex value.
223 * Access is done through binary search
224 */
225 static const struct iwl_hcmd_names iwl_mld_mac_conf_names[] = {
226 HCMD_NAME(LOW_LATENCY_CMD),
227 HCMD_NAME(SESSION_PROTECTION_CMD),
228 HCMD_NAME(MAC_CONFIG_CMD),
229 HCMD_NAME(LINK_CONFIG_CMD),
230 HCMD_NAME(STA_CONFIG_CMD),
231 HCMD_NAME(AUX_STA_CMD),
232 HCMD_NAME(STA_REMOVE_CMD),
233 HCMD_NAME(ROC_CMD),
234 HCMD_NAME(MISSED_BEACONS_NOTIF),
235 HCMD_NAME(EMLSR_TRANS_FAIL_NOTIF),
236 HCMD_NAME(ROC_NOTIF),
237 HCMD_NAME(CHANNEL_SWITCH_ERROR_NOTIF),
238 HCMD_NAME(SESSION_PROTECTION_NOTIF),
239 HCMD_NAME(PROBE_RESPONSE_DATA_NOTIF),
240 HCMD_NAME(CHANNEL_SWITCH_START_NOTIF),
241 };
242
243 /* Please keep this array *SORTED* by hex value.
244 * Access is done through binary search
245 */
246 static const struct iwl_hcmd_names iwl_mld_data_path_names[] = {
247 HCMD_NAME(TRIGGER_RX_QUEUES_NOTIF_CMD),
248 HCMD_NAME(WNM_PLATFORM_PTM_REQUEST_CMD),
249 HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD),
250 HCMD_NAME(RFH_QUEUE_CONFIG_CMD),
251 HCMD_NAME(TLC_MNG_CONFIG_CMD),
252 HCMD_NAME(RX_BAID_ALLOCATION_CONFIG_CMD),
253 HCMD_NAME(SCD_QUEUE_CONFIG_CMD),
254 HCMD_NAME(OMI_SEND_STATUS_NOTIF),
255 HCMD_NAME(ESR_MODE_NOTIF),
256 HCMD_NAME(MONITOR_NOTIF),
257 HCMD_NAME(TLC_MNG_UPDATE_NOTIF),
258 HCMD_NAME(MU_GROUP_MGMT_NOTIF),
259 };
260
261 /* Please keep this array *SORTED* by hex value.
262 * Access is done through binary search
263 */
264 static const struct iwl_hcmd_names iwl_mld_location_names[] = {
265 HCMD_NAME(TOF_RANGE_REQ_CMD),
266 HCMD_NAME(TOF_RANGE_RESPONSE_NOTIF),
267 };
268
269 /* Please keep this array *SORTED* by hex value.
270 * Access is done through binary search
271 */
272 static const struct iwl_hcmd_names iwl_mld_phy_names[] = {
273 HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE),
274 HCMD_NAME(CTDP_CONFIG_CMD),
275 HCMD_NAME(TEMP_REPORTING_THRESHOLDS_CMD),
276 HCMD_NAME(PER_CHAIN_LIMIT_OFFSET_CMD),
277 HCMD_NAME(CT_KILL_NOTIFICATION),
278 HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE),
279 };
280
281 /* Please keep this array *SORTED* by hex value.
282 * Access is done through binary search
283 */
284 static const struct iwl_hcmd_names iwl_mld_statistics_names[] = {
285 HCMD_NAME(STATISTICS_OPER_NOTIF),
286 HCMD_NAME(STATISTICS_OPER_PART1_NOTIF),
287 };
288
289 /* Please keep this array *SORTED* by hex value.
290 * Access is done through binary search
291 */
292 static const struct iwl_hcmd_names iwl_mld_prot_offload_names[] = {
293 HCMD_NAME(WOWLAN_WAKE_PKT_NOTIFICATION),
294 HCMD_NAME(WOWLAN_INFO_NOTIFICATION),
295 HCMD_NAME(D3_END_NOTIFICATION),
296 };
297
298 /* Please keep this array *SORTED* by hex value.
299 * Access is done through binary search
300 */
301 static const struct iwl_hcmd_names iwl_mld_coex_names[] = {
302 HCMD_NAME(PROFILE_NOTIF),
303 };
304
305 VISIBLE_IF_IWLWIFI_KUNIT
306 const struct iwl_hcmd_arr iwl_mld_groups[] = {
307 [LEGACY_GROUP] = HCMD_ARR(iwl_mld_legacy_names),
308 [LONG_GROUP] = HCMD_ARR(iwl_mld_legacy_names),
309 [SYSTEM_GROUP] = HCMD_ARR(iwl_mld_system_names),
310 [MAC_CONF_GROUP] = HCMD_ARR(iwl_mld_mac_conf_names),
311 [DATA_PATH_GROUP] = HCMD_ARR(iwl_mld_data_path_names),
312 [LOCATION_GROUP] = HCMD_ARR(iwl_mld_location_names),
313 [REGULATORY_AND_NVM_GROUP] = HCMD_ARR(iwl_mld_reg_and_nvm_names),
314 [DEBUG_GROUP] = HCMD_ARR(iwl_mld_debug_names),
315 [PHY_OPS_GROUP] = HCMD_ARR(iwl_mld_phy_names),
316 [STATISTICS_GROUP] = HCMD_ARR(iwl_mld_statistics_names),
317 [PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mld_prot_offload_names),
318 [BT_COEX_GROUP] = HCMD_ARR(iwl_mld_coex_names),
319 };
320 EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_groups);
321
322 #if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
323 const unsigned int global_iwl_mld_goups_size = ARRAY_SIZE(iwl_mld_groups);
324 EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(global_iwl_mld_goups_size);
325 #endif
326
327 static void
iwl_mld_configure_trans(struct iwl_op_mode * op_mode)328 iwl_mld_configure_trans(struct iwl_op_mode *op_mode)
329 {
330 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
331 static const u8 no_reclaim_cmds[] = {TX_CMD};
332 struct iwl_trans *trans = mld->trans;
333 u32 eckv_value;
334
335 iwl_bios_setup_step(trans, &mld->fwrt);
336 iwl_uefi_get_step_table(trans);
337
338 if (iwl_bios_get_eckv(&mld->fwrt, &eckv_value))
339 IWL_DEBUG_RADIO(mld, "ECKV table doesn't exist in BIOS\n");
340 else
341 trans->conf.ext_32khz_clock_valid = !!eckv_value;
342
343 trans->conf.rx_buf_size = iwl_amsdu_size_to_rxb_size();
344 trans->conf.command_groups = iwl_mld_groups;
345 trans->conf.command_groups_size = ARRAY_SIZE(iwl_mld_groups);
346 trans->conf.fw_reset_handshake = true;
347 trans->conf.queue_alloc_cmd_ver =
348 iwl_fw_lookup_cmd_ver(mld->fw, WIDE_ID(DATA_PATH_GROUP,
349 SCD_QUEUE_CONFIG_CMD),
350 0);
351 trans->conf.cb_data_offs = offsetof(struct ieee80211_tx_info,
352 driver_data[2]);
353 BUILD_BUG_ON(sizeof(no_reclaim_cmds) >
354 sizeof(trans->conf.no_reclaim_cmds));
355 memcpy(trans->conf.no_reclaim_cmds, no_reclaim_cmds,
356 sizeof(no_reclaim_cmds));
357 trans->conf.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
358
359 trans->conf.rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
360 trans->conf.rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
361 trans->conf.wide_cmd_header = true;
362
363 iwl_trans_op_mode_enter(trans, op_mode);
364 }
365
366 /*
367 *****************************************************
368 * op mode ops functions
369 *****************************************************
370 */
371
372 #define NUM_FW_LOAD_RETRIES 3
373 static struct iwl_op_mode *
iwl_op_mode_mld_start(struct iwl_trans * trans,const struct iwl_rf_cfg * cfg,const struct iwl_fw * fw,struct dentry * dbgfs_dir)374 iwl_op_mode_mld_start(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg,
375 const struct iwl_fw *fw, struct dentry *dbgfs_dir)
376 {
377 struct ieee80211_hw *hw;
378 struct iwl_op_mode *op_mode;
379 struct iwl_mld *mld;
380 int ret;
381
382 /* Allocate and initialize a new hardware device */
383 hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
384 sizeof(struct iwl_mld),
385 &iwl_mld_hw_ops);
386 if (!hw)
387 return ERR_PTR(-ENOMEM);
388
389 op_mode = hw->priv;
390
391 op_mode->ops = &iwl_mld_ops;
392
393 mld = IWL_OP_MODE_GET_MLD(op_mode);
394
395 iwl_construct_mld(mld, trans, cfg, fw, hw, dbgfs_dir);
396
397 /* we'll verify later it matches between commands */
398 mld->fw_rates_ver_3 = iwl_fw_lookup_cmd_ver(mld->fw, TX_CMD, 0) >= 11;
399
400 iwl_mld_construct_fw_runtime(mld, trans, fw, dbgfs_dir);
401
402 iwl_mld_get_bios_tables(mld);
403 iwl_uefi_get_sgom_table(trans, &mld->fwrt);
404 mld->bios_enable_puncturing = iwl_uefi_get_puncturing(&mld->fwrt);
405
406 iwl_mld_hw_set_regulatory(mld);
407
408 /* Configure transport layer with the opmode specific params */
409 iwl_mld_configure_trans(op_mode);
410
411 /* needed for regulatory init */
412 rtnl_lock();
413 /* Needed for sending commands */
414 wiphy_lock(mld->wiphy);
415
416 for (int i = 0; i < NUM_FW_LOAD_RETRIES; i++) {
417 ret = iwl_mld_load_fw(mld);
418 if (!ret)
419 break;
420 }
421
422 if (!ret) {
423 mld->nvm_data = iwl_get_nvm(mld->trans, mld->fw, 0, 0);
424 if (IS_ERR(mld->nvm_data)) {
425 IWL_ERR(mld, "Failed to read NVM: %d\n", ret);
426 ret = PTR_ERR(mld->nvm_data);
427 }
428 }
429
430 if (ret) {
431 wiphy_unlock(mld->wiphy);
432 rtnl_unlock();
433 goto err;
434 }
435
436 /* We are about to stop the FW. Notifications may require an
437 * operational FW, so handle them all here before we stop.
438 */
439 wiphy_work_flush(mld->wiphy, &mld->async_handlers_wk);
440
441 iwl_mld_stop_fw(mld);
442
443 wiphy_unlock(mld->wiphy);
444 rtnl_unlock();
445
446 ret = iwl_mld_leds_init(mld);
447 if (ret)
448 goto free_nvm;
449
450 ret = iwl_mld_alloc_scan_cmd(mld);
451 if (ret)
452 goto leds_exit;
453
454 ret = iwl_mld_low_latency_init(mld);
455 if (ret)
456 goto free_scan_cmd;
457
458 ret = iwl_mld_register_hw(mld);
459 if (ret)
460 goto low_latency_free;
461
462 iwl_mld_toggle_tx_ant(mld, &mld->mgmt_tx_ant);
463
464 iwl_mld_add_debugfs_files(mld, dbgfs_dir);
465 iwl_mld_thermal_initialize(mld);
466
467 iwl_mld_ptp_init(mld);
468
469 return op_mode;
470
471 low_latency_free:
472 iwl_mld_low_latency_free(mld);
473 free_scan_cmd:
474 kfree(mld->scan.cmd);
475 leds_exit:
476 iwl_mld_leds_exit(mld);
477 free_nvm:
478 kfree(mld->nvm_data);
479 err:
480 iwl_trans_op_mode_leave(mld->trans);
481 ieee80211_free_hw(mld->hw);
482 return ERR_PTR(ret);
483 }
484
485 static void
iwl_op_mode_mld_stop(struct iwl_op_mode * op_mode)486 iwl_op_mode_mld_stop(struct iwl_op_mode *op_mode)
487 {
488 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
489
490 iwl_mld_ptp_remove(mld);
491 iwl_mld_leds_exit(mld);
492
493 iwl_mld_thermal_exit(mld);
494
495 wiphy_lock(mld->wiphy);
496 iwl_mld_low_latency_stop(mld);
497 iwl_mld_deinit_time_sync(mld);
498 wiphy_unlock(mld->wiphy);
499
500 ieee80211_unregister_hw(mld->hw);
501
502 iwl_fw_runtime_free(&mld->fwrt);
503 iwl_mld_low_latency_free(mld);
504
505 iwl_trans_op_mode_leave(mld->trans);
506
507 kfree(mld->nvm_data);
508 kfree(mld->scan.cmd);
509 kfree(mld->error_recovery_buf);
510 kfree(mld->mcast_filter_cmd);
511
512 ieee80211_free_hw(mld->hw);
513 }
514
iwl_mld_queue_state_change(struct iwl_op_mode * op_mode,int hw_queue,bool queue_full)515 static void iwl_mld_queue_state_change(struct iwl_op_mode *op_mode,
516 int hw_queue, bool queue_full)
517 {
518 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
519 struct ieee80211_txq *txq;
520 struct iwl_mld_sta *mld_sta;
521 struct iwl_mld_txq *mld_txq;
522
523 rcu_read_lock();
524
525 txq = rcu_dereference(mld->fw_id_to_txq[hw_queue]);
526 if (!txq) {
527 rcu_read_unlock();
528
529 if (queue_full) {
530 /* An internal queue is not expected to become full */
531 IWL_WARN(mld,
532 "Internal hw_queue %d is full! stopping all queues\n",
533 hw_queue);
534 /* Stop all queues, as an internal queue is not
535 * mapped to a mac80211 one
536 */
537 ieee80211_stop_queues(mld->hw);
538 } else {
539 ieee80211_wake_queues(mld->hw);
540 }
541
542 return;
543 }
544
545 mld_txq = iwl_mld_txq_from_mac80211(txq);
546 mld_sta = txq->sta ? iwl_mld_sta_from_mac80211(txq->sta) : NULL;
547
548 mld_txq->status.stop_full = queue_full;
549
550 if (!queue_full && mld_sta &&
551 mld_sta->sta_state != IEEE80211_STA_NOTEXIST) {
552 local_bh_disable();
553 iwl_mld_tx_from_txq(mld, txq);
554 local_bh_enable();
555 }
556
557 rcu_read_unlock();
558 }
559
560 static void
iwl_mld_queue_full(struct iwl_op_mode * op_mode,int hw_queue)561 iwl_mld_queue_full(struct iwl_op_mode *op_mode, int hw_queue)
562 {
563 iwl_mld_queue_state_change(op_mode, hw_queue, true);
564 }
565
566 static void
iwl_mld_queue_not_full(struct iwl_op_mode * op_mode,int hw_queue)567 iwl_mld_queue_not_full(struct iwl_op_mode *op_mode, int hw_queue)
568 {
569 iwl_mld_queue_state_change(op_mode, hw_queue, false);
570 }
571
572 static bool
iwl_mld_set_hw_rfkill_state(struct iwl_op_mode * op_mode,bool state)573 iwl_mld_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
574 {
575 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
576
577 iwl_mld_set_hwkill(mld, state);
578
579 return false;
580 }
581
582 static void
iwl_mld_free_skb(struct iwl_op_mode * op_mode,struct sk_buff * skb)583 iwl_mld_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
584 {
585 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
586 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
587
588 iwl_trans_free_tx_cmd(mld->trans, info->driver_data[1]);
589 ieee80211_free_txskb(mld->hw, skb);
590 }
591
iwl_mld_read_error_recovery_buffer(struct iwl_mld * mld)592 static void iwl_mld_read_error_recovery_buffer(struct iwl_mld *mld)
593 {
594 u32 src_size = mld->fw->ucode_capa.error_log_size;
595 u32 src_addr = mld->fw->ucode_capa.error_log_addr;
596 u8 *recovery_buf;
597 int ret;
598
599 /* no recovery buffer size defined in a TLV */
600 if (!src_size)
601 return;
602
603 recovery_buf = kzalloc(src_size, GFP_ATOMIC);
604 if (!recovery_buf)
605 return;
606
607 ret = iwl_trans_read_mem_bytes(mld->trans, src_addr,
608 recovery_buf, src_size);
609 if (ret) {
610 IWL_ERR(mld, "Failed to read error recovery buffer (%d)\n",
611 ret);
612 kfree(recovery_buf);
613 return;
614 }
615
616 mld->error_recovery_buf = recovery_buf;
617 }
618
iwl_mld_restart_nic(struct iwl_mld * mld)619 static void iwl_mld_restart_nic(struct iwl_mld *mld)
620 {
621 iwl_mld_read_error_recovery_buffer(mld);
622
623 mld->fwrt.trans->dbg.restart_required = false;
624
625 ieee80211_restart_hw(mld->hw);
626 }
627
628 static void
iwl_mld_nic_error(struct iwl_op_mode * op_mode,enum iwl_fw_error_type type)629 iwl_mld_nic_error(struct iwl_op_mode *op_mode,
630 enum iwl_fw_error_type type)
631 {
632 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
633 bool trans_dead = test_bit(STATUS_TRANS_DEAD, &mld->trans->status);
634
635 if (type == IWL_ERR_TYPE_CMD_QUEUE_FULL)
636 IWL_ERR(mld, "Command queue full!\n");
637 else if (!trans_dead && !mld->fw_status.do_not_dump_once)
638 iwl_fwrt_dump_error_logs(&mld->fwrt);
639
640 mld->fw_status.do_not_dump_once = false;
641
642 /* It is necessary to abort any os scan here because mac80211 requires
643 * having the scan cleared before restarting.
644 * We'll reset the scan_status to NONE in restart cleanup in
645 * the next drv_start() call from mac80211. If ieee80211_hw_restart
646 * isn't called scan status will stay busy.
647 */
648 iwl_mld_report_scan_aborted(mld);
649
650 /*
651 * This should be first thing before trying to collect any
652 * data to avoid endless loops if any HW error happens while
653 * collecting debug data.
654 * It might not actually be true that we'll restart, but the
655 * setting doesn't matter if we're going to be unbound either.
656 */
657 if (type != IWL_ERR_TYPE_RESET_HS_TIMEOUT &&
658 mld->fw_status.running)
659 mld->fw_status.in_hw_restart = true;
660 }
661
iwl_mld_dump_error(struct iwl_op_mode * op_mode,struct iwl_fw_error_dump_mode * mode)662 static void iwl_mld_dump_error(struct iwl_op_mode *op_mode,
663 struct iwl_fw_error_dump_mode *mode)
664 {
665 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
666
667 /* if we come in from opmode we have the mutex held */
668 if (mode->context == IWL_ERR_CONTEXT_FROM_OPMODE) {
669 lockdep_assert_wiphy(mld->wiphy);
670 iwl_fw_error_collect(&mld->fwrt);
671 } else {
672 wiphy_lock(mld->wiphy);
673 if (mode->context != IWL_ERR_CONTEXT_ABORT)
674 iwl_fw_error_collect(&mld->fwrt);
675 wiphy_unlock(mld->wiphy);
676 }
677 }
678
iwl_mld_sw_reset(struct iwl_op_mode * op_mode,enum iwl_fw_error_type type)679 static bool iwl_mld_sw_reset(struct iwl_op_mode *op_mode,
680 enum iwl_fw_error_type type)
681 {
682 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
683
684 /* SW reset can happen for TOP error w/o NIC error, so
685 * also abort scan here and set in_hw_restart, when we
686 * had a NIC error both were already done.
687 */
688 iwl_mld_report_scan_aborted(mld);
689 mld->fw_status.in_hw_restart = true;
690
691 /* Do restart only in the following conditions are met:
692 * - we consider the FW as running
693 * - The trigger that brought us here is defined as one that requires
694 * a restart (in the debug TLVs)
695 */
696 if (!mld->fw_status.running || !mld->fwrt.trans->dbg.restart_required)
697 return false;
698
699 iwl_mld_restart_nic(mld);
700 return true;
701 }
702
703 static void
iwl_mld_time_point(struct iwl_op_mode * op_mode,enum iwl_fw_ini_time_point tp_id,union iwl_dbg_tlv_tp_data * tp_data)704 iwl_mld_time_point(struct iwl_op_mode *op_mode,
705 enum iwl_fw_ini_time_point tp_id,
706 union iwl_dbg_tlv_tp_data *tp_data)
707 {
708 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
709
710 iwl_dbg_tlv_time_point(&mld->fwrt, tp_id, tp_data);
711 }
712
713 #ifdef CONFIG_PM_SLEEP
iwl_mld_device_powered_off(struct iwl_op_mode * op_mode)714 static void iwl_mld_device_powered_off(struct iwl_op_mode *op_mode)
715 {
716 struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
717
718 wiphy_lock(mld->wiphy);
719 iwl_mld_stop_fw(mld);
720 mld->fw_status.in_d3 = false;
721 wiphy_unlock(mld->wiphy);
722 }
723 #else
iwl_mld_device_powered_off(struct iwl_op_mode * op_mode)724 static void iwl_mld_device_powered_off(struct iwl_op_mode *op_mode)
725 {}
726 #endif
727
728 static const struct iwl_op_mode_ops iwl_mld_ops = {
729 .start = iwl_op_mode_mld_start,
730 .stop = iwl_op_mode_mld_stop,
731 .rx = iwl_mld_rx,
732 .rx_rss = iwl_mld_rx_rss,
733 .queue_full = iwl_mld_queue_full,
734 .queue_not_full = iwl_mld_queue_not_full,
735 .hw_rf_kill = iwl_mld_set_hw_rfkill_state,
736 .free_skb = iwl_mld_free_skb,
737 .nic_error = iwl_mld_nic_error,
738 .dump_error = iwl_mld_dump_error,
739 .sw_reset = iwl_mld_sw_reset,
740 .time_point = iwl_mld_time_point,
741 .device_powered_off = pm_sleep_ptr(iwl_mld_device_powered_off),
742 };
743
744 struct iwl_mld_mod_params iwlmld_mod_params = {
745 .power_scheme = IWL_POWER_SCHEME_BPS,
746 };
747
748 module_param_named(power_scheme, iwlmld_mod_params.power_scheme, int, 0444);
749 MODULE_PARM_DESC(power_scheme,
750 "power management scheme: 1-active, 2-balanced, default: 2");
751