1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2019-2020 Realtek Corporation
16 static void rtw89_ops_tx(struct ieee80211_hw *hw,
17 struct ieee80211_tx_control *control,
20 struct rtw89_dev *rtwdev = hw->priv;
21 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
22 struct ieee80211_vif *vif = info->control.vif;
23 struct ieee80211_sta *sta = control->sta;
26 ret = rtw89_core_tx_write(rtwdev, vif, sta, skb, &qsel);
28 rtw89_err(rtwdev, "failed to transmit skb: %d\n", ret);
29 ieee80211_free_txskb(hw, skb);
32 rtw89_core_tx_kick_off(rtwdev, qsel);
35 static void rtw89_ops_wake_tx_queue(struct ieee80211_hw *hw,
36 struct ieee80211_txq *txq)
38 struct rtw89_dev *rtwdev = hw->priv;
40 ieee80211_schedule_txq(hw, txq);
41 queue_work(rtwdev->txq_wq, &rtwdev->txq_work);
44 static int rtw89_ops_start(struct ieee80211_hw *hw)
46 struct rtw89_dev *rtwdev = hw->priv;
49 mutex_lock(&rtwdev->mutex);
50 ret = rtw89_core_start(rtwdev);
51 mutex_unlock(&rtwdev->mutex);
56 static void rtw89_ops_stop(struct ieee80211_hw *hw)
58 struct rtw89_dev *rtwdev = hw->priv;
60 mutex_lock(&rtwdev->mutex);
61 rtw89_core_stop(rtwdev);
62 mutex_unlock(&rtwdev->mutex);
65 static int rtw89_ops_config(struct ieee80211_hw *hw, u32 changed)
67 struct rtw89_dev *rtwdev = hw->priv;
69 /* let previous ips work finish to ensure we don't leave ips twice */
70 cancel_work_sync(&rtwdev->ips_work);
72 mutex_lock(&rtwdev->mutex);
73 rtw89_leave_ps_mode(rtwdev);
75 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
76 !(hw->conf.flags & IEEE80211_CONF_IDLE))
77 rtw89_leave_ips(rtwdev);
79 if (changed & IEEE80211_CONF_CHANGE_PS) {
80 if (hw->conf.flags & IEEE80211_CONF_PS) {
81 rtwdev->lps_enabled = true;
83 rtw89_leave_lps(rtwdev);
84 rtwdev->lps_enabled = false;
88 if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
89 rtw89_set_channel(rtwdev);
91 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
92 (hw->conf.flags & IEEE80211_CONF_IDLE))
93 rtw89_enter_ips(rtwdev);
95 mutex_unlock(&rtwdev->mutex);
100 static int rtw89_ops_add_interface(struct ieee80211_hw *hw,
101 struct ieee80211_vif *vif)
103 struct rtw89_dev *rtwdev = hw->priv;
104 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
107 mutex_lock(&rtwdev->mutex);
108 rtwvif->rtwdev = rtwdev;
109 list_add_tail(&rtwvif->list, &rtwdev->rtwvifs_list);
110 INIT_WORK(&rtwvif->update_beacon_work, rtw89_core_update_beacon_work);
111 rtw89_leave_ps_mode(rtwdev);
113 rtw89_traffic_stats_init(rtwdev, &rtwvif->stats);
114 rtw89_vif_type_mapping(vif, false);
115 rtwvif->port = rtw89_core_acquire_bit_map(rtwdev->hw_port,
117 if (rtwvif->port == RTW89_PORT_NUM) {
122 rtwvif->bcn_hit_cond = 0;
123 rtwvif->mac_idx = RTW89_MAC_0;
124 rtwvif->phy_idx = RTW89_PHY_0;
125 rtwvif->hit_rule = 0;
126 ether_addr_copy(rtwvif->mac_addr, vif->addr);
128 ret = rtw89_mac_add_vif(rtwdev, rtwvif);
130 rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
134 rtw89_core_txq_init(rtwdev, vif->txq);
136 rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_START);
138 mutex_unlock(&rtwdev->mutex);
143 static void rtw89_ops_remove_interface(struct ieee80211_hw *hw,
144 struct ieee80211_vif *vif)
146 struct rtw89_dev *rtwdev = hw->priv;
147 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
149 cancel_work_sync(&rtwvif->update_beacon_work);
151 mutex_lock(&rtwdev->mutex);
152 rtw89_leave_ps_mode(rtwdev);
153 rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_STOP);
154 rtw89_mac_remove_vif(rtwdev, rtwvif);
155 rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
156 list_del_init(&rtwvif->list);
157 mutex_unlock(&rtwdev->mutex);
160 static void rtw89_ops_configure_filter(struct ieee80211_hw *hw,
161 unsigned int changed_flags,
162 unsigned int *new_flags,
165 struct rtw89_dev *rtwdev = hw->priv;
167 mutex_lock(&rtwdev->mutex);
168 rtw89_leave_ps_mode(rtwdev);
170 *new_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_FCSFAIL |
171 FIF_BCN_PRBRESP_PROMISC | FIF_PROBE_REQ;
173 if (changed_flags & FIF_ALLMULTI) {
174 if (*new_flags & FIF_ALLMULTI)
175 rtwdev->hal.rx_fltr &= ~B_AX_A_MC;
177 rtwdev->hal.rx_fltr |= B_AX_A_MC;
179 if (changed_flags & FIF_FCSFAIL) {
180 if (*new_flags & FIF_FCSFAIL)
181 rtwdev->hal.rx_fltr |= B_AX_A_CRC32_ERR;
183 rtwdev->hal.rx_fltr &= ~B_AX_A_CRC32_ERR;
185 if (changed_flags & FIF_OTHER_BSS) {
186 if (*new_flags & FIF_OTHER_BSS)
187 rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
189 rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
191 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
192 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
193 rtwdev->hal.rx_fltr &= ~B_AX_A_BCN_CHK_EN;
194 rtwdev->hal.rx_fltr &= ~B_AX_A_BC;
195 rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
197 rtwdev->hal.rx_fltr |= B_AX_A_BCN_CHK_EN;
198 rtwdev->hal.rx_fltr |= B_AX_A_BC;
199 rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
202 if (changed_flags & FIF_PROBE_REQ) {
203 if (*new_flags & FIF_PROBE_REQ) {
204 rtwdev->hal.rx_fltr &= ~B_AX_A_BC_CAM_MATCH;
205 rtwdev->hal.rx_fltr &= ~B_AX_A_UC_CAM_MATCH;
207 rtwdev->hal.rx_fltr |= B_AX_A_BC_CAM_MATCH;
208 rtwdev->hal.rx_fltr |= B_AX_A_UC_CAM_MATCH;
212 rtw89_write32_mask(rtwdev,
213 rtw89_mac_reg_by_idx(R_AX_RX_FLTR_OPT, RTW89_MAC_0),
214 B_AX_RX_FLTR_CFG_MASK,
215 rtwdev->hal.rx_fltr);
216 if (!rtwdev->dbcc_en)
218 rtw89_write32_mask(rtwdev,
219 rtw89_mac_reg_by_idx(R_AX_RX_FLTR_OPT, RTW89_MAC_1),
220 B_AX_RX_FLTR_CFG_MASK,
221 rtwdev->hal.rx_fltr);
224 mutex_unlock(&rtwdev->mutex);
227 static const u8 ac_to_fw_idx[IEEE80211_NUM_ACS] = {
228 [IEEE80211_AC_VO] = 3,
229 [IEEE80211_AC_VI] = 2,
230 [IEEE80211_AC_BE] = 0,
231 [IEEE80211_AC_BK] = 1,
234 static u8 rtw89_aifsn_to_aifs(struct rtw89_dev *rtwdev,
235 struct rtw89_vif *rtwvif, u8 aifsn)
237 struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif);
241 slot_time = vif->bss_conf.use_short_slot ? 9 : 20;
242 sifs = rtwdev->hal.current_band_type == RTW89_BAND_5G ? 16 : 10;
244 return aifsn * slot_time + sifs;
247 static void ____rtw89_conf_tx_edca(struct rtw89_dev *rtwdev,
248 struct rtw89_vif *rtwvif, u16 ac)
250 struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
255 /* 2^ecw - 1 = cw; ecw = log2(cw + 1) */
256 ecw_max = ilog2(params->cw_max + 1);
257 ecw_min = ilog2(params->cw_min + 1);
258 aifs = rtw89_aifsn_to_aifs(rtwdev, rtwvif, params->aifs);
259 val = FIELD_PREP(FW_EDCA_PARAM_TXOPLMT_MSK, params->txop) |
260 FIELD_PREP(FW_EDCA_PARAM_CWMAX_MSK, ecw_max) |
261 FIELD_PREP(FW_EDCA_PARAM_CWMIN_MSK, ecw_min) |
262 FIELD_PREP(FW_EDCA_PARAM_AIFS_MSK, aifs);
263 rtw89_fw_h2c_set_edca(rtwdev, rtwvif, ac_to_fw_idx[ac], val);
266 static const u32 ac_to_mu_edca_param[IEEE80211_NUM_ACS] = {
267 [IEEE80211_AC_VO] = R_AX_MUEDCA_VO_PARAM_0,
268 [IEEE80211_AC_VI] = R_AX_MUEDCA_VI_PARAM_0,
269 [IEEE80211_AC_BE] = R_AX_MUEDCA_BE_PARAM_0,
270 [IEEE80211_AC_BK] = R_AX_MUEDCA_BK_PARAM_0,
273 static void ____rtw89_conf_tx_mu_edca(struct rtw89_dev *rtwdev,
274 struct rtw89_vif *rtwvif, u16 ac)
276 struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
277 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca;
283 if (!params->mu_edca)
286 mu_edca = ¶ms->mu_edca_param_rec;
287 aifsn = FIELD_GET(GENMASK(3, 0), mu_edca->aifsn);
288 aifs = aifsn ? rtw89_aifsn_to_aifs(rtwdev, rtwvif, aifsn) : 0;
289 timer_32us = mu_edca->mu_edca_timer << 8;
291 val = FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_TIMER_MASK, timer_32us) |
292 FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_CW_MASK, mu_edca->ecw_min_max) |
293 FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_AIFS_MASK, aifs);
294 reg = rtw89_mac_reg_by_idx(ac_to_mu_edca_param[ac], rtwvif->mac_idx);
295 rtw89_write32(rtwdev, reg, val);
297 rtw89_mac_set_hw_muedca_ctrl(rtwdev, rtwvif, true);
300 static void __rtw89_conf_tx(struct rtw89_dev *rtwdev,
301 struct rtw89_vif *rtwvif, u16 ac)
303 ____rtw89_conf_tx_edca(rtwdev, rtwvif, ac);
304 ____rtw89_conf_tx_mu_edca(rtwdev, rtwvif, ac);
307 static void rtw89_conf_tx(struct rtw89_dev *rtwdev,
308 struct rtw89_vif *rtwvif)
312 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
313 __rtw89_conf_tx(rtwdev, rtwvif, ac);
316 static void rtw89_station_mode_sta_assoc(struct rtw89_dev *rtwdev,
317 struct ieee80211_vif *vif,
318 struct ieee80211_bss_conf *conf)
320 struct ieee80211_sta *sta;
322 if (vif->type != NL80211_IFTYPE_STATION)
325 sta = ieee80211_find_sta(vif, conf->bssid);
327 rtw89_err(rtwdev, "can't find sta to set sta_assoc state\n");
331 rtw89_vif_type_mapping(vif, true);
333 rtw89_core_sta_assoc(rtwdev, vif, sta);
336 static void rtw89_ops_bss_info_changed(struct ieee80211_hw *hw,
337 struct ieee80211_vif *vif,
338 struct ieee80211_bss_conf *conf,
341 struct rtw89_dev *rtwdev = hw->priv;
342 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
344 mutex_lock(&rtwdev->mutex);
345 rtw89_leave_ps_mode(rtwdev);
347 if (changed & BSS_CHANGED_ASSOC) {
349 rtw89_station_mode_sta_assoc(rtwdev, vif, conf);
350 rtw89_phy_set_bss_color(rtwdev, vif);
351 rtw89_chip_cfg_txpwr_ul_tb_offset(rtwdev, vif);
352 rtw89_mac_port_update(rtwdev, rtwvif);
353 rtw89_store_op_chan(rtwdev);
355 /* Abort ongoing scan if cancel_scan isn't issued
356 * when disconnected by peer
358 if (rtwdev->scanning)
359 rtw89_hw_scan_abort(rtwdev, vif);
363 if (changed & BSS_CHANGED_BSSID) {
364 ether_addr_copy(rtwvif->bssid, conf->bssid);
365 rtw89_cam_bssid_changed(rtwdev, rtwvif);
366 rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
369 if (changed & BSS_CHANGED_BEACON)
370 rtw89_fw_h2c_update_beacon(rtwdev, rtwvif);
372 if (changed & BSS_CHANGED_ERP_SLOT)
373 rtw89_conf_tx(rtwdev, rtwvif);
375 if (changed & BSS_CHANGED_HE_BSS_COLOR)
376 rtw89_phy_set_bss_color(rtwdev, vif);
378 if (changed & BSS_CHANGED_MU_GROUPS)
379 rtw89_mac_bf_set_gid_table(rtwdev, vif, conf);
381 mutex_unlock(&rtwdev->mutex);
384 static int rtw89_ops_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
386 struct rtw89_dev *rtwdev = hw->priv;
387 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
389 mutex_lock(&rtwdev->mutex);
390 ether_addr_copy(rtwvif->bssid, vif->bss_conf.bssid);
391 rtw89_cam_bssid_changed(rtwdev, rtwvif);
392 rtw89_mac_port_update(rtwdev, rtwvif);
393 rtw89_fw_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
394 rtw89_fw_h2c_role_maintain(rtwdev, rtwvif, NULL, RTW89_ROLE_TYPE_CHANGE);
395 rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
396 rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
397 rtw89_chip_rfk_channel(rtwdev);
398 mutex_unlock(&rtwdev->mutex);
404 void rtw89_ops_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
406 struct rtw89_dev *rtwdev = hw->priv;
407 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
409 mutex_lock(&rtwdev->mutex);
410 rtw89_fw_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
411 rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
412 mutex_unlock(&rtwdev->mutex);
415 static int rtw89_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
418 struct rtw89_dev *rtwdev = hw->priv;
419 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
420 struct rtw89_vif *rtwvif = rtwsta->rtwvif;
422 ieee80211_queue_work(rtwdev->hw, &rtwvif->update_beacon_work);
427 static int rtw89_ops_conf_tx(struct ieee80211_hw *hw,
428 struct ieee80211_vif *vif, u16 ac,
429 const struct ieee80211_tx_queue_params *params)
431 struct rtw89_dev *rtwdev = hw->priv;
432 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
434 mutex_lock(&rtwdev->mutex);
435 rtw89_leave_ps_mode(rtwdev);
436 rtwvif->tx_params[ac] = *params;
437 __rtw89_conf_tx(rtwdev, rtwvif, ac);
438 mutex_unlock(&rtwdev->mutex);
443 static int __rtw89_ops_sta_state(struct ieee80211_hw *hw,
444 struct ieee80211_vif *vif,
445 struct ieee80211_sta *sta,
446 enum ieee80211_sta_state old_state,
447 enum ieee80211_sta_state new_state)
449 struct rtw89_dev *rtwdev = hw->priv;
451 if (old_state == IEEE80211_STA_NOTEXIST &&
452 new_state == IEEE80211_STA_NONE)
453 return rtw89_core_sta_add(rtwdev, vif, sta);
455 if (old_state == IEEE80211_STA_AUTH &&
456 new_state == IEEE80211_STA_ASSOC) {
457 if (vif->type == NL80211_IFTYPE_STATION)
458 return 0; /* defer to bss_info_changed to have vif info */
459 return rtw89_core_sta_assoc(rtwdev, vif, sta);
462 if (old_state == IEEE80211_STA_ASSOC &&
463 new_state == IEEE80211_STA_AUTH)
464 return rtw89_core_sta_disassoc(rtwdev, vif, sta);
466 if (old_state == IEEE80211_STA_AUTH &&
467 new_state == IEEE80211_STA_NONE)
468 return rtw89_core_sta_disconnect(rtwdev, vif, sta);
470 if (old_state == IEEE80211_STA_NONE &&
471 new_state == IEEE80211_STA_NOTEXIST)
472 return rtw89_core_sta_remove(rtwdev, vif, sta);
477 static int rtw89_ops_sta_state(struct ieee80211_hw *hw,
478 struct ieee80211_vif *vif,
479 struct ieee80211_sta *sta,
480 enum ieee80211_sta_state old_state,
481 enum ieee80211_sta_state new_state)
483 struct rtw89_dev *rtwdev = hw->priv;
486 mutex_lock(&rtwdev->mutex);
487 rtw89_leave_ps_mode(rtwdev);
488 ret = __rtw89_ops_sta_state(hw, vif, sta, old_state, new_state);
489 mutex_unlock(&rtwdev->mutex);
494 static int rtw89_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
495 struct ieee80211_vif *vif,
496 struct ieee80211_sta *sta,
497 struct ieee80211_key_conf *key)
499 struct rtw89_dev *rtwdev = hw->priv;
502 mutex_lock(&rtwdev->mutex);
503 rtw89_leave_ps_mode(rtwdev);
507 rtw89_btc_ntfy_specific_packet(rtwdev, PACKET_EAPOL_END);
508 ret = rtw89_cam_sec_key_add(rtwdev, vif, sta, key);
509 if (ret && ret != -EOPNOTSUPP) {
510 rtw89_err(rtwdev, "failed to add key to sec cam\n");
515 rtw89_hci_flush_queues(rtwdev, BIT(rtwdev->hw->queues) - 1,
517 rtw89_mac_flush_txq(rtwdev, BIT(rtwdev->hw->queues) - 1, false);
518 ret = rtw89_cam_sec_key_del(rtwdev, vif, sta, key, true);
520 rtw89_err(rtwdev, "failed to remove key from sec cam\n");
527 mutex_unlock(&rtwdev->mutex);
532 static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw,
533 struct ieee80211_vif *vif,
534 struct ieee80211_ampdu_params *params)
536 struct rtw89_dev *rtwdev = hw->priv;
537 struct ieee80211_sta *sta = params->sta;
538 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
539 u16 tid = params->tid;
540 struct ieee80211_txq *txq = sta->txq[tid];
541 struct rtw89_txq *rtwtxq = (struct rtw89_txq *)txq->drv_priv;
543 switch (params->action) {
544 case IEEE80211_AMPDU_TX_START:
545 return IEEE80211_AMPDU_TX_START_IMMEDIATE;
546 case IEEE80211_AMPDU_TX_STOP_CONT:
547 case IEEE80211_AMPDU_TX_STOP_FLUSH:
548 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
549 mutex_lock(&rtwdev->mutex);
550 clear_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
551 mutex_unlock(&rtwdev->mutex);
552 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
554 case IEEE80211_AMPDU_TX_OPERATIONAL:
555 mutex_lock(&rtwdev->mutex);
556 set_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
557 rtwsta->ampdu_params[tid].agg_num = params->buf_size;
558 rtwsta->ampdu_params[tid].amsdu = params->amsdu;
559 rtw89_leave_ps_mode(rtwdev);
560 mutex_unlock(&rtwdev->mutex);
562 case IEEE80211_AMPDU_RX_START:
563 mutex_lock(&rtwdev->mutex);
564 rtw89_fw_h2c_ba_cam(rtwdev, rtwsta, true, params);
565 mutex_unlock(&rtwdev->mutex);
567 case IEEE80211_AMPDU_RX_STOP:
568 mutex_lock(&rtwdev->mutex);
569 rtw89_fw_h2c_ba_cam(rtwdev, rtwsta, false, params);
570 mutex_unlock(&rtwdev->mutex);
580 static int rtw89_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
582 struct rtw89_dev *rtwdev = hw->priv;
584 mutex_lock(&rtwdev->mutex);
585 rtw89_leave_ps_mode(rtwdev);
586 if (test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
587 rtw89_mac_update_rts_threshold(rtwdev, RTW89_MAC_0);
588 mutex_unlock(&rtwdev->mutex);
593 static void rtw89_ops_sta_statistics(struct ieee80211_hw *hw,
594 struct ieee80211_vif *vif,
595 struct ieee80211_sta *sta,
596 struct station_info *sinfo)
598 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
600 sinfo->txrate = rtwsta->ra_report.txrate;
601 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
604 static void rtw89_ops_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
605 u32 queues, bool drop)
607 struct rtw89_dev *rtwdev = hw->priv;
609 mutex_lock(&rtwdev->mutex);
610 rtw89_leave_lps(rtwdev);
611 rtw89_hci_flush_queues(rtwdev, queues, drop);
612 rtw89_mac_flush_txq(rtwdev, queues, drop);
613 mutex_unlock(&rtwdev->mutex);
616 struct rtw89_iter_bitrate_mask_data {
617 struct rtw89_dev *rtwdev;
618 struct ieee80211_vif *vif;
619 const struct cfg80211_bitrate_mask *mask;
622 static void rtw89_ra_mask_info_update_iter(void *data, struct ieee80211_sta *sta)
624 struct rtw89_iter_bitrate_mask_data *br_data = data;
625 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
626 struct ieee80211_vif *vif = rtwvif_to_vif(rtwsta->rtwvif);
628 if (vif != br_data->vif)
631 rtwsta->use_cfg_mask = true;
632 rtwsta->mask = *br_data->mask;
633 rtw89_phy_ra_updata_sta(br_data->rtwdev, sta, IEEE80211_RC_SUPP_RATES_CHANGED);
636 static void rtw89_ra_mask_info_update(struct rtw89_dev *rtwdev,
637 struct ieee80211_vif *vif,
638 const struct cfg80211_bitrate_mask *mask)
640 struct rtw89_iter_bitrate_mask_data br_data = { .rtwdev = rtwdev,
644 ieee80211_iterate_stations_atomic(rtwdev->hw, rtw89_ra_mask_info_update_iter,
648 static int rtw89_ops_set_bitrate_mask(struct ieee80211_hw *hw,
649 struct ieee80211_vif *vif,
650 const struct cfg80211_bitrate_mask *mask)
652 struct rtw89_dev *rtwdev = hw->priv;
654 mutex_lock(&rtwdev->mutex);
655 rtw89_phy_rate_pattern_vif(rtwdev, vif, mask);
656 rtw89_ra_mask_info_update(rtwdev, vif, mask);
657 mutex_unlock(&rtwdev->mutex);
663 int rtw89_ops_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
665 struct rtw89_dev *rtwdev = hw->priv;
666 struct rtw89_hal *hal = &rtwdev->hal;
668 if (rx_ant != hw->wiphy->available_antennas_rx)
671 mutex_lock(&rtwdev->mutex);
672 hal->antenna_tx = tx_ant;
673 hal->antenna_rx = rx_ant;
674 mutex_unlock(&rtwdev->mutex);
680 int rtw89_ops_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
682 struct rtw89_dev *rtwdev = hw->priv;
683 struct rtw89_hal *hal = &rtwdev->hal;
685 *tx_ant = hal->antenna_tx;
686 *rx_ant = hal->antenna_rx;
691 static void rtw89_ops_sw_scan_start(struct ieee80211_hw *hw,
692 struct ieee80211_vif *vif,
695 struct rtw89_dev *rtwdev = hw->priv;
696 struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
698 mutex_lock(&rtwdev->mutex);
699 rtw89_core_scan_start(rtwdev, rtwvif, mac_addr, false);
700 mutex_unlock(&rtwdev->mutex);
703 static void rtw89_ops_sw_scan_complete(struct ieee80211_hw *hw,
704 struct ieee80211_vif *vif)
706 struct rtw89_dev *rtwdev = hw->priv;
708 mutex_lock(&rtwdev->mutex);
709 rtw89_core_scan_complete(rtwdev, vif, false);
710 mutex_unlock(&rtwdev->mutex);
713 static void rtw89_ops_reconfig_complete(struct ieee80211_hw *hw,
714 enum ieee80211_reconfig_type reconfig_type)
716 struct rtw89_dev *rtwdev = hw->priv;
718 if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART)
719 rtw89_ser_recfg_done(rtwdev);
722 static int rtw89_ops_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
723 struct ieee80211_scan_request *req)
725 struct rtw89_dev *rtwdev = hw->priv;
728 if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
731 if (rtwdev->scanning)
734 mutex_lock(&rtwdev->mutex);
735 rtw89_hw_scan_start(rtwdev, vif, req);
736 ret = rtw89_hw_scan_offload(rtwdev, vif, true);
738 rtw89_hw_scan_abort(rtwdev, vif);
739 rtw89_err(rtwdev, "HW scan failed with status: %d\n", ret);
741 mutex_unlock(&rtwdev->mutex);
746 static void rtw89_ops_cancel_hw_scan(struct ieee80211_hw *hw,
747 struct ieee80211_vif *vif)
749 struct rtw89_dev *rtwdev = hw->priv;
751 if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
754 if (!rtwdev->scanning)
757 mutex_lock(&rtwdev->mutex);
758 rtw89_hw_scan_abort(rtwdev, vif);
759 mutex_unlock(&rtwdev->mutex);
762 static void rtw89_ops_sta_rc_update(struct ieee80211_hw *hw,
763 struct ieee80211_vif *vif,
764 struct ieee80211_sta *sta, u32 changed)
766 struct rtw89_dev *rtwdev = hw->priv;
768 rtw89_phy_ra_updata_sta(rtwdev, sta, changed);
771 const struct ieee80211_ops rtw89_ops = {
773 .wake_tx_queue = rtw89_ops_wake_tx_queue,
774 .start = rtw89_ops_start,
775 .stop = rtw89_ops_stop,
776 .config = rtw89_ops_config,
777 .add_interface = rtw89_ops_add_interface,
778 .remove_interface = rtw89_ops_remove_interface,
779 .configure_filter = rtw89_ops_configure_filter,
780 .bss_info_changed = rtw89_ops_bss_info_changed,
781 .start_ap = rtw89_ops_start_ap,
782 .stop_ap = rtw89_ops_stop_ap,
783 .set_tim = rtw89_ops_set_tim,
784 .conf_tx = rtw89_ops_conf_tx,
785 .sta_state = rtw89_ops_sta_state,
786 .set_key = rtw89_ops_set_key,
787 .ampdu_action = rtw89_ops_ampdu_action,
788 .set_rts_threshold = rtw89_ops_set_rts_threshold,
789 .sta_statistics = rtw89_ops_sta_statistics,
790 .flush = rtw89_ops_flush,
791 .set_bitrate_mask = rtw89_ops_set_bitrate_mask,
792 .set_antenna = rtw89_ops_set_antenna,
793 .get_antenna = rtw89_ops_get_antenna,
794 .sw_scan_start = rtw89_ops_sw_scan_start,
795 .sw_scan_complete = rtw89_ops_sw_scan_complete,
796 .reconfig_complete = rtw89_ops_reconfig_complete,
797 .hw_scan = rtw89_ops_hw_scan,
798 .cancel_hw_scan = rtw89_ops_cancel_hw_scan,
799 .set_sar_specs = rtw89_ops_set_sar_specs,
800 .sta_rc_update = rtw89_ops_sta_rc_update,
802 EXPORT_SYMBOL(rtw89_ops);