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