1967439c7SZong-Zhe Yang /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2967439c7SZong-Zhe Yang  * Copyright(c) 2020-2022  Realtek Corporation
3967439c7SZong-Zhe Yang  */
4967439c7SZong-Zhe Yang 
5967439c7SZong-Zhe Yang #ifndef __RTW89_CHAN_H__
6967439c7SZong-Zhe Yang #define __RTW89_CHAN_H__
7967439c7SZong-Zhe Yang 
8967439c7SZong-Zhe Yang #include "core.h"
9967439c7SZong-Zhe Yang 
10*4843aa37SZong-Zhe Yang /* The dwell time in TU before doing rtw89_chanctx_work(). */
11*4843aa37SZong-Zhe Yang #define RTW89_CHANCTX_TIME_MCC_PREPARE 100
12*4843aa37SZong-Zhe Yang 
rtw89_get_entity_state(struct rtw89_dev * rtwdev)13967439c7SZong-Zhe Yang static inline bool rtw89_get_entity_state(struct rtw89_dev *rtwdev)
14967439c7SZong-Zhe Yang {
15967439c7SZong-Zhe Yang 	struct rtw89_hal *hal = &rtwdev->hal;
16967439c7SZong-Zhe Yang 
17967439c7SZong-Zhe Yang 	return READ_ONCE(hal->entity_active);
18967439c7SZong-Zhe Yang }
19967439c7SZong-Zhe Yang 
rtw89_set_entity_state(struct rtw89_dev * rtwdev,bool active)20967439c7SZong-Zhe Yang static inline void rtw89_set_entity_state(struct rtw89_dev *rtwdev, bool active)
21967439c7SZong-Zhe Yang {
22967439c7SZong-Zhe Yang 	struct rtw89_hal *hal = &rtwdev->hal;
23967439c7SZong-Zhe Yang 
24967439c7SZong-Zhe Yang 	WRITE_ONCE(hal->entity_active, active);
25967439c7SZong-Zhe Yang }
26967439c7SZong-Zhe Yang 
277cf674ffSZong-Zhe Yang static inline
rtw89_get_entity_mode(struct rtw89_dev * rtwdev)287cf674ffSZong-Zhe Yang enum rtw89_entity_mode rtw89_get_entity_mode(struct rtw89_dev *rtwdev)
297cf674ffSZong-Zhe Yang {
307cf674ffSZong-Zhe Yang 	struct rtw89_hal *hal = &rtwdev->hal;
317cf674ffSZong-Zhe Yang 
327cf674ffSZong-Zhe Yang 	return READ_ONCE(hal->entity_mode);
337cf674ffSZong-Zhe Yang }
347cf674ffSZong-Zhe Yang 
rtw89_set_entity_mode(struct rtw89_dev * rtwdev,enum rtw89_entity_mode mode)357cf674ffSZong-Zhe Yang static inline void rtw89_set_entity_mode(struct rtw89_dev *rtwdev,
367cf674ffSZong-Zhe Yang 					 enum rtw89_entity_mode mode)
377cf674ffSZong-Zhe Yang {
387cf674ffSZong-Zhe Yang 	struct rtw89_hal *hal = &rtwdev->hal;
397cf674ffSZong-Zhe Yang 
407cf674ffSZong-Zhe Yang 	WRITE_ONCE(hal->entity_mode, mode);
417cf674ffSZong-Zhe Yang }
427cf674ffSZong-Zhe Yang 
43bb8152b3SZong-Zhe Yang void rtw89_chan_create(struct rtw89_chan *chan, u8 center_chan, u8 primary_chan,
44bb8152b3SZong-Zhe Yang 		       enum rtw89_band band, enum rtw89_bandwidth bandwidth);
45cbb145b9SZong-Zhe Yang bool rtw89_assign_entity_chan(struct rtw89_dev *rtwdev,
46cbb145b9SZong-Zhe Yang 			      enum rtw89_sub_entity_idx idx,
47cbb145b9SZong-Zhe Yang 			      const struct rtw89_chan *new);
48494399b2SZong-Zhe Yang void rtw89_config_entity_chandef(struct rtw89_dev *rtwdev,
49494399b2SZong-Zhe Yang 				 enum rtw89_sub_entity_idx idx,
50494399b2SZong-Zhe Yang 				 const struct cfg80211_chan_def *chandef);
51a0e97ae3SPo-Hao Huang void rtw89_config_roc_chandef(struct rtw89_dev *rtwdev,
52a0e97ae3SPo-Hao Huang 			      enum rtw89_sub_entity_idx idx,
53a0e97ae3SPo-Hao Huang 			      const struct cfg80211_chan_def *chandef);
54a88b6cc4SZong-Zhe Yang void rtw89_entity_init(struct rtw89_dev *rtwdev);
557cf674ffSZong-Zhe Yang enum rtw89_entity_mode rtw89_entity_recalc(struct rtw89_dev *rtwdev);
56*4843aa37SZong-Zhe Yang void rtw89_chanctx_work(struct work_struct *work);
57*4843aa37SZong-Zhe Yang void rtw89_queue_chanctx_work(struct rtw89_dev *rtwdev);
5884b50f41SZong-Zhe Yang int rtw89_chanctx_ops_add(struct rtw89_dev *rtwdev,
5984b50f41SZong-Zhe Yang 			  struct ieee80211_chanctx_conf *ctx);
6084b50f41SZong-Zhe Yang void rtw89_chanctx_ops_remove(struct rtw89_dev *rtwdev,
6184b50f41SZong-Zhe Yang 			      struct ieee80211_chanctx_conf *ctx);
6284b50f41SZong-Zhe Yang void rtw89_chanctx_ops_change(struct rtw89_dev *rtwdev,
6384b50f41SZong-Zhe Yang 			      struct ieee80211_chanctx_conf *ctx,
6484b50f41SZong-Zhe Yang 			      u32 changed);
6584b50f41SZong-Zhe Yang int rtw89_chanctx_ops_assign_vif(struct rtw89_dev *rtwdev,
6684b50f41SZong-Zhe Yang 				 struct rtw89_vif *rtwvif,
6784b50f41SZong-Zhe Yang 				 struct ieee80211_chanctx_conf *ctx);
6884b50f41SZong-Zhe Yang void rtw89_chanctx_ops_unassign_vif(struct rtw89_dev *rtwdev,
6984b50f41SZong-Zhe Yang 				    struct rtw89_vif *rtwvif,
7084b50f41SZong-Zhe Yang 				    struct ieee80211_chanctx_conf *ctx);
71cbb145b9SZong-Zhe Yang 
72967439c7SZong-Zhe Yang #endif
73