xref: /freebsd/sys/contrib/dev/rtw89/mac80211.c (revision 72ae04c7334743c0fec2e8c99ac13fd8ca63f51b)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2019-2020  Realtek Corporation
3  */
4 
5 #include "cam.h"
6 #include "chan.h"
7 #include "coex.h"
8 #include "debug.h"
9 #include "fw.h"
10 #include "mac.h"
11 #include "phy.h"
12 #include "ps.h"
13 #include "reg.h"
14 #include "sar.h"
15 #include "ser.h"
16 #include "util.h"
17 #include "wow.h"
18 
19 static void rtw89_ops_tx(struct ieee80211_hw *hw,
20 			 struct ieee80211_tx_control *control,
21 			 struct sk_buff *skb)
22 {
23 	struct rtw89_dev *rtwdev = hw->priv;
24 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
25 	struct ieee80211_vif *vif = info->control.vif;
26 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
27 	struct ieee80211_sta *sta = control->sta;
28 	u32 flags = IEEE80211_SKB_CB(skb)->flags;
29 	int ret, qsel;
30 
31 	if (rtwvif->offchan && !(flags & IEEE80211_TX_CTL_TX_OFFCHAN) && sta) {
32 		struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
33 
34 		rtw89_debug(rtwdev, RTW89_DBG_TXRX, "ops_tx during offchan\n");
35 		skb_queue_tail(&rtwsta->roc_queue, skb);
36 		return;
37 	}
38 
39 	ret = rtw89_core_tx_write(rtwdev, vif, sta, skb, &qsel);
40 	if (ret) {
41 		rtw89_err(rtwdev, "failed to transmit skb: %d\n", ret);
42 		ieee80211_free_txskb(hw, skb);
43 		return;
44 	}
45 	rtw89_core_tx_kick_off(rtwdev, qsel);
46 }
47 
48 static void rtw89_ops_wake_tx_queue(struct ieee80211_hw *hw,
49 				    struct ieee80211_txq *txq)
50 {
51 	struct rtw89_dev *rtwdev = hw->priv;
52 
53 	ieee80211_schedule_txq(hw, txq);
54 	queue_work(rtwdev->txq_wq, &rtwdev->txq_work);
55 }
56 
57 static int rtw89_ops_start(struct ieee80211_hw *hw)
58 {
59 	struct rtw89_dev *rtwdev = hw->priv;
60 	int ret;
61 
62 	mutex_lock(&rtwdev->mutex);
63 	ret = rtw89_core_start(rtwdev);
64 	mutex_unlock(&rtwdev->mutex);
65 
66 	return ret;
67 }
68 
69 static void rtw89_ops_stop(struct ieee80211_hw *hw, bool suspend)
70 {
71 	struct rtw89_dev *rtwdev = hw->priv;
72 
73 	mutex_lock(&rtwdev->mutex);
74 	rtw89_core_stop(rtwdev);
75 	mutex_unlock(&rtwdev->mutex);
76 }
77 
78 static int rtw89_ops_config(struct ieee80211_hw *hw, u32 changed)
79 {
80 	struct rtw89_dev *rtwdev = hw->priv;
81 
82 	/* let previous ips work finish to ensure we don't leave ips twice */
83 	cancel_work_sync(&rtwdev->ips_work);
84 
85 	mutex_lock(&rtwdev->mutex);
86 	rtw89_leave_ps_mode(rtwdev);
87 
88 	if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
89 	    !(hw->conf.flags & IEEE80211_CONF_IDLE))
90 		rtw89_leave_ips(rtwdev);
91 
92 	if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
93 		rtw89_config_entity_chandef(rtwdev, RTW89_SUB_ENTITY_0,
94 					    &hw->conf.chandef);
95 		rtw89_set_channel(rtwdev);
96 	}
97 
98 	if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
99 	    (hw->conf.flags & IEEE80211_CONF_IDLE) &&
100 	    !rtwdev->scanning)
101 		rtw89_enter_ips(rtwdev);
102 
103 	mutex_unlock(&rtwdev->mutex);
104 
105 	return 0;
106 }
107 
108 static int rtw89_ops_add_interface(struct ieee80211_hw *hw,
109 				   struct ieee80211_vif *vif)
110 {
111 	struct rtw89_dev *rtwdev = hw->priv;
112 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
113 	int ret = 0;
114 
115 	rtw89_debug(rtwdev, RTW89_DBG_STATE, "add vif %pM type %d, p2p %d\n",
116 		    vif->addr, vif->type, vif->p2p);
117 
118 	mutex_lock(&rtwdev->mutex);
119 
120 	rtw89_leave_ips_by_hwflags(rtwdev);
121 
122 	if (RTW89_CHK_FW_FEATURE(BEACON_FILTER, &rtwdev->fw))
123 		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
124 				     IEEE80211_VIF_SUPPORTS_CQM_RSSI;
125 
126 	rtwvif->rtwdev = rtwdev;
127 	rtwvif->roc.state = RTW89_ROC_IDLE;
128 	rtwvif->offchan = false;
129 	list_add_tail(&rtwvif->list, &rtwdev->rtwvifs_list);
130 	INIT_WORK(&rtwvif->update_beacon_work, rtw89_core_update_beacon_work);
131 	INIT_DELAYED_WORK(&rtwvif->roc.roc_work, rtw89_roc_work);
132 	rtw89_leave_ps_mode(rtwdev);
133 
134 	rtw89_traffic_stats_init(rtwdev, &rtwvif->stats);
135 	rtw89_vif_type_mapping(vif, false);
136 	rtwvif->port = rtw89_core_acquire_bit_map(rtwdev->hw_port,
137 						  RTW89_PORT_NUM);
138 	if (rtwvif->port == RTW89_PORT_NUM) {
139 		ret = -ENOSPC;
140 		list_del_init(&rtwvif->list);
141 		goto out;
142 	}
143 
144 	rtwvif->bcn_hit_cond = 0;
145 	rtwvif->mac_idx = RTW89_MAC_0;
146 	rtwvif->phy_idx = RTW89_PHY_0;
147 	rtwvif->sub_entity_idx = RTW89_SUB_ENTITY_0;
148 	rtwvif->chanctx_assigned = false;
149 	rtwvif->hit_rule = 0;
150 	rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_DFLT;
151 	ether_addr_copy(rtwvif->mac_addr, vif->addr);
152 	INIT_LIST_HEAD(&rtwvif->general_pkt_list);
153 
154 	ret = rtw89_mac_add_vif(rtwdev, rtwvif);
155 	if (ret) {
156 		rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
157 		list_del_init(&rtwvif->list);
158 		goto out;
159 	}
160 
161 	rtw89_core_txq_init(rtwdev, vif->txq);
162 
163 	rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_START);
164 
165 	rtw89_recalc_lps(rtwdev);
166 out:
167 	mutex_unlock(&rtwdev->mutex);
168 
169 	return ret;
170 }
171 
172 static void rtw89_ops_remove_interface(struct ieee80211_hw *hw,
173 				       struct ieee80211_vif *vif)
174 {
175 	struct rtw89_dev *rtwdev = hw->priv;
176 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
177 
178 	rtw89_debug(rtwdev, RTW89_DBG_STATE, "remove vif %pM type %d p2p %d\n",
179 		    vif->addr, vif->type, vif->p2p);
180 
181 	cancel_work_sync(&rtwvif->update_beacon_work);
182 	cancel_delayed_work_sync(&rtwvif->roc.roc_work);
183 
184 	mutex_lock(&rtwdev->mutex);
185 	rtw89_leave_ps_mode(rtwdev);
186 	rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_STOP);
187 	rtw89_mac_remove_vif(rtwdev, rtwvif);
188 	rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
189 	list_del_init(&rtwvif->list);
190 	rtw89_recalc_lps(rtwdev);
191 	rtw89_enter_ips_by_hwflags(rtwdev);
192 
193 	mutex_unlock(&rtwdev->mutex);
194 }
195 
196 static int rtw89_ops_change_interface(struct ieee80211_hw *hw,
197 				      struct ieee80211_vif *vif,
198 				      enum nl80211_iftype type, bool p2p)
199 {
200 	struct rtw89_dev *rtwdev = hw->priv;
201 	int ret;
202 
203 	set_bit(RTW89_FLAG_CHANGING_INTERFACE, rtwdev->flags);
204 
205 	rtw89_debug(rtwdev, RTW89_DBG_STATE, "change vif %pM (%d)->(%d), p2p (%d)->(%d)\n",
206 		    vif->addr, vif->type, type, vif->p2p, p2p);
207 
208 	rtw89_ops_remove_interface(hw, vif);
209 
210 	vif->type = type;
211 	vif->p2p = p2p;
212 
213 	ret = rtw89_ops_add_interface(hw, vif);
214 	if (ret)
215 		rtw89_warn(rtwdev, "failed to change interface %d\n", ret);
216 
217 	clear_bit(RTW89_FLAG_CHANGING_INTERFACE, rtwdev->flags);
218 
219 	return ret;
220 }
221 
222 static void rtw89_ops_configure_filter(struct ieee80211_hw *hw,
223 				       unsigned int changed_flags,
224 				       unsigned int *new_flags,
225 				       u64 multicast)
226 {
227 	struct rtw89_dev *rtwdev = hw->priv;
228 	const struct rtw89_mac_gen_def *mac = rtwdev->chip->mac_def;
229 	u32 rx_fltr;
230 
231 	mutex_lock(&rtwdev->mutex);
232 	rtw89_leave_ps_mode(rtwdev);
233 
234 	*new_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_FCSFAIL |
235 		      FIF_BCN_PRBRESP_PROMISC | FIF_PROBE_REQ;
236 
237 	if (changed_flags & FIF_ALLMULTI) {
238 		if (*new_flags & FIF_ALLMULTI)
239 			rtwdev->hal.rx_fltr &= ~B_AX_A_MC;
240 		else
241 			rtwdev->hal.rx_fltr |= B_AX_A_MC;
242 	}
243 	if (changed_flags & FIF_FCSFAIL) {
244 		if (*new_flags & FIF_FCSFAIL)
245 			rtwdev->hal.rx_fltr |= B_AX_A_CRC32_ERR;
246 		else
247 			rtwdev->hal.rx_fltr &= ~B_AX_A_CRC32_ERR;
248 	}
249 	if (changed_flags & FIF_OTHER_BSS) {
250 		if (*new_flags & FIF_OTHER_BSS)
251 			rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
252 		else
253 			rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
254 	}
255 	if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
256 		if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
257 			rtwdev->hal.rx_fltr &= ~B_AX_A_BCN_CHK_EN;
258 			rtwdev->hal.rx_fltr &= ~B_AX_A_BC;
259 			rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
260 		} else {
261 			rtwdev->hal.rx_fltr |= B_AX_A_BCN_CHK_EN;
262 			rtwdev->hal.rx_fltr |= B_AX_A_BC;
263 			rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
264 		}
265 	}
266 	if (changed_flags & FIF_PROBE_REQ) {
267 		if (*new_flags & FIF_PROBE_REQ) {
268 			rtwdev->hal.rx_fltr &= ~B_AX_A_BC_CAM_MATCH;
269 			rtwdev->hal.rx_fltr &= ~B_AX_A_UC_CAM_MATCH;
270 		} else {
271 			rtwdev->hal.rx_fltr |= B_AX_A_BC_CAM_MATCH;
272 			rtwdev->hal.rx_fltr |= B_AX_A_UC_CAM_MATCH;
273 		}
274 	}
275 
276 	rx_fltr = rtwdev->hal.rx_fltr;
277 
278 	/* mac80211 doesn't configure filter when HW scan, driver need to
279 	 * set by itself. However, during P2P scan might have configure
280 	 * filter to overwrite filter that HW scan needed, so we need to
281 	 * check scan and append related filter
282 	 */
283 	if (rtwdev->scanning) {
284 		rx_fltr &= ~B_AX_A_BCN_CHK_EN;
285 		rx_fltr &= ~B_AX_A_BC;
286 		rx_fltr &= ~B_AX_A_A1_MATCH;
287 	}
288 
289 	rtw89_write32_mask(rtwdev,
290 			   rtw89_mac_reg_by_idx(rtwdev, mac->rx_fltr, RTW89_MAC_0),
291 			   B_AX_RX_FLTR_CFG_MASK,
292 			   rx_fltr);
293 	if (!rtwdev->dbcc_en)
294 		goto out;
295 	rtw89_write32_mask(rtwdev,
296 			   rtw89_mac_reg_by_idx(rtwdev, mac->rx_fltr, RTW89_MAC_1),
297 			   B_AX_RX_FLTR_CFG_MASK,
298 			   rx_fltr);
299 
300 out:
301 	mutex_unlock(&rtwdev->mutex);
302 }
303 
304 static const u8 ac_to_fw_idx[IEEE80211_NUM_ACS] = {
305 	[IEEE80211_AC_VO] = 3,
306 	[IEEE80211_AC_VI] = 2,
307 	[IEEE80211_AC_BE] = 0,
308 	[IEEE80211_AC_BK] = 1,
309 };
310 
311 static u8 rtw89_aifsn_to_aifs(struct rtw89_dev *rtwdev,
312 			      struct rtw89_vif *rtwvif, u8 aifsn)
313 {
314 	struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif);
315 	const struct rtw89_chan *chan = rtw89_chan_get(rtwdev,
316 						       rtwvif->sub_entity_idx);
317 	u8 slot_time;
318 	u8 sifs;
319 
320 	slot_time = vif->bss_conf.use_short_slot ? 9 : 20;
321 	sifs = chan->band_type == RTW89_BAND_2G ? 10 : 16;
322 
323 	return aifsn * slot_time + sifs;
324 }
325 
326 static void ____rtw89_conf_tx_edca(struct rtw89_dev *rtwdev,
327 				   struct rtw89_vif *rtwvif, u16 ac)
328 {
329 	struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
330 	u32 val;
331 	u8 ecw_max, ecw_min;
332 	u8 aifs;
333 
334 	/* 2^ecw - 1 = cw; ecw = log2(cw + 1) */
335 	ecw_max = ilog2(params->cw_max + 1);
336 	ecw_min = ilog2(params->cw_min + 1);
337 	aifs = rtw89_aifsn_to_aifs(rtwdev, rtwvif, params->aifs);
338 	val = FIELD_PREP(FW_EDCA_PARAM_TXOPLMT_MSK, params->txop) |
339 	      FIELD_PREP(FW_EDCA_PARAM_CWMAX_MSK, ecw_max) |
340 	      FIELD_PREP(FW_EDCA_PARAM_CWMIN_MSK, ecw_min) |
341 	      FIELD_PREP(FW_EDCA_PARAM_AIFS_MSK, aifs);
342 	rtw89_fw_h2c_set_edca(rtwdev, rtwvif, ac_to_fw_idx[ac], val);
343 }
344 
345 #define R_MUEDCA_ACS_PARAM(acs) {R_AX_MUEDCA_ ## acs ## _PARAM_0, \
346 				 R_BE_MUEDCA_ ## acs ## _PARAM_0}
347 
348 static const u32 ac_to_mu_edca_param[IEEE80211_NUM_ACS][RTW89_CHIP_GEN_NUM] = {
349 	[IEEE80211_AC_VO] = R_MUEDCA_ACS_PARAM(VO),
350 	[IEEE80211_AC_VI] = R_MUEDCA_ACS_PARAM(VI),
351 	[IEEE80211_AC_BE] = R_MUEDCA_ACS_PARAM(BE),
352 	[IEEE80211_AC_BK] = R_MUEDCA_ACS_PARAM(BK),
353 };
354 
355 static void ____rtw89_conf_tx_mu_edca(struct rtw89_dev *rtwdev,
356 				      struct rtw89_vif *rtwvif, u16 ac)
357 {
358 	struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
359 	struct ieee80211_he_mu_edca_param_ac_rec *mu_edca;
360 	int gen = rtwdev->chip->chip_gen;
361 	u8 aifs, aifsn;
362 	u16 timer_32us;
363 	u32 reg;
364 	u32 val;
365 
366 	if (!params->mu_edca)
367 		return;
368 
369 	mu_edca = &params->mu_edca_param_rec;
370 	aifsn = FIELD_GET(GENMASK(3, 0), mu_edca->aifsn);
371 	aifs = aifsn ? rtw89_aifsn_to_aifs(rtwdev, rtwvif, aifsn) : 0;
372 	timer_32us = mu_edca->mu_edca_timer << 8;
373 
374 	val = FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_TIMER_MASK, timer_32us) |
375 	      FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_CW_MASK, mu_edca->ecw_min_max) |
376 	      FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_AIFS_MASK, aifs);
377 	reg = rtw89_mac_reg_by_idx(rtwdev, ac_to_mu_edca_param[ac][gen], rtwvif->mac_idx);
378 	rtw89_write32(rtwdev, reg, val);
379 
380 	rtw89_mac_set_hw_muedca_ctrl(rtwdev, rtwvif, true);
381 }
382 
383 static void __rtw89_conf_tx(struct rtw89_dev *rtwdev,
384 			    struct rtw89_vif *rtwvif, u16 ac)
385 {
386 	____rtw89_conf_tx_edca(rtwdev, rtwvif, ac);
387 	____rtw89_conf_tx_mu_edca(rtwdev, rtwvif, ac);
388 }
389 
390 static void rtw89_conf_tx(struct rtw89_dev *rtwdev,
391 			  struct rtw89_vif *rtwvif)
392 {
393 	u16 ac;
394 
395 	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
396 		__rtw89_conf_tx(rtwdev, rtwvif, ac);
397 }
398 
399 static void rtw89_station_mode_sta_assoc(struct rtw89_dev *rtwdev,
400 					 struct ieee80211_vif *vif)
401 {
402 	struct ieee80211_sta *sta;
403 
404 	if (vif->type != NL80211_IFTYPE_STATION)
405 		return;
406 
407 	sta = ieee80211_find_sta(vif, vif->cfg.ap_addr);
408 	if (!sta) {
409 		rtw89_err(rtwdev, "can't find sta to set sta_assoc state\n");
410 		return;
411 	}
412 
413 	rtw89_vif_type_mapping(vif, true);
414 
415 	rtw89_core_sta_assoc(rtwdev, vif, sta);
416 }
417 
418 static void rtw89_ops_vif_cfg_changed(struct ieee80211_hw *hw,
419 				      struct ieee80211_vif *vif, u64 changed)
420 {
421 	struct rtw89_dev *rtwdev = hw->priv;
422 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
423 
424 	mutex_lock(&rtwdev->mutex);
425 	rtw89_leave_ps_mode(rtwdev);
426 
427 	if (changed & BSS_CHANGED_ASSOC) {
428 		if (vif->cfg.assoc) {
429 			rtw89_station_mode_sta_assoc(rtwdev, vif);
430 			rtw89_phy_set_bss_color(rtwdev, vif);
431 			rtw89_chip_cfg_txpwr_ul_tb_offset(rtwdev, vif);
432 			rtw89_mac_port_update(rtwdev, rtwvif);
433 			rtw89_mac_set_he_obss_narrow_bw_ru(rtwdev, vif);
434 
435 			rtw89_queue_chanctx_work(rtwdev);
436 		} else {
437 			/* Abort ongoing scan if cancel_scan isn't issued
438 			 * when disconnected by peer
439 			 */
440 			if (rtwdev->scanning)
441 				rtw89_hw_scan_abort(rtwdev, rtwdev->scan_info.scanning_vif);
442 		}
443 	}
444 
445 	if (changed & BSS_CHANGED_PS)
446 		rtw89_recalc_lps(rtwdev);
447 
448 	if (changed & BSS_CHANGED_ARP_FILTER)
449 		rtwvif->ip_addr = vif->cfg.arp_addr_list[0];
450 
451 	mutex_unlock(&rtwdev->mutex);
452 }
453 
454 static void rtw89_ops_link_info_changed(struct ieee80211_hw *hw,
455 					struct ieee80211_vif *vif,
456 					struct ieee80211_bss_conf *conf,
457 					u64 changed)
458 {
459 	struct rtw89_dev *rtwdev = hw->priv;
460 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
461 
462 	mutex_lock(&rtwdev->mutex);
463 	rtw89_leave_ps_mode(rtwdev);
464 
465 	if (changed & BSS_CHANGED_BSSID) {
466 		ether_addr_copy(rtwvif->bssid, conf->bssid);
467 		rtw89_cam_bssid_changed(rtwdev, rtwvif);
468 		rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
469 		WRITE_ONCE(rtwvif->sync_bcn_tsf, 0);
470 	}
471 
472 	if (changed & BSS_CHANGED_BEACON)
473 		rtw89_chip_h2c_update_beacon(rtwdev, rtwvif);
474 
475 	if (changed & BSS_CHANGED_ERP_SLOT)
476 		rtw89_conf_tx(rtwdev, rtwvif);
477 
478 	if (changed & BSS_CHANGED_HE_BSS_COLOR)
479 		rtw89_phy_set_bss_color(rtwdev, vif);
480 
481 	if (changed & BSS_CHANGED_MU_GROUPS)
482 		rtw89_mac_bf_set_gid_table(rtwdev, vif, conf);
483 
484 	if (changed & BSS_CHANGED_P2P_PS)
485 		rtw89_core_update_p2p_ps(rtwdev, vif);
486 
487 	if (changed & BSS_CHANGED_CQM)
488 		rtw89_fw_h2c_set_bcn_fltr_cfg(rtwdev, vif, true);
489 
490 	if (changed & BSS_CHANGED_TPE)
491 		rtw89_reg_6ghz_recalc(rtwdev, rtwvif, true);
492 
493 	mutex_unlock(&rtwdev->mutex);
494 }
495 
496 static int rtw89_ops_start_ap(struct ieee80211_hw *hw,
497 			      struct ieee80211_vif *vif,
498 			      struct ieee80211_bss_conf *link_conf)
499 {
500 	struct rtw89_dev *rtwdev = hw->priv;
501 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
502 	const struct rtw89_chan *chan;
503 
504 	mutex_lock(&rtwdev->mutex);
505 
506 	chan = rtw89_chan_get(rtwdev, rtwvif->sub_entity_idx);
507 	if (chan->band_type == RTW89_BAND_6G) {
508 		mutex_unlock(&rtwdev->mutex);
509 		return -EOPNOTSUPP;
510 	}
511 
512 	if (rtwdev->scanning)
513 		rtw89_hw_scan_abort(rtwdev, rtwdev->scan_info.scanning_vif);
514 
515 	ether_addr_copy(rtwvif->bssid, vif->bss_conf.bssid);
516 	rtw89_cam_bssid_changed(rtwdev, rtwvif);
517 	rtw89_mac_port_update(rtwdev, rtwvif);
518 	rtw89_chip_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
519 	rtw89_fw_h2c_role_maintain(rtwdev, rtwvif, NULL, RTW89_ROLE_TYPE_CHANGE);
520 	rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
521 	rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
522 	rtw89_chip_rfk_channel(rtwdev);
523 
524 	rtw89_queue_chanctx_work(rtwdev);
525 	mutex_unlock(&rtwdev->mutex);
526 
527 	return 0;
528 }
529 
530 static
531 void rtw89_ops_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
532 		       struct ieee80211_bss_conf *link_conf)
533 {
534 	struct rtw89_dev *rtwdev = hw->priv;
535 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
536 
537 	mutex_lock(&rtwdev->mutex);
538 	rtw89_mac_stop_ap(rtwdev, rtwvif);
539 	rtw89_chip_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
540 	rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
541 	mutex_unlock(&rtwdev->mutex);
542 }
543 
544 static int rtw89_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
545 			     bool set)
546 {
547 	struct rtw89_dev *rtwdev = hw->priv;
548 	struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
549 	struct rtw89_vif *rtwvif = rtwsta->rtwvif;
550 
551 	ieee80211_queue_work(rtwdev->hw, &rtwvif->update_beacon_work);
552 
553 	return 0;
554 }
555 
556 static int rtw89_ops_conf_tx(struct ieee80211_hw *hw,
557 			     struct ieee80211_vif *vif,
558 			     unsigned int link_id, u16 ac,
559 			     const struct ieee80211_tx_queue_params *params)
560 {
561 	struct rtw89_dev *rtwdev = hw->priv;
562 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
563 
564 	mutex_lock(&rtwdev->mutex);
565 	rtw89_leave_ps_mode(rtwdev);
566 	rtwvif->tx_params[ac] = *params;
567 	__rtw89_conf_tx(rtwdev, rtwvif, ac);
568 	mutex_unlock(&rtwdev->mutex);
569 
570 	return 0;
571 }
572 
573 static int __rtw89_ops_sta_state(struct ieee80211_hw *hw,
574 				 struct ieee80211_vif *vif,
575 				 struct ieee80211_sta *sta,
576 				 enum ieee80211_sta_state old_state,
577 				 enum ieee80211_sta_state new_state)
578 {
579 	struct rtw89_dev *rtwdev = hw->priv;
580 
581 	if (old_state == IEEE80211_STA_NOTEXIST &&
582 	    new_state == IEEE80211_STA_NONE)
583 		return rtw89_core_sta_add(rtwdev, vif, sta);
584 
585 	if (old_state == IEEE80211_STA_AUTH &&
586 	    new_state == IEEE80211_STA_ASSOC) {
587 		if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
588 			return 0; /* defer to bss_info_changed to have vif info */
589 		return rtw89_core_sta_assoc(rtwdev, vif, sta);
590 	}
591 
592 	if (old_state == IEEE80211_STA_ASSOC &&
593 	    new_state == IEEE80211_STA_AUTH)
594 		return rtw89_core_sta_disassoc(rtwdev, vif, sta);
595 
596 	if (old_state == IEEE80211_STA_AUTH &&
597 	    new_state == IEEE80211_STA_NONE)
598 		return rtw89_core_sta_disconnect(rtwdev, vif, sta);
599 
600 	if (old_state == IEEE80211_STA_NONE &&
601 	    new_state == IEEE80211_STA_NOTEXIST)
602 		return rtw89_core_sta_remove(rtwdev, vif, sta);
603 
604 	return 0;
605 }
606 
607 static int rtw89_ops_sta_state(struct ieee80211_hw *hw,
608 			       struct ieee80211_vif *vif,
609 			       struct ieee80211_sta *sta,
610 			       enum ieee80211_sta_state old_state,
611 			       enum ieee80211_sta_state new_state)
612 {
613 	struct rtw89_dev *rtwdev = hw->priv;
614 	int ret;
615 
616 	mutex_lock(&rtwdev->mutex);
617 	rtw89_leave_ps_mode(rtwdev);
618 	ret = __rtw89_ops_sta_state(hw, vif, sta, old_state, new_state);
619 	mutex_unlock(&rtwdev->mutex);
620 
621 	return ret;
622 }
623 
624 static int rtw89_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
625 			     struct ieee80211_vif *vif,
626 			     struct ieee80211_sta *sta,
627 			     struct ieee80211_key_conf *key)
628 {
629 	struct rtw89_dev *rtwdev = hw->priv;
630 	int ret = 0;
631 
632 	mutex_lock(&rtwdev->mutex);
633 	rtw89_leave_ps_mode(rtwdev);
634 
635 	switch (cmd) {
636 	case SET_KEY:
637 		rtw89_btc_ntfy_specific_packet(rtwdev, PACKET_EAPOL_END);
638 		ret = rtw89_cam_sec_key_add(rtwdev, vif, sta, key);
639 		if (ret && ret != -EOPNOTSUPP) {
640 			rtw89_err(rtwdev, "failed to add key to sec cam\n");
641 			goto out;
642 		}
643 		break;
644 	case DISABLE_KEY:
645 		rtw89_hci_flush_queues(rtwdev, BIT(rtwdev->hw->queues) - 1,
646 				       false);
647 		rtw89_mac_flush_txq(rtwdev, BIT(rtwdev->hw->queues) - 1, false);
648 		ret = rtw89_cam_sec_key_del(rtwdev, vif, sta, key, true);
649 		if (ret) {
650 			rtw89_err(rtwdev, "failed to remove key from sec cam\n");
651 			goto out;
652 		}
653 		break;
654 	}
655 
656 out:
657 	mutex_unlock(&rtwdev->mutex);
658 
659 	return ret;
660 }
661 
662 static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw,
663 				  struct ieee80211_vif *vif,
664 				  struct ieee80211_ampdu_params *params)
665 {
666 	struct rtw89_dev *rtwdev = hw->priv;
667 	struct ieee80211_sta *sta = params->sta;
668 	struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
669 	u16 tid = params->tid;
670 	struct ieee80211_txq *txq = sta->txq[tid];
671 	struct rtw89_txq *rtwtxq = (struct rtw89_txq *)txq->drv_priv;
672 
673 	switch (params->action) {
674 	case IEEE80211_AMPDU_TX_START:
675 		return IEEE80211_AMPDU_TX_START_IMMEDIATE;
676 	case IEEE80211_AMPDU_TX_STOP_CONT:
677 	case IEEE80211_AMPDU_TX_STOP_FLUSH:
678 	case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
679 		mutex_lock(&rtwdev->mutex);
680 		clear_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
681 		clear_bit(tid, rtwsta->ampdu_map);
682 		rtw89_chip_h2c_ampdu_cmac_tbl(rtwdev, vif, sta);
683 		mutex_unlock(&rtwdev->mutex);
684 		ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
685 		break;
686 	case IEEE80211_AMPDU_TX_OPERATIONAL:
687 		mutex_lock(&rtwdev->mutex);
688 		set_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
689 		rtwsta->ampdu_params[tid].agg_num = params->buf_size;
690 		rtwsta->ampdu_params[tid].amsdu = params->amsdu;
691 		set_bit(tid, rtwsta->ampdu_map);
692 		rtw89_leave_ps_mode(rtwdev);
693 		rtw89_chip_h2c_ampdu_cmac_tbl(rtwdev, vif, sta);
694 		mutex_unlock(&rtwdev->mutex);
695 		break;
696 	case IEEE80211_AMPDU_RX_START:
697 		mutex_lock(&rtwdev->mutex);
698 		rtw89_chip_h2c_ba_cam(rtwdev, rtwsta, true, params);
699 		mutex_unlock(&rtwdev->mutex);
700 		break;
701 	case IEEE80211_AMPDU_RX_STOP:
702 		mutex_lock(&rtwdev->mutex);
703 		rtw89_chip_h2c_ba_cam(rtwdev, rtwsta, false, params);
704 		mutex_unlock(&rtwdev->mutex);
705 		break;
706 	default:
707 		WARN_ON(1);
708 		return -ENOTSUPP;
709 	}
710 
711 	return 0;
712 }
713 
714 static int rtw89_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
715 {
716 	struct rtw89_dev *rtwdev = hw->priv;
717 
718 	mutex_lock(&rtwdev->mutex);
719 	rtw89_leave_ps_mode(rtwdev);
720 	if (test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
721 		rtw89_mac_update_rts_threshold(rtwdev, RTW89_MAC_0);
722 	mutex_unlock(&rtwdev->mutex);
723 
724 	return 0;
725 }
726 
727 static void rtw89_ops_sta_statistics(struct ieee80211_hw *hw,
728 				     struct ieee80211_vif *vif,
729 				     struct ieee80211_sta *sta,
730 				     struct station_info *sinfo)
731 {
732 	struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
733 
734 	sinfo->txrate = rtwsta->ra_report.txrate;
735 	sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
736 }
737 
738 static
739 void __rtw89_drop_packets(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif)
740 {
741 	struct rtw89_vif *rtwvif;
742 
743 	if (vif) {
744 		rtwvif = (struct rtw89_vif *)vif->drv_priv;
745 		rtw89_mac_pkt_drop_vif(rtwdev, rtwvif);
746 	} else {
747 		rtw89_for_each_rtwvif(rtwdev, rtwvif)
748 			rtw89_mac_pkt_drop_vif(rtwdev, rtwvif);
749 	}
750 }
751 
752 static void rtw89_ops_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
753 			    u32 queues, bool drop)
754 {
755 	struct rtw89_dev *rtwdev = hw->priv;
756 
757 	mutex_lock(&rtwdev->mutex);
758 	rtw89_leave_lps(rtwdev);
759 	rtw89_hci_flush_queues(rtwdev, queues, drop);
760 
761 	if (drop && !RTW89_CHK_FW_FEATURE(NO_PACKET_DROP, &rtwdev->fw))
762 		__rtw89_drop_packets(rtwdev, vif);
763 	else
764 		rtw89_mac_flush_txq(rtwdev, queues, drop);
765 
766 	mutex_unlock(&rtwdev->mutex);
767 }
768 
769 struct rtw89_iter_bitrate_mask_data {
770 	struct rtw89_dev *rtwdev;
771 	struct ieee80211_vif *vif;
772 	const struct cfg80211_bitrate_mask *mask;
773 };
774 
775 static void rtw89_ra_mask_info_update_iter(void *data, struct ieee80211_sta *sta)
776 {
777 	struct rtw89_iter_bitrate_mask_data *br_data = data;
778 	struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
779 	struct ieee80211_vif *vif = rtwvif_to_vif(rtwsta->rtwvif);
780 
781 	if (vif != br_data->vif || vif->p2p)
782 		return;
783 
784 	rtwsta->use_cfg_mask = true;
785 	rtwsta->mask = *br_data->mask;
786 	rtw89_phy_ra_updata_sta(br_data->rtwdev, sta, IEEE80211_RC_SUPP_RATES_CHANGED);
787 }
788 
789 static void rtw89_ra_mask_info_update(struct rtw89_dev *rtwdev,
790 				      struct ieee80211_vif *vif,
791 				      const struct cfg80211_bitrate_mask *mask)
792 {
793 	struct rtw89_iter_bitrate_mask_data br_data = { .rtwdev = rtwdev,
794 							.vif = vif,
795 							.mask = mask};
796 
797 	ieee80211_iterate_stations_atomic(rtwdev->hw, rtw89_ra_mask_info_update_iter,
798 					  &br_data);
799 }
800 
801 static int rtw89_ops_set_bitrate_mask(struct ieee80211_hw *hw,
802 				      struct ieee80211_vif *vif,
803 				      const struct cfg80211_bitrate_mask *mask)
804 {
805 	struct rtw89_dev *rtwdev = hw->priv;
806 
807 	mutex_lock(&rtwdev->mutex);
808 	rtw89_phy_rate_pattern_vif(rtwdev, vif, mask);
809 	rtw89_ra_mask_info_update(rtwdev, vif, mask);
810 	mutex_unlock(&rtwdev->mutex);
811 
812 	return 0;
813 }
814 
815 static
816 int rtw89_ops_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
817 {
818 	struct rtw89_dev *rtwdev = hw->priv;
819 	struct rtw89_hal *hal = &rtwdev->hal;
820 
821 	if (hal->ant_diversity) {
822 		if (tx_ant != rx_ant || hweight32(tx_ant) != 1)
823 			return -EINVAL;
824 	} else if (rx_ant != hw->wiphy->available_antennas_rx && rx_ant != hal->antenna_rx) {
825 		return -EINVAL;
826 	}
827 
828 	mutex_lock(&rtwdev->mutex);
829 	hal->antenna_tx = tx_ant;
830 	hal->antenna_rx = rx_ant;
831 	hal->tx_path_diversity = false;
832 	hal->ant_diversity_fixed = true;
833 	mutex_unlock(&rtwdev->mutex);
834 
835 	return 0;
836 }
837 
838 static
839 int rtw89_ops_get_antenna(struct ieee80211_hw *hw,  u32 *tx_ant, u32 *rx_ant)
840 {
841 	struct rtw89_dev *rtwdev = hw->priv;
842 	struct rtw89_hal *hal = &rtwdev->hal;
843 
844 	*tx_ant = hal->antenna_tx;
845 	*rx_ant = hal->antenna_rx;
846 
847 	return 0;
848 }
849 
850 static void rtw89_ops_sw_scan_start(struct ieee80211_hw *hw,
851 				    struct ieee80211_vif *vif,
852 				    const u8 *mac_addr)
853 {
854 	struct rtw89_dev *rtwdev = hw->priv;
855 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
856 
857 	mutex_lock(&rtwdev->mutex);
858 	rtw89_core_scan_start(rtwdev, rtwvif, mac_addr, false);
859 	mutex_unlock(&rtwdev->mutex);
860 }
861 
862 static void rtw89_ops_sw_scan_complete(struct ieee80211_hw *hw,
863 				       struct ieee80211_vif *vif)
864 {
865 	struct rtw89_dev *rtwdev = hw->priv;
866 
867 	mutex_lock(&rtwdev->mutex);
868 	rtw89_core_scan_complete(rtwdev, vif, false);
869 	mutex_unlock(&rtwdev->mutex);
870 }
871 
872 static void rtw89_ops_reconfig_complete(struct ieee80211_hw *hw,
873 					enum ieee80211_reconfig_type reconfig_type)
874 {
875 	struct rtw89_dev *rtwdev = hw->priv;
876 
877 	if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART)
878 		rtw89_ser_recfg_done(rtwdev);
879 }
880 
881 static int rtw89_ops_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
882 			     struct ieee80211_scan_request *req)
883 {
884 	struct rtw89_dev *rtwdev = hw->priv;
885 	struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
886 	int ret = 0;
887 
888 	if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
889 		return 1;
890 
891 	if (rtwdev->scanning || rtwvif->offchan)
892 		return -EBUSY;
893 
894 	mutex_lock(&rtwdev->mutex);
895 	rtw89_hw_scan_start(rtwdev, vif, req);
896 	ret = rtw89_hw_scan_offload(rtwdev, vif, true);
897 	if (ret) {
898 		rtw89_hw_scan_abort(rtwdev, vif);
899 		rtw89_err(rtwdev, "HW scan failed with status: %d\n", ret);
900 	}
901 	mutex_unlock(&rtwdev->mutex);
902 
903 	return ret;
904 }
905 
906 static void rtw89_ops_cancel_hw_scan(struct ieee80211_hw *hw,
907 				     struct ieee80211_vif *vif)
908 {
909 	struct rtw89_dev *rtwdev = hw->priv;
910 
911 	if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
912 		return;
913 
914 	if (!rtwdev->scanning)
915 		return;
916 
917 	mutex_lock(&rtwdev->mutex);
918 	rtw89_hw_scan_abort(rtwdev, vif);
919 	mutex_unlock(&rtwdev->mutex);
920 }
921 
922 static void rtw89_ops_sta_rc_update(struct ieee80211_hw *hw,
923 				    struct ieee80211_vif *vif,
924 				    struct ieee80211_sta *sta, u32 changed)
925 {
926 	struct rtw89_dev *rtwdev = hw->priv;
927 
928 	rtw89_phy_ra_updata_sta(rtwdev, sta, changed);
929 }
930 
931 static int rtw89_ops_add_chanctx(struct ieee80211_hw *hw,
932 				 struct ieee80211_chanctx_conf *ctx)
933 {
934 	struct rtw89_dev *rtwdev = hw->priv;
935 	int ret;
936 
937 	mutex_lock(&rtwdev->mutex);
938 	ret = rtw89_chanctx_ops_add(rtwdev, ctx);
939 	mutex_unlock(&rtwdev->mutex);
940 
941 	return ret;
942 }
943 
944 static void rtw89_ops_remove_chanctx(struct ieee80211_hw *hw,
945 				     struct ieee80211_chanctx_conf *ctx)
946 {
947 	struct rtw89_dev *rtwdev = hw->priv;
948 
949 	mutex_lock(&rtwdev->mutex);
950 	rtw89_chanctx_ops_remove(rtwdev, ctx);
951 	mutex_unlock(&rtwdev->mutex);
952 }
953 
954 static void rtw89_ops_change_chanctx(struct ieee80211_hw *hw,
955 				     struct ieee80211_chanctx_conf *ctx,
956 				     u32 changed)
957 {
958 	struct rtw89_dev *rtwdev = hw->priv;
959 
960 	mutex_lock(&rtwdev->mutex);
961 	rtw89_chanctx_ops_change(rtwdev, ctx, changed);
962 	mutex_unlock(&rtwdev->mutex);
963 }
964 
965 static int rtw89_ops_assign_vif_chanctx(struct ieee80211_hw *hw,
966 					struct ieee80211_vif *vif,
967 					struct ieee80211_bss_conf *link_conf,
968 					struct ieee80211_chanctx_conf *ctx)
969 {
970 	struct rtw89_dev *rtwdev = hw->priv;
971 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
972 	int ret;
973 
974 	mutex_lock(&rtwdev->mutex);
975 	ret = rtw89_chanctx_ops_assign_vif(rtwdev, rtwvif, ctx);
976 	mutex_unlock(&rtwdev->mutex);
977 
978 	return ret;
979 }
980 
981 static void rtw89_ops_unassign_vif_chanctx(struct ieee80211_hw *hw,
982 					   struct ieee80211_vif *vif,
983 					   struct ieee80211_bss_conf *link_conf,
984 					   struct ieee80211_chanctx_conf *ctx)
985 {
986 	struct rtw89_dev *rtwdev = hw->priv;
987 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
988 
989 	mutex_lock(&rtwdev->mutex);
990 	rtw89_chanctx_ops_unassign_vif(rtwdev, rtwvif, ctx);
991 	mutex_unlock(&rtwdev->mutex);
992 }
993 
994 static int rtw89_ops_remain_on_channel(struct ieee80211_hw *hw,
995 				       struct ieee80211_vif *vif,
996 				       struct ieee80211_channel *chan,
997 				       int duration,
998 				       enum ieee80211_roc_type type)
999 {
1000 	struct rtw89_dev *rtwdev = hw->priv;
1001 	struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
1002 	struct rtw89_roc *roc = &rtwvif->roc;
1003 
1004 	if (!vif)
1005 		return -EINVAL;
1006 
1007 	mutex_lock(&rtwdev->mutex);
1008 
1009 	if (roc->state != RTW89_ROC_IDLE) {
1010 		mutex_unlock(&rtwdev->mutex);
1011 		return -EBUSY;
1012 	}
1013 
1014 	if (rtwdev->scanning)
1015 		rtw89_hw_scan_abort(rtwdev, rtwdev->scan_info.scanning_vif);
1016 
1017 	if (type == IEEE80211_ROC_TYPE_MGMT_TX)
1018 		roc->state = RTW89_ROC_MGMT;
1019 	else
1020 		roc->state = RTW89_ROC_NORMAL;
1021 
1022 	roc->duration = duration;
1023 	roc->chan = *chan;
1024 	roc->type = type;
1025 
1026 	rtw89_roc_start(rtwdev, rtwvif);
1027 
1028 	mutex_unlock(&rtwdev->mutex);
1029 
1030 	return 0;
1031 }
1032 
1033 static int rtw89_ops_cancel_remain_on_channel(struct ieee80211_hw *hw,
1034 					      struct ieee80211_vif *vif)
1035 {
1036 	struct rtw89_dev *rtwdev = hw->priv;
1037 	struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
1038 
1039 	if (!rtwvif)
1040 		return -EINVAL;
1041 
1042 	cancel_delayed_work_sync(&rtwvif->roc.roc_work);
1043 
1044 	mutex_lock(&rtwdev->mutex);
1045 	rtw89_roc_end(rtwdev, rtwvif);
1046 	mutex_unlock(&rtwdev->mutex);
1047 
1048 	return 0;
1049 }
1050 
1051 static void rtw89_set_tid_config_iter(void *data, struct ieee80211_sta *sta)
1052 {
1053 	struct cfg80211_tid_config *tid_config = data;
1054 	struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
1055 	struct rtw89_dev *rtwdev = rtwsta->rtwvif->rtwdev;
1056 
1057 	rtw89_core_set_tid_config(rtwdev, sta, tid_config);
1058 }
1059 
1060 static int rtw89_ops_set_tid_config(struct ieee80211_hw *hw,
1061 				    struct ieee80211_vif *vif,
1062 				    struct ieee80211_sta *sta,
1063 				    struct cfg80211_tid_config *tid_config)
1064 {
1065 	struct rtw89_dev *rtwdev = hw->priv;
1066 
1067 	mutex_lock(&rtwdev->mutex);
1068 	if (sta)
1069 		rtw89_core_set_tid_config(rtwdev, sta, tid_config);
1070 	else
1071 		ieee80211_iterate_stations_atomic(rtwdev->hw,
1072 						  rtw89_set_tid_config_iter,
1073 						  tid_config);
1074 	mutex_unlock(&rtwdev->mutex);
1075 
1076 	return 0;
1077 }
1078 
1079 #ifdef CONFIG_PM
1080 static int rtw89_ops_suspend(struct ieee80211_hw *hw,
1081 			     struct cfg80211_wowlan *wowlan)
1082 {
1083 	struct rtw89_dev *rtwdev = hw->priv;
1084 	int ret;
1085 
1086 	set_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
1087 	cancel_delayed_work_sync(&rtwdev->track_work);
1088 
1089 	mutex_lock(&rtwdev->mutex);
1090 	ret = rtw89_wow_suspend(rtwdev, wowlan);
1091 	mutex_unlock(&rtwdev->mutex);
1092 
1093 	if (ret) {
1094 		rtw89_warn(rtwdev, "failed to suspend for wow %d\n", ret);
1095 		clear_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
1096 		return 1;
1097 	}
1098 
1099 	return 0;
1100 }
1101 
1102 static int rtw89_ops_resume(struct ieee80211_hw *hw)
1103 {
1104 	struct rtw89_dev *rtwdev = hw->priv;
1105 	int ret;
1106 
1107 	mutex_lock(&rtwdev->mutex);
1108 	ret = rtw89_wow_resume(rtwdev);
1109 	if (ret)
1110 		rtw89_warn(rtwdev, "failed to resume for wow %d\n", ret);
1111 	mutex_unlock(&rtwdev->mutex);
1112 
1113 	clear_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
1114 	ieee80211_queue_delayed_work(rtwdev->hw, &rtwdev->track_work,
1115 				     RTW89_TRACK_WORK_PERIOD);
1116 
1117 	return ret ? 1 : 0;
1118 }
1119 
1120 static void rtw89_ops_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1121 {
1122 	struct rtw89_dev *rtwdev = hw->priv;
1123 
1124 	device_set_wakeup_enable(rtwdev->dev, enabled);
1125 }
1126 
1127 static void rtw89_set_rekey_data(struct ieee80211_hw *hw,
1128 				 struct ieee80211_vif *vif,
1129 				 struct cfg80211_gtk_rekey_data *data)
1130 {
1131 	struct rtw89_dev *rtwdev = hw->priv;
1132 	struct rtw89_wow_param *rtw_wow = &rtwdev->wow;
1133 	struct rtw89_wow_gtk_info *gtk_info = &rtw_wow->gtk_info;
1134 
1135 	if (data->kek_len > sizeof(gtk_info->kek) ||
1136 	    data->kck_len > sizeof(gtk_info->kck)) {
1137 		rtw89_warn(rtwdev, "kek or kck length over fw limit\n");
1138 		return;
1139 	}
1140 
1141 	mutex_lock(&rtwdev->mutex);
1142 
1143 	memcpy(gtk_info->kek, data->kek, data->kek_len);
1144 	memcpy(gtk_info->kck, data->kck, data->kck_len);
1145 
1146 	mutex_unlock(&rtwdev->mutex);
1147 }
1148 #endif
1149 
1150 const struct ieee80211_ops rtw89_ops = {
1151 	.tx			= rtw89_ops_tx,
1152 	.wake_tx_queue		= rtw89_ops_wake_tx_queue,
1153 	.start			= rtw89_ops_start,
1154 	.stop			= rtw89_ops_stop,
1155 	.config			= rtw89_ops_config,
1156 	.add_interface		= rtw89_ops_add_interface,
1157 	.change_interface       = rtw89_ops_change_interface,
1158 	.remove_interface	= rtw89_ops_remove_interface,
1159 	.configure_filter	= rtw89_ops_configure_filter,
1160 	.vif_cfg_changed	= rtw89_ops_vif_cfg_changed,
1161 	.link_info_changed	= rtw89_ops_link_info_changed,
1162 	.start_ap		= rtw89_ops_start_ap,
1163 	.stop_ap		= rtw89_ops_stop_ap,
1164 	.set_tim		= rtw89_ops_set_tim,
1165 	.conf_tx		= rtw89_ops_conf_tx,
1166 	.sta_state		= rtw89_ops_sta_state,
1167 	.set_key		= rtw89_ops_set_key,
1168 	.ampdu_action		= rtw89_ops_ampdu_action,
1169 	.set_rts_threshold	= rtw89_ops_set_rts_threshold,
1170 	.sta_statistics		= rtw89_ops_sta_statistics,
1171 	.flush			= rtw89_ops_flush,
1172 	.set_bitrate_mask	= rtw89_ops_set_bitrate_mask,
1173 	.set_antenna		= rtw89_ops_set_antenna,
1174 	.get_antenna		= rtw89_ops_get_antenna,
1175 	.sw_scan_start		= rtw89_ops_sw_scan_start,
1176 	.sw_scan_complete	= rtw89_ops_sw_scan_complete,
1177 	.reconfig_complete	= rtw89_ops_reconfig_complete,
1178 	.hw_scan		= rtw89_ops_hw_scan,
1179 	.cancel_hw_scan		= rtw89_ops_cancel_hw_scan,
1180 	.add_chanctx		= rtw89_ops_add_chanctx,
1181 	.remove_chanctx		= rtw89_ops_remove_chanctx,
1182 	.change_chanctx		= rtw89_ops_change_chanctx,
1183 	.assign_vif_chanctx	= rtw89_ops_assign_vif_chanctx,
1184 	.unassign_vif_chanctx	= rtw89_ops_unassign_vif_chanctx,
1185 	.remain_on_channel		= rtw89_ops_remain_on_channel,
1186 	.cancel_remain_on_channel	= rtw89_ops_cancel_remain_on_channel,
1187 	.set_sar_specs		= rtw89_ops_set_sar_specs,
1188 	.sta_rc_update		= rtw89_ops_sta_rc_update,
1189 	.set_tid_config		= rtw89_ops_set_tid_config,
1190 #ifdef CONFIG_PM
1191 	.suspend		= rtw89_ops_suspend,
1192 	.resume			= rtw89_ops_resume,
1193 	.set_wakeup		= rtw89_ops_set_wakeup,
1194 	.set_rekey_data		= rtw89_set_rekey_data,
1195 #endif
1196 };
1197 EXPORT_SYMBOL(rtw89_ops);
1198