xref: /linux/drivers/net/wireless/realtek/rtw89/chan.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
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 #define RTW89_MCC_SWITCH_CH_TIME 3
22 
23 #define RTW89_MCC_PROBE_TIMEOUT 100
24 #define RTW89_MCC_PROBE_MAX_TRIES 3
25 
26 #define RTW89_MCC_DETECT_BCN_MAX_TRIES 2
27 
28 #define RTW89_MCC_MIN_GO_DURATION \
29 	(RTW89_MCC_EARLY_TX_BCN_TIME + RTW89_MCC_MIN_RX_BCN_TIME)
30 
31 #define RTW89_MCC_MIN_STA_DURATION \
32 	(RTW89_MCC_EARLY_RX_BCN_TIME + RTW89_MCC_MIN_RX_BCN_TIME)
33 
34 #define RTW89_MCC_MIN_RX_BCN_WITH_SWITCH_CH_TIME \
35 	(RTW89_MCC_MIN_RX_BCN_TIME + RTW89_MCC_SWITCH_CH_TIME)
36 
37 #define RTW89_MCC_DFLT_GROUP 0
38 #define RTW89_MCC_NEXT_GROUP(cur) (((cur) + 1) % 4)
39 
40 #define RTW89_MCC_DFLT_TX_NULL_EARLY 7
41 #define RTW89_MCC_DFLT_COURTESY_SLOT 3
42 
43 #define RTW89_MCC_REQ_COURTESY_TIME 5
44 #define RTW89_MCC_REQ_COURTESY(pattern, role)			\
45 ({								\
46 	const struct rtw89_mcc_pattern *p = pattern;		\
47 	p->tob_ ## role <= RTW89_MCC_REQ_COURTESY_TIME ||	\
48 	p->toa_ ## role <= RTW89_MCC_REQ_COURTESY_TIME;		\
49 })
50 
51 #define NUM_OF_RTW89_MCC_ROLES 2
52 
53 enum rtw89_mr_wtype {
54 	RTW89_MR_WTYPE_NONE,
55 	RTW89_MR_WTYPE_NONMLD,
56 	RTW89_MR_WTYPE_MLD1L1R,
57 	RTW89_MR_WTYPE_MLD2L1R,
58 	RTW89_MR_WTYPE_MLD2L2R,
59 	RTW89_MR_WTYPE_NONMLD_NONMLD,
60 	RTW89_MR_WTYPE_MLD1L1R_NONMLD,
61 	RTW89_MR_WTYPE_MLD2L1R_NONMLD,
62 	RTW89_MR_WTYPE_MLD2L2R_NONMLD,
63 	RTW89_MR_WTYPE_UNKNOWN,
64 };
65 
66 enum rtw89_mr_wmode {
67 	RTW89_MR_WMODE_NONE,
68 	RTW89_MR_WMODE_1CLIENT,
69 	RTW89_MR_WMODE_1AP,
70 	RTW89_MR_WMODE_1AP_1CLIENT,
71 	RTW89_MR_WMODE_2CLIENTS,
72 	RTW89_MR_WMODE_2APS,
73 	RTW89_MR_WMODE_UNKNOWN,
74 };
75 
76 enum rtw89_mr_ctxtype {
77 	RTW89_MR_CTX_NONE,
78 	RTW89_MR_CTX1_2GHZ,
79 	RTW89_MR_CTX1_5GHZ,
80 	RTW89_MR_CTX1_6GHZ,
81 	RTW89_MR_CTX2_2GHZ,
82 	RTW89_MR_CTX2_5GHZ,
83 	RTW89_MR_CTX2_6GHZ,
84 	RTW89_MR_CTX2_2GHZ_5GHZ,
85 	RTW89_MR_CTX2_2GHZ_6GHZ,
86 	RTW89_MR_CTX2_5GHZ_6GHZ,
87 	RTW89_MR_CTX_UNKNOWN,
88 };
89 
90 struct rtw89_mr_chanctx_info {
91 	enum rtw89_mr_wtype wtype;
92 	enum rtw89_mr_wmode wmode;
93 	enum rtw89_mr_ctxtype ctxtype;
94 };
95 
96 enum rtw89_chanctx_pause_reasons {
97 	RTW89_CHANCTX_PAUSE_REASON_HW_SCAN,
98 	RTW89_CHANCTX_PAUSE_REASON_ROC,
99 	RTW89_CHANCTX_PAUSE_REASON_GC_BCN_LOSS,
100 };
101 
102 struct rtw89_chanctx_pause_parm {
103 	const struct rtw89_vif_link *trigger;
104 	enum rtw89_chanctx_pause_reasons rsn;
105 };
106 
107 struct rtw89_chanctx_cb_parm {
108 	int (*cb)(struct rtw89_dev *rtwdev, void *data);
109 	void *data;
110 	const char *caller;
111 };
112 
113 struct rtw89_entity_weight {
114 	unsigned int registered_chanctxs;
115 	unsigned int active_chanctxs;
116 	unsigned int active_roles;
117 };
118 
rtw89_get_entity_state(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx)119 static inline bool rtw89_get_entity_state(struct rtw89_dev *rtwdev,
120 					  enum rtw89_phy_idx phy_idx)
121 {
122 	struct rtw89_hal *hal = &rtwdev->hal;
123 
124 	return READ_ONCE(hal->entity_active[phy_idx]);
125 }
126 
rtw89_set_entity_state(struct rtw89_dev * rtwdev,enum rtw89_phy_idx phy_idx,bool active)127 static inline void rtw89_set_entity_state(struct rtw89_dev *rtwdev,
128 					  enum rtw89_phy_idx phy_idx,
129 					  bool active)
130 {
131 	struct rtw89_hal *hal = &rtwdev->hal;
132 
133 	WRITE_ONCE(hal->entity_active[phy_idx], active);
134 }
135 
136 static inline
rtw89_get_entity_mode(struct rtw89_dev * rtwdev)137 enum rtw89_entity_mode rtw89_get_entity_mode(struct rtw89_dev *rtwdev)
138 {
139 	struct rtw89_hal *hal = &rtwdev->hal;
140 
141 	return READ_ONCE(hal->entity_mode);
142 }
143 
rtw89_set_entity_mode(struct rtw89_dev * rtwdev,enum rtw89_entity_mode mode)144 static inline void rtw89_set_entity_mode(struct rtw89_dev *rtwdev,
145 					 enum rtw89_entity_mode mode)
146 {
147 	struct rtw89_hal *hal = &rtwdev->hal;
148 
149 	WRITE_ONCE(hal->entity_mode, mode);
150 }
151 
152 void rtw89_chan_create(struct rtw89_chan *chan, u8 center_chan, u8 primary_chan,
153 		       enum rtw89_band band, enum rtw89_bandwidth bandwidth);
154 bool rtw89_assign_entity_chan(struct rtw89_dev *rtwdev,
155 			      enum rtw89_chanctx_idx idx,
156 			      const struct rtw89_chan *new);
157 int rtw89_iterate_entity_chan(struct rtw89_dev *rtwdev,
158 			      int (*iterator)(const struct rtw89_chan *chan,
159 					      void *data),
160 			      void *data);
161 void rtw89_config_entity_chandef(struct rtw89_dev *rtwdev,
162 				 enum rtw89_chanctx_idx idx,
163 				 const struct cfg80211_chan_def *chandef);
164 void rtw89_config_roc_chandef(struct rtw89_dev *rtwdev,
165 			      struct rtw89_vif_link *rtwvif_link,
166 			      const struct cfg80211_chan_def *chandef);
167 void rtw89_entity_init(struct rtw89_dev *rtwdev);
168 enum rtw89_entity_mode rtw89_entity_recalc(struct rtw89_dev *rtwdev);
169 void rtw89_chanctx_work(struct wiphy *wiphy, struct wiphy_work *work);
170 void rtw89_queue_chanctx_work(struct rtw89_dev *rtwdev);
171 void rtw89_queue_chanctx_change(struct rtw89_dev *rtwdev,
172 				enum rtw89_chanctx_changes change);
173 void rtw89_query_mr_chanctx_info(struct rtw89_dev *rtwdev, u8 inst_idx,
174 				 struct rtw89_mr_chanctx_info *info);
175 void rtw89_chanctx_track(struct rtw89_dev *rtwdev);
176 void rtw89_chanctx_pause(struct rtw89_dev *rtwdev,
177 			 const struct rtw89_chanctx_pause_parm *parm);
178 void rtw89_chanctx_proceed(struct rtw89_dev *rtwdev,
179 			   const struct rtw89_chanctx_cb_parm *cb_parm);
180 
181 const struct rtw89_chan *__rtw89_mgnt_chan_get(struct rtw89_dev *rtwdev,
182 					       const char *caller_message,
183 					       u8 link_index);
184 
185 #define rtw89_mgnt_chan_get(rtwdev, link_index) \
186 	__rtw89_mgnt_chan_get(rtwdev, __func__, link_index)
187 
188 struct rtw89_mcc_links_info {
189 	struct rtw89_vif_link *links[NUM_OF_RTW89_MCC_ROLES];
190 };
191 
192 void rtw89_mcc_get_links(struct rtw89_dev *rtwdev, struct rtw89_mcc_links_info *info);
193 void rtw89_mcc_prepare_done_work(struct wiphy *wiphy, struct wiphy_work *work);
194 void rtw89_mcc_gc_detect_beacon_work(struct wiphy *wiphy, struct wiphy_work *work);
195 bool rtw89_mcc_detect_go_bcn(struct rtw89_dev *rtwdev,
196 			     struct rtw89_vif_link *rtwvif_link);
197 
198 int rtw89_chanctx_ops_add(struct rtw89_dev *rtwdev,
199 			  struct ieee80211_chanctx_conf *ctx);
200 void rtw89_chanctx_ops_remove(struct rtw89_dev *rtwdev,
201 			      struct ieee80211_chanctx_conf *ctx);
202 void rtw89_chanctx_ops_change(struct rtw89_dev *rtwdev,
203 			      struct ieee80211_chanctx_conf *ctx,
204 			      u32 changed);
205 int rtw89_chanctx_ops_assign_vif(struct rtw89_dev *rtwdev,
206 				 struct rtw89_vif_link *rtwvif_link,
207 				 struct ieee80211_chanctx_conf *ctx);
208 void rtw89_chanctx_ops_unassign_vif(struct rtw89_dev *rtwdev,
209 				    struct rtw89_vif_link *rtwvif_link,
210 				    struct ieee80211_chanctx_conf *ctx);
211 int rtw89_chanctx_ops_reassign_vif(struct rtw89_dev *rtwdev,
212 				   struct rtw89_vif_link *rtwvif_link,
213 				   struct ieee80211_chanctx_conf *old_ctx,
214 				   struct ieee80211_chanctx_conf *new_ctx,
215 				   bool replace);
216 
217 #endif
218