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