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