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
rtw89_ops_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)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
rtw89_ops_wake_tx_queue(struct ieee80211_hw * hw,struct ieee80211_txq * txq)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
rtw89_ops_start(struct ieee80211_hw * hw)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
rtw89_ops_stop(struct ieee80211_hw * hw)69 static void rtw89_ops_stop(struct ieee80211_hw *hw)
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
rtw89_ops_config(struct ieee80211_hw * hw,u32 changed)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
rtw89_ops_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)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->hit_rule = 0;
149 rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_DFLT;
150 ether_addr_copy(rtwvif->mac_addr, vif->addr);
151 INIT_LIST_HEAD(&rtwvif->general_pkt_list);
152
153 ret = rtw89_mac_add_vif(rtwdev, rtwvif);
154 if (ret) {
155 rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
156 list_del_init(&rtwvif->list);
157 goto out;
158 }
159
160 rtw89_core_txq_init(rtwdev, vif->txq);
161
162 rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_START);
163
164 rtw89_recalc_lps(rtwdev);
165 out:
166 mutex_unlock(&rtwdev->mutex);
167
168 return ret;
169 }
170
rtw89_ops_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)171 static void rtw89_ops_remove_interface(struct ieee80211_hw *hw,
172 struct ieee80211_vif *vif)
173 {
174 struct rtw89_dev *rtwdev = hw->priv;
175 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
176
177 rtw89_debug(rtwdev, RTW89_DBG_STATE, "remove vif %pM type %d p2p %d\n",
178 vif->addr, vif->type, vif->p2p);
179
180 cancel_work_sync(&rtwvif->update_beacon_work);
181 cancel_delayed_work_sync(&rtwvif->roc.roc_work);
182
183 mutex_lock(&rtwdev->mutex);
184 rtw89_leave_ps_mode(rtwdev);
185 rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_STOP);
186 rtw89_mac_remove_vif(rtwdev, rtwvif);
187 rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
188 list_del_init(&rtwvif->list);
189 rtw89_recalc_lps(rtwdev);
190 rtw89_enter_ips_by_hwflags(rtwdev);
191
192 mutex_unlock(&rtwdev->mutex);
193 }
194
rtw89_ops_change_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif,enum nl80211_iftype type,bool p2p)195 static int rtw89_ops_change_interface(struct ieee80211_hw *hw,
196 struct ieee80211_vif *vif,
197 enum nl80211_iftype type, bool p2p)
198 {
199 struct rtw89_dev *rtwdev = hw->priv;
200 int ret;
201
202 set_bit(RTW89_FLAG_CHANGING_INTERFACE, rtwdev->flags);
203
204 rtw89_debug(rtwdev, RTW89_DBG_STATE, "change vif %pM (%d)->(%d), p2p (%d)->(%d)\n",
205 vif->addr, vif->type, type, vif->p2p, p2p);
206
207 rtw89_ops_remove_interface(hw, vif);
208
209 vif->type = type;
210 vif->p2p = p2p;
211
212 ret = rtw89_ops_add_interface(hw, vif);
213 if (ret)
214 rtw89_warn(rtwdev, "failed to change interface %d\n", ret);
215
216 clear_bit(RTW89_FLAG_CHANGING_INTERFACE, rtwdev->flags);
217
218 return ret;
219 }
220
rtw89_ops_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * new_flags,u64 multicast)221 static void rtw89_ops_configure_filter(struct ieee80211_hw *hw,
222 unsigned int changed_flags,
223 unsigned int *new_flags,
224 u64 multicast)
225 {
226 struct rtw89_dev *rtwdev = hw->priv;
227 const struct rtw89_mac_gen_def *mac = rtwdev->chip->mac_def;
228
229 mutex_lock(&rtwdev->mutex);
230 rtw89_leave_ps_mode(rtwdev);
231
232 *new_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_FCSFAIL |
233 FIF_BCN_PRBRESP_PROMISC | FIF_PROBE_REQ;
234
235 if (changed_flags & FIF_ALLMULTI) {
236 if (*new_flags & FIF_ALLMULTI)
237 rtwdev->hal.rx_fltr &= ~B_AX_A_MC;
238 else
239 rtwdev->hal.rx_fltr |= B_AX_A_MC;
240 }
241 if (changed_flags & FIF_FCSFAIL) {
242 if (*new_flags & FIF_FCSFAIL)
243 rtwdev->hal.rx_fltr |= B_AX_A_CRC32_ERR;
244 else
245 rtwdev->hal.rx_fltr &= ~B_AX_A_CRC32_ERR;
246 }
247 if (changed_flags & FIF_OTHER_BSS) {
248 if (*new_flags & FIF_OTHER_BSS)
249 rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
250 else
251 rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
252 }
253 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
254 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
255 rtwdev->hal.rx_fltr &= ~B_AX_A_BCN_CHK_EN;
256 rtwdev->hal.rx_fltr &= ~B_AX_A_BC;
257 rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
258 } else {
259 rtwdev->hal.rx_fltr |= B_AX_A_BCN_CHK_EN;
260 rtwdev->hal.rx_fltr |= B_AX_A_BC;
261 rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
262 }
263 }
264 if (changed_flags & FIF_PROBE_REQ) {
265 if (*new_flags & FIF_PROBE_REQ) {
266 rtwdev->hal.rx_fltr &= ~B_AX_A_BC_CAM_MATCH;
267 rtwdev->hal.rx_fltr &= ~B_AX_A_UC_CAM_MATCH;
268 } else {
269 rtwdev->hal.rx_fltr |= B_AX_A_BC_CAM_MATCH;
270 rtwdev->hal.rx_fltr |= B_AX_A_UC_CAM_MATCH;
271 }
272 }
273
274 rtw89_write32_mask(rtwdev,
275 rtw89_mac_reg_by_idx(rtwdev, mac->rx_fltr, RTW89_MAC_0),
276 B_AX_RX_FLTR_CFG_MASK,
277 rtwdev->hal.rx_fltr);
278 if (!rtwdev->dbcc_en)
279 goto out;
280 rtw89_write32_mask(rtwdev,
281 rtw89_mac_reg_by_idx(rtwdev, mac->rx_fltr, RTW89_MAC_1),
282 B_AX_RX_FLTR_CFG_MASK,
283 rtwdev->hal.rx_fltr);
284
285 out:
286 mutex_unlock(&rtwdev->mutex);
287 }
288
289 static const u8 ac_to_fw_idx[IEEE80211_NUM_ACS] = {
290 [IEEE80211_AC_VO] = 3,
291 [IEEE80211_AC_VI] = 2,
292 [IEEE80211_AC_BE] = 0,
293 [IEEE80211_AC_BK] = 1,
294 };
295
rtw89_aifsn_to_aifs(struct rtw89_dev * rtwdev,struct rtw89_vif * rtwvif,u8 aifsn)296 static u8 rtw89_aifsn_to_aifs(struct rtw89_dev *rtwdev,
297 struct rtw89_vif *rtwvif, u8 aifsn)
298 {
299 struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif);
300 const struct rtw89_chan *chan = rtw89_chan_get(rtwdev,
301 rtwvif->sub_entity_idx);
302 u8 slot_time;
303 u8 sifs;
304
305 slot_time = vif->bss_conf.use_short_slot ? 9 : 20;
306 sifs = chan->band_type == RTW89_BAND_5G ? 16 : 10;
307
308 return aifsn * slot_time + sifs;
309 }
310
____rtw89_conf_tx_edca(struct rtw89_dev * rtwdev,struct rtw89_vif * rtwvif,u16 ac)311 static void ____rtw89_conf_tx_edca(struct rtw89_dev *rtwdev,
312 struct rtw89_vif *rtwvif, u16 ac)
313 {
314 struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
315 u32 val;
316 u8 ecw_max, ecw_min;
317 u8 aifs;
318
319 /* 2^ecw - 1 = cw; ecw = log2(cw + 1) */
320 ecw_max = ilog2(params->cw_max + 1);
321 ecw_min = ilog2(params->cw_min + 1);
322 aifs = rtw89_aifsn_to_aifs(rtwdev, rtwvif, params->aifs);
323 val = FIELD_PREP(FW_EDCA_PARAM_TXOPLMT_MSK, params->txop) |
324 FIELD_PREP(FW_EDCA_PARAM_CWMAX_MSK, ecw_max) |
325 FIELD_PREP(FW_EDCA_PARAM_CWMIN_MSK, ecw_min) |
326 FIELD_PREP(FW_EDCA_PARAM_AIFS_MSK, aifs);
327 rtw89_fw_h2c_set_edca(rtwdev, rtwvif, ac_to_fw_idx[ac], val);
328 }
329
330 static const u32 ac_to_mu_edca_param[IEEE80211_NUM_ACS] = {
331 [IEEE80211_AC_VO] = R_AX_MUEDCA_VO_PARAM_0,
332 [IEEE80211_AC_VI] = R_AX_MUEDCA_VI_PARAM_0,
333 [IEEE80211_AC_BE] = R_AX_MUEDCA_BE_PARAM_0,
334 [IEEE80211_AC_BK] = R_AX_MUEDCA_BK_PARAM_0,
335 };
336
____rtw89_conf_tx_mu_edca(struct rtw89_dev * rtwdev,struct rtw89_vif * rtwvif,u16 ac)337 static void ____rtw89_conf_tx_mu_edca(struct rtw89_dev *rtwdev,
338 struct rtw89_vif *rtwvif, u16 ac)
339 {
340 struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
341 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca;
342 u8 aifs, aifsn;
343 u16 timer_32us;
344 u32 reg;
345 u32 val;
346
347 if (!params->mu_edca)
348 return;
349
350 mu_edca = ¶ms->mu_edca_param_rec;
351 aifsn = FIELD_GET(GENMASK(3, 0), mu_edca->aifsn);
352 aifs = aifsn ? rtw89_aifsn_to_aifs(rtwdev, rtwvif, aifsn) : 0;
353 timer_32us = mu_edca->mu_edca_timer << 8;
354
355 val = FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_TIMER_MASK, timer_32us) |
356 FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_CW_MASK, mu_edca->ecw_min_max) |
357 FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_AIFS_MASK, aifs);
358 reg = rtw89_mac_reg_by_idx(rtwdev, ac_to_mu_edca_param[ac], rtwvif->mac_idx);
359 rtw89_write32(rtwdev, reg, val);
360
361 rtw89_mac_set_hw_muedca_ctrl(rtwdev, rtwvif, true);
362 }
363
__rtw89_conf_tx(struct rtw89_dev * rtwdev,struct rtw89_vif * rtwvif,u16 ac)364 static void __rtw89_conf_tx(struct rtw89_dev *rtwdev,
365 struct rtw89_vif *rtwvif, u16 ac)
366 {
367 ____rtw89_conf_tx_edca(rtwdev, rtwvif, ac);
368 ____rtw89_conf_tx_mu_edca(rtwdev, rtwvif, ac);
369 }
370
rtw89_conf_tx(struct rtw89_dev * rtwdev,struct rtw89_vif * rtwvif)371 static void rtw89_conf_tx(struct rtw89_dev *rtwdev,
372 struct rtw89_vif *rtwvif)
373 {
374 u16 ac;
375
376 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
377 __rtw89_conf_tx(rtwdev, rtwvif, ac);
378 }
379
rtw89_station_mode_sta_assoc(struct rtw89_dev * rtwdev,struct ieee80211_vif * vif,struct ieee80211_bss_conf * conf)380 static void rtw89_station_mode_sta_assoc(struct rtw89_dev *rtwdev,
381 struct ieee80211_vif *vif,
382 struct ieee80211_bss_conf *conf)
383 {
384 struct ieee80211_sta *sta;
385
386 if (vif->type != NL80211_IFTYPE_STATION)
387 return;
388
389 sta = ieee80211_find_sta(vif, conf->bssid);
390 if (!sta) {
391 rtw89_err(rtwdev, "can't find sta to set sta_assoc state\n");
392 return;
393 }
394
395 rtw89_vif_type_mapping(vif, true);
396
397 rtw89_core_sta_assoc(rtwdev, vif, sta);
398 }
399
rtw89_ops_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * conf,u64 changed)400 static void rtw89_ops_bss_info_changed(struct ieee80211_hw *hw,
401 struct ieee80211_vif *vif,
402 struct ieee80211_bss_conf *conf,
403 u64 changed)
404 {
405 struct rtw89_dev *rtwdev = hw->priv;
406 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
407
408 mutex_lock(&rtwdev->mutex);
409 rtw89_leave_ps_mode(rtwdev);
410
411 if (changed & BSS_CHANGED_ASSOC) {
412 if (vif->cfg.assoc) {
413 rtw89_station_mode_sta_assoc(rtwdev, vif, conf);
414 rtw89_phy_set_bss_color(rtwdev, vif);
415 rtw89_chip_cfg_txpwr_ul_tb_offset(rtwdev, vif);
416 rtw89_mac_port_update(rtwdev, rtwvif);
417 rtw89_mac_set_he_obss_narrow_bw_ru(rtwdev, vif);
418
419 rtw89_queue_chanctx_work(rtwdev);
420 } else {
421 /* Abort ongoing scan if cancel_scan isn't issued
422 * when disconnected by peer
423 */
424 if (rtwdev->scanning)
425 rtw89_hw_scan_abort(rtwdev, vif);
426 }
427 }
428
429 if (changed & BSS_CHANGED_BSSID) {
430 ether_addr_copy(rtwvif->bssid, conf->bssid);
431 rtw89_cam_bssid_changed(rtwdev, rtwvif);
432 rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
433 }
434
435 if (changed & BSS_CHANGED_BEACON)
436 rtw89_fw_h2c_update_beacon(rtwdev, rtwvif);
437
438 if (changed & BSS_CHANGED_ERP_SLOT)
439 rtw89_conf_tx(rtwdev, rtwvif);
440
441 if (changed & BSS_CHANGED_HE_BSS_COLOR)
442 rtw89_phy_set_bss_color(rtwdev, vif);
443
444 if (changed & BSS_CHANGED_MU_GROUPS)
445 rtw89_mac_bf_set_gid_table(rtwdev, vif, conf);
446
447 if (changed & BSS_CHANGED_P2P_PS)
448 rtw89_process_p2p_ps(rtwdev, vif);
449
450 if (changed & BSS_CHANGED_CQM)
451 rtw89_fw_h2c_set_bcn_fltr_cfg(rtwdev, vif, true);
452
453 if (changed & BSS_CHANGED_PS)
454 rtw89_recalc_lps(rtwdev);
455
456 mutex_unlock(&rtwdev->mutex);
457 }
458
rtw89_ops_start_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)459 static int rtw89_ops_start_ap(struct ieee80211_hw *hw,
460 struct ieee80211_vif *vif,
461 struct ieee80211_bss_conf *link_conf)
462 {
463 struct rtw89_dev *rtwdev = hw->priv;
464 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
465 const struct rtw89_chan *chan;
466
467 mutex_lock(&rtwdev->mutex);
468
469 chan = rtw89_chan_get(rtwdev, rtwvif->sub_entity_idx);
470 if (chan->band_type == RTW89_BAND_6G) {
471 mutex_unlock(&rtwdev->mutex);
472 return -EOPNOTSUPP;
473 }
474
475 ether_addr_copy(rtwvif->bssid, vif->bss_conf.bssid);
476 rtw89_cam_bssid_changed(rtwdev, rtwvif);
477 rtw89_mac_port_update(rtwdev, rtwvif);
478 rtw89_fw_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
479 rtw89_fw_h2c_role_maintain(rtwdev, rtwvif, NULL, RTW89_ROLE_TYPE_CHANGE);
480 rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
481 rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
482 rtw89_chip_rfk_channel(rtwdev);
483
484 rtw89_queue_chanctx_work(rtwdev);
485 mutex_unlock(&rtwdev->mutex);
486
487 return 0;
488 }
489
490 static
rtw89_ops_stop_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)491 void rtw89_ops_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
492 struct ieee80211_bss_conf *link_conf)
493 {
494 struct rtw89_dev *rtwdev = hw->priv;
495 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
496
497 mutex_lock(&rtwdev->mutex);
498 rtw89_mac_stop_ap(rtwdev, rtwvif);
499 rtw89_fw_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
500 rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
501 mutex_unlock(&rtwdev->mutex);
502 }
503
rtw89_ops_set_tim(struct ieee80211_hw * hw,struct ieee80211_sta * sta,bool set)504 static int rtw89_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
505 bool set)
506 {
507 struct rtw89_dev *rtwdev = hw->priv;
508 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
509 struct rtw89_vif *rtwvif = rtwsta->rtwvif;
510
511 ieee80211_queue_work(rtwdev->hw, &rtwvif->update_beacon_work);
512
513 return 0;
514 }
515
rtw89_ops_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id,u16 ac,const struct ieee80211_tx_queue_params * params)516 static int rtw89_ops_conf_tx(struct ieee80211_hw *hw,
517 struct ieee80211_vif *vif,
518 unsigned int link_id, u16 ac,
519 const struct ieee80211_tx_queue_params *params)
520 {
521 struct rtw89_dev *rtwdev = hw->priv;
522 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
523
524 mutex_lock(&rtwdev->mutex);
525 rtw89_leave_ps_mode(rtwdev);
526 rtwvif->tx_params[ac] = *params;
527 __rtw89_conf_tx(rtwdev, rtwvif, ac);
528 mutex_unlock(&rtwdev->mutex);
529
530 return 0;
531 }
532
__rtw89_ops_sta_state(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,enum ieee80211_sta_state old_state,enum ieee80211_sta_state new_state)533 static int __rtw89_ops_sta_state(struct ieee80211_hw *hw,
534 struct ieee80211_vif *vif,
535 struct ieee80211_sta *sta,
536 enum ieee80211_sta_state old_state,
537 enum ieee80211_sta_state new_state)
538 {
539 struct rtw89_dev *rtwdev = hw->priv;
540
541 if (old_state == IEEE80211_STA_NOTEXIST &&
542 new_state == IEEE80211_STA_NONE)
543 return rtw89_core_sta_add(rtwdev, vif, sta);
544
545 if (old_state == IEEE80211_STA_AUTH &&
546 new_state == IEEE80211_STA_ASSOC) {
547 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
548 return 0; /* defer to bss_info_changed to have vif info */
549 return rtw89_core_sta_assoc(rtwdev, vif, sta);
550 }
551
552 if (old_state == IEEE80211_STA_ASSOC &&
553 new_state == IEEE80211_STA_AUTH)
554 return rtw89_core_sta_disassoc(rtwdev, vif, sta);
555
556 if (old_state == IEEE80211_STA_AUTH &&
557 new_state == IEEE80211_STA_NONE)
558 return rtw89_core_sta_disconnect(rtwdev, vif, sta);
559
560 if (old_state == IEEE80211_STA_NONE &&
561 new_state == IEEE80211_STA_NOTEXIST)
562 return rtw89_core_sta_remove(rtwdev, vif, sta);
563
564 return 0;
565 }
566
rtw89_ops_sta_state(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,enum ieee80211_sta_state old_state,enum ieee80211_sta_state new_state)567 static int rtw89_ops_sta_state(struct ieee80211_hw *hw,
568 struct ieee80211_vif *vif,
569 struct ieee80211_sta *sta,
570 enum ieee80211_sta_state old_state,
571 enum ieee80211_sta_state new_state)
572 {
573 struct rtw89_dev *rtwdev = hw->priv;
574 int ret;
575
576 mutex_lock(&rtwdev->mutex);
577 rtw89_leave_ps_mode(rtwdev);
578 ret = __rtw89_ops_sta_state(hw, vif, sta, old_state, new_state);
579 mutex_unlock(&rtwdev->mutex);
580
581 return ret;
582 }
583
rtw89_ops_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)584 static int rtw89_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
585 struct ieee80211_vif *vif,
586 struct ieee80211_sta *sta,
587 struct ieee80211_key_conf *key)
588 {
589 struct rtw89_dev *rtwdev = hw->priv;
590 int ret = 0;
591
592 mutex_lock(&rtwdev->mutex);
593 rtw89_leave_ps_mode(rtwdev);
594
595 switch (cmd) {
596 case SET_KEY:
597 rtw89_btc_ntfy_specific_packet(rtwdev, PACKET_EAPOL_END);
598 ret = rtw89_cam_sec_key_add(rtwdev, vif, sta, key);
599 if (ret && ret != -EOPNOTSUPP) {
600 rtw89_err(rtwdev, "failed to add key to sec cam\n");
601 goto out;
602 }
603 break;
604 case DISABLE_KEY:
605 rtw89_hci_flush_queues(rtwdev, BIT(rtwdev->hw->queues) - 1,
606 false);
607 rtw89_mac_flush_txq(rtwdev, BIT(rtwdev->hw->queues) - 1, false);
608 ret = rtw89_cam_sec_key_del(rtwdev, vif, sta, key, true);
609 if (ret) {
610 rtw89_err(rtwdev, "failed to remove key from sec cam\n");
611 goto out;
612 }
613 break;
614 }
615
616 out:
617 mutex_unlock(&rtwdev->mutex);
618
619 return ret;
620 }
621
rtw89_ops_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)622 static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw,
623 struct ieee80211_vif *vif,
624 struct ieee80211_ampdu_params *params)
625 {
626 struct rtw89_dev *rtwdev = hw->priv;
627 struct ieee80211_sta *sta = params->sta;
628 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
629 u16 tid = params->tid;
630 struct ieee80211_txq *txq = sta->txq[tid];
631 struct rtw89_txq *rtwtxq = (struct rtw89_txq *)txq->drv_priv;
632
633 switch (params->action) {
634 case IEEE80211_AMPDU_TX_START:
635 return IEEE80211_AMPDU_TX_START_IMMEDIATE;
636 case IEEE80211_AMPDU_TX_STOP_CONT:
637 case IEEE80211_AMPDU_TX_STOP_FLUSH:
638 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
639 mutex_lock(&rtwdev->mutex);
640 clear_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
641 mutex_unlock(&rtwdev->mutex);
642 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
643 break;
644 case IEEE80211_AMPDU_TX_OPERATIONAL:
645 mutex_lock(&rtwdev->mutex);
646 set_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
647 rtwsta->ampdu_params[tid].agg_num = params->buf_size;
648 rtwsta->ampdu_params[tid].amsdu = params->amsdu;
649 rtw89_leave_ps_mode(rtwdev);
650 mutex_unlock(&rtwdev->mutex);
651 break;
652 case IEEE80211_AMPDU_RX_START:
653 mutex_lock(&rtwdev->mutex);
654 rtw89_fw_h2c_ba_cam(rtwdev, rtwsta, true, params);
655 mutex_unlock(&rtwdev->mutex);
656 break;
657 case IEEE80211_AMPDU_RX_STOP:
658 mutex_lock(&rtwdev->mutex);
659 rtw89_fw_h2c_ba_cam(rtwdev, rtwsta, false, params);
660 mutex_unlock(&rtwdev->mutex);
661 break;
662 default:
663 WARN_ON(1);
664 return -ENOTSUPP;
665 }
666
667 return 0;
668 }
669
rtw89_ops_set_rts_threshold(struct ieee80211_hw * hw,u32 value)670 static int rtw89_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
671 {
672 struct rtw89_dev *rtwdev = hw->priv;
673
674 mutex_lock(&rtwdev->mutex);
675 rtw89_leave_ps_mode(rtwdev);
676 if (test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
677 rtw89_mac_update_rts_threshold(rtwdev, RTW89_MAC_0);
678 mutex_unlock(&rtwdev->mutex);
679
680 return 0;
681 }
682
rtw89_ops_sta_statistics(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct station_info * sinfo)683 static void rtw89_ops_sta_statistics(struct ieee80211_hw *hw,
684 struct ieee80211_vif *vif,
685 struct ieee80211_sta *sta,
686 struct station_info *sinfo)
687 {
688 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
689
690 sinfo->txrate = rtwsta->ra_report.txrate;
691 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
692 }
693
694 static
__rtw89_drop_packets(struct rtw89_dev * rtwdev,struct ieee80211_vif * vif)695 void __rtw89_drop_packets(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif)
696 {
697 struct rtw89_vif *rtwvif;
698
699 if (vif) {
700 rtwvif = (struct rtw89_vif *)vif->drv_priv;
701 rtw89_mac_pkt_drop_vif(rtwdev, rtwvif);
702 } else {
703 rtw89_for_each_rtwvif(rtwdev, rtwvif)
704 rtw89_mac_pkt_drop_vif(rtwdev, rtwvif);
705 }
706 }
707
rtw89_ops_flush(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 queues,bool drop)708 static void rtw89_ops_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
709 u32 queues, bool drop)
710 {
711 struct rtw89_dev *rtwdev = hw->priv;
712
713 mutex_lock(&rtwdev->mutex);
714 rtw89_leave_lps(rtwdev);
715 rtw89_hci_flush_queues(rtwdev, queues, drop);
716
717 if (drop && !RTW89_CHK_FW_FEATURE(NO_PACKET_DROP, &rtwdev->fw))
718 __rtw89_drop_packets(rtwdev, vif);
719 else
720 rtw89_mac_flush_txq(rtwdev, queues, drop);
721
722 mutex_unlock(&rtwdev->mutex);
723 }
724
725 struct rtw89_iter_bitrate_mask_data {
726 struct rtw89_dev *rtwdev;
727 struct ieee80211_vif *vif;
728 const struct cfg80211_bitrate_mask *mask;
729 };
730
rtw89_ra_mask_info_update_iter(void * data,struct ieee80211_sta * sta)731 static void rtw89_ra_mask_info_update_iter(void *data, struct ieee80211_sta *sta)
732 {
733 struct rtw89_iter_bitrate_mask_data *br_data = data;
734 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
735 struct ieee80211_vif *vif = rtwvif_to_vif(rtwsta->rtwvif);
736
737 if (vif != br_data->vif || vif->p2p)
738 return;
739
740 rtwsta->use_cfg_mask = true;
741 rtwsta->mask = *br_data->mask;
742 rtw89_phy_ra_updata_sta(br_data->rtwdev, sta, IEEE80211_RC_SUPP_RATES_CHANGED);
743 }
744
rtw89_ra_mask_info_update(struct rtw89_dev * rtwdev,struct ieee80211_vif * vif,const struct cfg80211_bitrate_mask * mask)745 static void rtw89_ra_mask_info_update(struct rtw89_dev *rtwdev,
746 struct ieee80211_vif *vif,
747 const struct cfg80211_bitrate_mask *mask)
748 {
749 struct rtw89_iter_bitrate_mask_data br_data = { .rtwdev = rtwdev,
750 .vif = vif,
751 .mask = mask};
752
753 ieee80211_iterate_stations_atomic(rtwdev->hw, rtw89_ra_mask_info_update_iter,
754 &br_data);
755 }
756
rtw89_ops_set_bitrate_mask(struct ieee80211_hw * hw,struct ieee80211_vif * vif,const struct cfg80211_bitrate_mask * mask)757 static int rtw89_ops_set_bitrate_mask(struct ieee80211_hw *hw,
758 struct ieee80211_vif *vif,
759 const struct cfg80211_bitrate_mask *mask)
760 {
761 struct rtw89_dev *rtwdev = hw->priv;
762
763 mutex_lock(&rtwdev->mutex);
764 rtw89_phy_rate_pattern_vif(rtwdev, vif, mask);
765 rtw89_ra_mask_info_update(rtwdev, vif, mask);
766 mutex_unlock(&rtwdev->mutex);
767
768 return 0;
769 }
770
771 static
rtw89_ops_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)772 int rtw89_ops_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
773 {
774 struct rtw89_dev *rtwdev = hw->priv;
775 struct rtw89_hal *hal = &rtwdev->hal;
776
777 if (hal->ant_diversity) {
778 if (tx_ant != rx_ant || hweight32(tx_ant) != 1)
779 return -EINVAL;
780 } else if (rx_ant != hw->wiphy->available_antennas_rx && rx_ant != hal->antenna_rx) {
781 return -EINVAL;
782 }
783
784 mutex_lock(&rtwdev->mutex);
785 hal->antenna_tx = tx_ant;
786 hal->antenna_rx = rx_ant;
787 hal->tx_path_diversity = false;
788 hal->ant_diversity_fixed = true;
789 mutex_unlock(&rtwdev->mutex);
790
791 return 0;
792 }
793
794 static
rtw89_ops_get_antenna(struct ieee80211_hw * hw,u32 * tx_ant,u32 * rx_ant)795 int rtw89_ops_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
796 {
797 struct rtw89_dev *rtwdev = hw->priv;
798 struct rtw89_hal *hal = &rtwdev->hal;
799
800 *tx_ant = hal->antenna_tx;
801 *rx_ant = hal->antenna_rx;
802
803 return 0;
804 }
805
rtw89_ops_sw_scan_start(struct ieee80211_hw * hw,struct ieee80211_vif * vif,const u8 * mac_addr)806 static void rtw89_ops_sw_scan_start(struct ieee80211_hw *hw,
807 struct ieee80211_vif *vif,
808 const u8 *mac_addr)
809 {
810 struct rtw89_dev *rtwdev = hw->priv;
811 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
812
813 mutex_lock(&rtwdev->mutex);
814 rtw89_core_scan_start(rtwdev, rtwvif, mac_addr, false);
815 mutex_unlock(&rtwdev->mutex);
816 }
817
rtw89_ops_sw_scan_complete(struct ieee80211_hw * hw,struct ieee80211_vif * vif)818 static void rtw89_ops_sw_scan_complete(struct ieee80211_hw *hw,
819 struct ieee80211_vif *vif)
820 {
821 struct rtw89_dev *rtwdev = hw->priv;
822
823 mutex_lock(&rtwdev->mutex);
824 rtw89_core_scan_complete(rtwdev, vif, false);
825 mutex_unlock(&rtwdev->mutex);
826 }
827
rtw89_ops_reconfig_complete(struct ieee80211_hw * hw,enum ieee80211_reconfig_type reconfig_type)828 static void rtw89_ops_reconfig_complete(struct ieee80211_hw *hw,
829 enum ieee80211_reconfig_type reconfig_type)
830 {
831 struct rtw89_dev *rtwdev = hw->priv;
832
833 if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART)
834 rtw89_ser_recfg_done(rtwdev);
835 }
836
rtw89_ops_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_scan_request * req)837 static int rtw89_ops_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
838 struct ieee80211_scan_request *req)
839 {
840 struct rtw89_dev *rtwdev = hw->priv;
841 struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
842 int ret = 0;
843
844 if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
845 return 1;
846
847 if (rtwdev->scanning || rtwvif->offchan)
848 return -EBUSY;
849
850 mutex_lock(&rtwdev->mutex);
851 rtw89_hw_scan_start(rtwdev, vif, req);
852 ret = rtw89_hw_scan_offload(rtwdev, vif, true);
853 if (ret) {
854 rtw89_hw_scan_abort(rtwdev, vif);
855 rtw89_err(rtwdev, "HW scan failed with status: %d\n", ret);
856 }
857 mutex_unlock(&rtwdev->mutex);
858
859 return ret;
860 }
861
rtw89_ops_cancel_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)862 static void rtw89_ops_cancel_hw_scan(struct ieee80211_hw *hw,
863 struct ieee80211_vif *vif)
864 {
865 struct rtw89_dev *rtwdev = hw->priv;
866
867 if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
868 return;
869
870 if (!rtwdev->scanning)
871 return;
872
873 mutex_lock(&rtwdev->mutex);
874 rtw89_hw_scan_abort(rtwdev, vif);
875 mutex_unlock(&rtwdev->mutex);
876 }
877
rtw89_ops_sta_rc_update(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,u32 changed)878 static void rtw89_ops_sta_rc_update(struct ieee80211_hw *hw,
879 struct ieee80211_vif *vif,
880 struct ieee80211_sta *sta, u32 changed)
881 {
882 struct rtw89_dev *rtwdev = hw->priv;
883
884 rtw89_phy_ra_updata_sta(rtwdev, sta, changed);
885 }
886
rtw89_ops_add_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx)887 static int rtw89_ops_add_chanctx(struct ieee80211_hw *hw,
888 struct ieee80211_chanctx_conf *ctx)
889 {
890 struct rtw89_dev *rtwdev = hw->priv;
891 int ret;
892
893 mutex_lock(&rtwdev->mutex);
894 ret = rtw89_chanctx_ops_add(rtwdev, ctx);
895 mutex_unlock(&rtwdev->mutex);
896
897 return ret;
898 }
899
rtw89_ops_remove_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx)900 static void rtw89_ops_remove_chanctx(struct ieee80211_hw *hw,
901 struct ieee80211_chanctx_conf *ctx)
902 {
903 struct rtw89_dev *rtwdev = hw->priv;
904
905 mutex_lock(&rtwdev->mutex);
906 rtw89_chanctx_ops_remove(rtwdev, ctx);
907 mutex_unlock(&rtwdev->mutex);
908 }
909
rtw89_ops_change_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * ctx,u32 changed)910 static void rtw89_ops_change_chanctx(struct ieee80211_hw *hw,
911 struct ieee80211_chanctx_conf *ctx,
912 u32 changed)
913 {
914 struct rtw89_dev *rtwdev = hw->priv;
915
916 mutex_lock(&rtwdev->mutex);
917 rtw89_chanctx_ops_change(rtwdev, ctx, changed);
918 mutex_unlock(&rtwdev->mutex);
919 }
920
rtw89_ops_assign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * ctx)921 static int rtw89_ops_assign_vif_chanctx(struct ieee80211_hw *hw,
922 struct ieee80211_vif *vif,
923 struct ieee80211_bss_conf *link_conf,
924 struct ieee80211_chanctx_conf *ctx)
925 {
926 struct rtw89_dev *rtwdev = hw->priv;
927 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
928 int ret;
929
930 mutex_lock(&rtwdev->mutex);
931 ret = rtw89_chanctx_ops_assign_vif(rtwdev, rtwvif, ctx);
932 mutex_unlock(&rtwdev->mutex);
933
934 return ret;
935 }
936
rtw89_ops_unassign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * ctx)937 static void rtw89_ops_unassign_vif_chanctx(struct ieee80211_hw *hw,
938 struct ieee80211_vif *vif,
939 struct ieee80211_bss_conf *link_conf,
940 struct ieee80211_chanctx_conf *ctx)
941 {
942 struct rtw89_dev *rtwdev = hw->priv;
943 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
944
945 mutex_lock(&rtwdev->mutex);
946 rtw89_chanctx_ops_unassign_vif(rtwdev, rtwvif, ctx);
947 mutex_unlock(&rtwdev->mutex);
948 }
949
rtw89_ops_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel * chan,int duration,enum ieee80211_roc_type type)950 static int rtw89_ops_remain_on_channel(struct ieee80211_hw *hw,
951 struct ieee80211_vif *vif,
952 struct ieee80211_channel *chan,
953 int duration,
954 enum ieee80211_roc_type type)
955 {
956 struct rtw89_dev *rtwdev = hw->priv;
957 struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
958 struct rtw89_roc *roc = &rtwvif->roc;
959
960 if (!vif)
961 return -EINVAL;
962
963 mutex_lock(&rtwdev->mutex);
964
965 if (roc->state != RTW89_ROC_IDLE) {
966 mutex_unlock(&rtwdev->mutex);
967 return -EBUSY;
968 }
969
970 if (rtwdev->scanning)
971 rtw89_hw_scan_abort(rtwdev, vif);
972
973 if (type == IEEE80211_ROC_TYPE_MGMT_TX)
974 roc->state = RTW89_ROC_MGMT;
975 else
976 roc->state = RTW89_ROC_NORMAL;
977
978 roc->duration = duration;
979 roc->chan = *chan;
980 roc->type = type;
981
982 rtw89_roc_start(rtwdev, rtwvif);
983
984 mutex_unlock(&rtwdev->mutex);
985
986 return 0;
987 }
988
rtw89_ops_cancel_remain_on_channel(struct ieee80211_hw * hw,struct ieee80211_vif * vif)989 static int rtw89_ops_cancel_remain_on_channel(struct ieee80211_hw *hw,
990 struct ieee80211_vif *vif)
991 {
992 struct rtw89_dev *rtwdev = hw->priv;
993 struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
994
995 if (!rtwvif)
996 return -EINVAL;
997
998 cancel_delayed_work_sync(&rtwvif->roc.roc_work);
999
1000 mutex_lock(&rtwdev->mutex);
1001 rtw89_roc_end(rtwdev, rtwvif);
1002 mutex_unlock(&rtwdev->mutex);
1003
1004 return 0;
1005 }
1006
rtw89_set_tid_config_iter(void * data,struct ieee80211_sta * sta)1007 static void rtw89_set_tid_config_iter(void *data, struct ieee80211_sta *sta)
1008 {
1009 struct cfg80211_tid_config *tid_config = data;
1010 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
1011 struct rtw89_dev *rtwdev = rtwsta->rtwvif->rtwdev;
1012
1013 rtw89_core_set_tid_config(rtwdev, sta, tid_config);
1014 }
1015
rtw89_ops_set_tid_config(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct cfg80211_tid_config * tid_config)1016 static int rtw89_ops_set_tid_config(struct ieee80211_hw *hw,
1017 struct ieee80211_vif *vif,
1018 struct ieee80211_sta *sta,
1019 struct cfg80211_tid_config *tid_config)
1020 {
1021 struct rtw89_dev *rtwdev = hw->priv;
1022
1023 mutex_lock(&rtwdev->mutex);
1024 if (sta)
1025 rtw89_core_set_tid_config(rtwdev, sta, tid_config);
1026 else
1027 ieee80211_iterate_stations_atomic(rtwdev->hw,
1028 rtw89_set_tid_config_iter,
1029 tid_config);
1030 mutex_unlock(&rtwdev->mutex);
1031
1032 return 0;
1033 }
1034
1035 #ifdef CONFIG_PM
rtw89_ops_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)1036 static int rtw89_ops_suspend(struct ieee80211_hw *hw,
1037 struct cfg80211_wowlan *wowlan)
1038 {
1039 struct rtw89_dev *rtwdev = hw->priv;
1040 int ret;
1041
1042 set_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
1043 cancel_delayed_work_sync(&rtwdev->track_work);
1044
1045 mutex_lock(&rtwdev->mutex);
1046 ret = rtw89_wow_suspend(rtwdev, wowlan);
1047 mutex_unlock(&rtwdev->mutex);
1048
1049 if (ret) {
1050 rtw89_warn(rtwdev, "failed to suspend for wow %d\n", ret);
1051 clear_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
1052 return 1;
1053 }
1054
1055 return 0;
1056 }
1057
rtw89_ops_resume(struct ieee80211_hw * hw)1058 static int rtw89_ops_resume(struct ieee80211_hw *hw)
1059 {
1060 struct rtw89_dev *rtwdev = hw->priv;
1061 int ret;
1062
1063 mutex_lock(&rtwdev->mutex);
1064 ret = rtw89_wow_resume(rtwdev);
1065 if (ret)
1066 rtw89_warn(rtwdev, "failed to resume for wow %d\n", ret);
1067 mutex_unlock(&rtwdev->mutex);
1068
1069 clear_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
1070 ieee80211_queue_delayed_work(rtwdev->hw, &rtwdev->track_work,
1071 RTW89_TRACK_WORK_PERIOD);
1072
1073 return ret ? 1 : 0;
1074 }
1075
rtw89_ops_set_wakeup(struct ieee80211_hw * hw,bool enabled)1076 static void rtw89_ops_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1077 {
1078 struct rtw89_dev *rtwdev = hw->priv;
1079
1080 device_set_wakeup_enable(rtwdev->dev, enabled);
1081 }
1082 #endif
1083
1084 const struct ieee80211_ops rtw89_ops = {
1085 .tx = rtw89_ops_tx,
1086 .wake_tx_queue = rtw89_ops_wake_tx_queue,
1087 .start = rtw89_ops_start,
1088 .stop = rtw89_ops_stop,
1089 .config = rtw89_ops_config,
1090 .add_interface = rtw89_ops_add_interface,
1091 .change_interface = rtw89_ops_change_interface,
1092 .remove_interface = rtw89_ops_remove_interface,
1093 .configure_filter = rtw89_ops_configure_filter,
1094 .bss_info_changed = rtw89_ops_bss_info_changed,
1095 .start_ap = rtw89_ops_start_ap,
1096 .stop_ap = rtw89_ops_stop_ap,
1097 .set_tim = rtw89_ops_set_tim,
1098 .conf_tx = rtw89_ops_conf_tx,
1099 .sta_state = rtw89_ops_sta_state,
1100 .set_key = rtw89_ops_set_key,
1101 .ampdu_action = rtw89_ops_ampdu_action,
1102 .set_rts_threshold = rtw89_ops_set_rts_threshold,
1103 .sta_statistics = rtw89_ops_sta_statistics,
1104 .flush = rtw89_ops_flush,
1105 .set_bitrate_mask = rtw89_ops_set_bitrate_mask,
1106 .set_antenna = rtw89_ops_set_antenna,
1107 .get_antenna = rtw89_ops_get_antenna,
1108 .sw_scan_start = rtw89_ops_sw_scan_start,
1109 .sw_scan_complete = rtw89_ops_sw_scan_complete,
1110 .reconfig_complete = rtw89_ops_reconfig_complete,
1111 .hw_scan = rtw89_ops_hw_scan,
1112 .cancel_hw_scan = rtw89_ops_cancel_hw_scan,
1113 .add_chanctx = rtw89_ops_add_chanctx,
1114 .remove_chanctx = rtw89_ops_remove_chanctx,
1115 .change_chanctx = rtw89_ops_change_chanctx,
1116 .assign_vif_chanctx = rtw89_ops_assign_vif_chanctx,
1117 .unassign_vif_chanctx = rtw89_ops_unassign_vif_chanctx,
1118 .remain_on_channel = rtw89_ops_remain_on_channel,
1119 .cancel_remain_on_channel = rtw89_ops_cancel_remain_on_channel,
1120 .set_sar_specs = rtw89_ops_set_sar_specs,
1121 .sta_rc_update = rtw89_ops_sta_rc_update,
1122 .set_tid_config = rtw89_ops_set_tid_config,
1123 #ifdef CONFIG_PM
1124 .suspend = rtw89_ops_suspend,
1125 .resume = rtw89_ops_resume,
1126 .set_wakeup = rtw89_ops_set_wakeup,
1127 #endif
1128 };
1129 EXPORT_SYMBOL(rtw89_ops);
1130