1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 * Copyright(c) 2020-2022 Realtek Corporation 3 */ 4 5 #ifndef __RTW89_CHAN_H__ 6 #define __RTW89_CHAN_H__ 7 8 #include "core.h" 9 10 /* The dwell time in TU before doing rtw89_chanctx_work(). */ 11 #define RTW89_CHANCTX_TIME_MCC_PREPARE 100 12 #define RTW89_CHANCTX_TIME_MCC 100 13 14 /* various MCC setting time in TU */ 15 #define RTW89_MCC_LONG_TRIGGER_TIME 300 16 #define RTW89_MCC_SHORT_TRIGGER_TIME 100 17 #define RTW89_MCC_EARLY_TX_BCN_TIME 10 18 #define RTW89_MCC_EARLY_RX_BCN_TIME 5 19 #define RTW89_MCC_MIN_RX_BCN_TIME 10 20 #define RTW89_MCC_DFLT_BCN_OFST_TIME 40 21 22 #define RTW89_MCC_MIN_GO_DURATION \ 23 (RTW89_MCC_EARLY_TX_BCN_TIME + RTW89_MCC_MIN_RX_BCN_TIME) 24 25 #define RTW89_MCC_MIN_STA_DURATION \ 26 (RTW89_MCC_EARLY_RX_BCN_TIME + RTW89_MCC_MIN_RX_BCN_TIME) 27 28 #define RTW89_MCC_DFLT_GROUP 0 29 #define RTW89_MCC_NEXT_GROUP(cur) (((cur) + 1) % 4) 30 31 #define RTW89_MCC_DFLT_TX_NULL_EARLY 3 32 #define RTW89_MCC_DFLT_COURTESY_SLOT 3 33 34 #define RTW89_MCC_REQ_COURTESY_TIME 5 35 #define RTW89_MCC_REQ_COURTESY(pattern, role) \ 36 ({ \ 37 const struct rtw89_mcc_pattern *p = pattern; \ 38 p->tob_ ## role <= RTW89_MCC_REQ_COURTESY_TIME || \ 39 p->toa_ ## role <= RTW89_MCC_REQ_COURTESY_TIME; \ 40 }) 41 42 #define NUM_OF_RTW89_MCC_ROLES 2 43 44 enum rtw89_chanctx_pause_reasons { 45 RTW89_CHANCTX_PAUSE_REASON_HW_SCAN, 46 RTW89_CHANCTX_PAUSE_REASON_ROC, 47 }; 48 49 struct rtw89_chanctx_pause_parm { 50 const struct rtw89_vif_link *trigger; 51 enum rtw89_chanctx_pause_reasons rsn; 52 }; 53 54 struct rtw89_chanctx_cb_parm { 55 int (*cb)(struct rtw89_dev *rtwdev, void *data); 56 void *data; 57 const char *caller; 58 }; 59 60 struct rtw89_entity_weight { 61 unsigned int active_chanctxs; 62 unsigned int active_roles; 63 }; 64 65 static inline bool rtw89_get_entity_state(struct rtw89_dev *rtwdev, 66 enum rtw89_phy_idx phy_idx) 67 { 68 struct rtw89_hal *hal = &rtwdev->hal; 69 70 return READ_ONCE(hal->entity_active[phy_idx]); 71 } 72 73 static inline void rtw89_set_entity_state(struct rtw89_dev *rtwdev, 74 enum rtw89_phy_idx phy_idx, 75 bool active) 76 { 77 struct rtw89_hal *hal = &rtwdev->hal; 78 79 WRITE_ONCE(hal->entity_active[phy_idx], active); 80 } 81 82 static inline 83 enum rtw89_entity_mode rtw89_get_entity_mode(struct rtw89_dev *rtwdev) 84 { 85 struct rtw89_hal *hal = &rtwdev->hal; 86 87 return READ_ONCE(hal->entity_mode); 88 } 89 90 static inline void rtw89_set_entity_mode(struct rtw89_dev *rtwdev, 91 enum rtw89_entity_mode mode) 92 { 93 struct rtw89_hal *hal = &rtwdev->hal; 94 95 WRITE_ONCE(hal->entity_mode, mode); 96 } 97 98 void rtw89_chan_create(struct rtw89_chan *chan, u8 center_chan, u8 primary_chan, 99 enum rtw89_band band, enum rtw89_bandwidth bandwidth); 100 bool rtw89_assign_entity_chan(struct rtw89_dev *rtwdev, 101 enum rtw89_chanctx_idx idx, 102 const struct rtw89_chan *new); 103 int rtw89_iterate_entity_chan(struct rtw89_dev *rtwdev, 104 int (*iterator)(const struct rtw89_chan *chan, 105 void *data), 106 void *data); 107 void rtw89_config_entity_chandef(struct rtw89_dev *rtwdev, 108 enum rtw89_chanctx_idx idx, 109 const struct cfg80211_chan_def *chandef); 110 void rtw89_config_roc_chandef(struct rtw89_dev *rtwdev, 111 struct rtw89_vif_link *rtwvif_link, 112 const struct cfg80211_chan_def *chandef); 113 void rtw89_entity_init(struct rtw89_dev *rtwdev); 114 enum rtw89_entity_mode rtw89_entity_recalc(struct rtw89_dev *rtwdev); 115 void rtw89_chanctx_work(struct wiphy *wiphy, struct wiphy_work *work); 116 void rtw89_queue_chanctx_work(struct rtw89_dev *rtwdev); 117 void rtw89_queue_chanctx_change(struct rtw89_dev *rtwdev, 118 enum rtw89_chanctx_changes change); 119 void rtw89_chanctx_track(struct rtw89_dev *rtwdev); 120 void rtw89_chanctx_pause(struct rtw89_dev *rtwdev, 121 const struct rtw89_chanctx_pause_parm *parm); 122 void rtw89_chanctx_proceed(struct rtw89_dev *rtwdev, 123 const struct rtw89_chanctx_cb_parm *cb_parm); 124 125 const struct rtw89_chan *__rtw89_mgnt_chan_get(struct rtw89_dev *rtwdev, 126 const char *caller_message, 127 u8 link_index); 128 129 #define rtw89_mgnt_chan_get(rtwdev, link_index) \ 130 __rtw89_mgnt_chan_get(rtwdev, __func__, link_index) 131 132 int rtw89_chanctx_ops_add(struct rtw89_dev *rtwdev, 133 struct ieee80211_chanctx_conf *ctx); 134 void rtw89_chanctx_ops_remove(struct rtw89_dev *rtwdev, 135 struct ieee80211_chanctx_conf *ctx); 136 void rtw89_chanctx_ops_change(struct rtw89_dev *rtwdev, 137 struct ieee80211_chanctx_conf *ctx, 138 u32 changed); 139 int rtw89_chanctx_ops_assign_vif(struct rtw89_dev *rtwdev, 140 struct rtw89_vif_link *rtwvif_link, 141 struct ieee80211_chanctx_conf *ctx); 142 void rtw89_chanctx_ops_unassign_vif(struct rtw89_dev *rtwdev, 143 struct rtw89_vif_link *rtwvif_link, 144 struct ieee80211_chanctx_conf *ctx); 145 146 #endif 147