• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef __RTW_BEAMFORMING_H_
16 #define __RTW_BEAMFORMING_H_
17 
18 #ifdef CONFIG_BEAMFORMING
19 
20 #ifdef RTW_BEAMFORMING_VERSION_2
21 #define MAX_NUM_BEAMFORMEE_SU	2
22 #define MAX_NUM_BEAMFORMER_SU	2
23 #define MAX_NUM_BEAMFORMEE_MU	6
24 #define MAX_NUM_BEAMFORMER_MU	1
25 
26 #define MAX_BEAMFORMEE_ENTRY_NUM	(MAX_NUM_BEAMFORMEE_SU + MAX_NUM_BEAMFORMEE_MU)
27 #define MAX_BEAMFORMER_ENTRY_NUM	(MAX_NUM_BEAMFORMER_SU + MAX_NUM_BEAMFORMER_MU)
28 
29 /* <Note> Need to be defined by IC */
30 #define SU_SOUNDING_TIMEOUT	5	/* unit: ms */
31 #define MU_SOUNDING_TIMEOUT	8	/* unit: ms */
32 
33 #define GET_BEAMFORM_INFO(adapter)	(&GET_HAL_DATA(adapter)->beamforming_info)
34 #define GetInitSoundCnt(_SoundPeriod, _MinSoundPeriod)	((_SoundPeriod)/(_MinSoundPeriod))
35 
36 enum BEAMFORMING_CTRL_TYPE {
37 	BEAMFORMING_CTRL_ENTER = 0,
38 	BEAMFORMING_CTRL_LEAVE = 1,
39 	BEAMFORMING_CTRL_START_PERIOD = 2,
40 	BEAMFORMING_CTRL_END_PERIOD = 3,
41 	BEAMFORMING_CTRL_SOUNDING_FAIL = 4,
42 	BEAMFORMING_CTRL_SOUNDING_CLK = 5,
43 	BEAMFORMING_CTRL_SET_GID_TABLE = 6,
44 	BEAMFORMING_CTRL_SET_CSI_REPORT = 7,
45 };
46 
47 enum _BEAMFORMING_STATE {
48 	BEAMFORMING_STATE_IDLE,
49 	BEAMFORMING_STATE_START,
50 	BEAMFORMING_STATE_END,
51 };
52 
53 /*
54  * typedef BEAMFORMING_CAP for phydm
55  */
56 typedef enum beamforming_cap {
57 	BEAMFORMING_CAP_NONE = 0x0,
58 	BEAMFORMER_CAP_HT_EXPLICIT = 0x1,
59 	BEAMFORMEE_CAP_HT_EXPLICIT = 0x2,
60 	BEAMFORMER_CAP_VHT_SU = 0x4,			/* Self has er Cap, because Reg er  & peer ee */
61 	BEAMFORMEE_CAP_VHT_SU = 0x8, 			/* Self has ee Cap, because Reg ee & peer er */
62 	BEAMFORMER_CAP_VHT_MU = 0x10,			/* Self has er Cap, because Reg er & peer ee */
63 	BEAMFORMEE_CAP_VHT_MU = 0x20,			/* Self has ee Cap, because Reg ee & peer er */
64 	BEAMFORMER_CAP = 0x40,
65 	BEAMFORMEE_CAP = 0x80,
66 } BEAMFORMING_CAP;
67 
68 enum _BEAMFORM_ENTRY_HW_STATE {
69 	BEAMFORM_ENTRY_HW_STATE_NONE,
70 	BEAMFORM_ENTRY_HW_STATE_ADD_INIT,
71 	BEAMFORM_ENTRY_HW_STATE_ADDING,
72 	BEAMFORM_ENTRY_HW_STATE_ADDED,
73 	BEAMFORM_ENTRY_HW_STATE_DELETE_INIT,
74 	BEAMFORM_ENTRY_HW_STATE_DELETING,
75 	BEAMFORM_ENTRY_HW_STATE_MAX
76 };
77 
78 /* The sounding state is recorded by BFer. */
79 enum _SOUNDING_STATE {
80 	SOUNDING_STATE_NONE		= 0,
81 	SOUNDING_STATE_INIT		= 1,
82 	SOUNDING_STATE_SU_START		= 2,
83 	SOUNDING_STATE_SU_SOUNDDOWN	= 3,
84 	SOUNDING_STATE_MU_START		= 4,
85 	SOUNDING_STATE_MU_SOUNDDOWN	= 5,
86 	SOUNDING_STATE_SOUNDING_TIMEOUT	= 6,
87 	SOUNDING_STATE_MAX
88 };
89 
90 struct beamformee_entry {
91 	u8 used;	/* _TRUE/_FALSE */
92 	u8 txbf;
93 	u8 sounding;
94 	/* Used to construct AID field of NDPA packet */
95 	u16 aid;
96 	/* Used to Set Reg42C in IBSS mode */
97 	u16 mac_id;
98 	/* Used to fill Reg42C & Reg714 to compare with P_AID of Tx DESC */
99 	u16 p_aid;
100 	u8 g_id;
101 	/* Used to fill Reg6E4 to fill Mac address of CSI report frame */
102 	u8 mac_addr[ETH_ALEN];
103 	/* Sounding BandWidth */
104 	enum channel_width sound_bw;
105 	u16 sound_period;
106 
107 	enum beamforming_cap cap;
108 	enum _BEAMFORM_ENTRY_HW_STATE state;
109 
110 	/* The BFee need to be sounded when count to zero */
111 	u8 SoundCnt;
112 	u8 bCandidateSoundingPeer;
113 	u8 bSoundingTimeout;
114 	u8 bDeleteSounding;
115 	/* Get the result through throughput and Tx rate from BB API */
116 	u8 bApplySounding;
117 
118 	/* information for sounding judgement */
119 	systime tx_timestamp;
120 	u64 tx_bytes;
121 
122 	u16 LogStatusFailCnt:5;	/* 0~21 */
123 	u16 DefaultCSICnt:5; /* 0~21 */
124 	u8 CSIMatrix[327];
125 	u16 CSIMatrixLen;
126 
127 	u8 NumofSoundingDim;
128 
129 	u8 comp_steering_num_of_bfer;
130 
131 
132 	/* SU-MIMO */
133 	u8 su_reg_index;
134 
135 	/* MU-MIMO */
136 	u8 mu_reg_index;
137 	u8 gid_valid[8];
138 	u8 user_position[16];
139 
140 	/* For 8822B C-cut workaround */
141 	/* If the flag set to _TRUE, do not sound this STA */
142 	u8 bSuspendSUCap;
143 };
144 
145 struct beamformer_entry {
146 	u8 used;
147 	/* p_aid of BFer entry is probably not used */
148 	/* Used to fill Reg42C & Reg714 to compare with p_aid of Tx DESC */
149 	u16 p_aid;
150 	u8 g_id;
151 	u8 mac_addr[ETH_ALEN];
152 
153 	enum beamforming_cap cap;
154 	enum _BEAMFORM_ENTRY_HW_STATE state;
155 
156 	u8 NumofSoundingDim;
157 
158 	/* SU-MIMO */
159 	u8 su_reg_index;
160 
161 	/* MU-MIMO */
162 	u8 gid_valid[8];
163 	u8 user_position[16];
164 	u16 aid;
165 };
166 
167 struct sounding_info {
168 	u8 su_sounding_list[MAX_NUM_BEAMFORMEE_SU];
169 	u8 mu_sounding_list[MAX_NUM_BEAMFORMEE_MU];
170 
171 	enum _SOUNDING_STATE state;
172 	/*
173 	 * su_bfee_curidx is index for beamforming_info.bfee_entry[]
174 	 * range: 0~MAX_BEAMFORMEE_ENTRY_NUM
175 	 */
176 	u8 su_bfee_curidx;
177 	u8 candidate_mu_bfee_cnt;
178 
179 	/* For sounding schedule maintenance */
180 	u16 min_sounding_period;
181 	/* Get from sounding list */
182 	/* Ex: SU STA1, SU STA2, MU STA(1~n) => the value will be 2+1=3 */
183 	u8 sound_remain_cnt_per_period;
184 };
185 
186 struct _RT_CSI_INFO{
187 	u8 Nc;
188 	u8 Nr;
189 	u8 Ng;
190 	u8 CodeBook;
191 	u8 ChnlWidth;
192 	u8 bVHT;
193 };
194 
195 struct beamforming_info {
196 	enum beamforming_cap beamforming_cap;
197 	enum _BEAMFORMING_STATE beamforming_state;
198 	struct beamformee_entry bfee_entry[MAX_BEAMFORMEE_ENTRY_NUM];
199 	struct beamformer_entry bfer_entry[MAX_BEAMFORMER_ENTRY_NUM];
200 	u8 sounding_sequence;
201 	u8 beamformee_su_cnt;
202 	u8 beamformer_su_cnt;
203 	u32 beamformee_su_reg_maping;
204 	u32 beamformer_su_reg_maping;
205 	/* For MU-MINO */
206 	u8 beamformee_mu_cnt;
207 	u8 beamformer_mu_cnt;
208 	u32 beamformee_mu_reg_maping;
209 	u8 first_mu_bfee_index;
210 	u8 mu_bfer_curidx;
211 	u8 cur_csi_rpt_rate;
212 
213 	struct sounding_info sounding_info;
214 	/* schedule regular timer for sounding */
215 	_timer sounding_timer;
216 	/* moniter if soudning too long */
217 	_timer sounding_timeout_timer;
218 
219 	/* For HW configuration */
220 	u8 SetHalBFEnterOnDemandCnt;
221 	u8 SetHalBFLeaveOnDemandCnt;
222 	u8 SetHalSoundownOnDemandCnt;
223 	u8 bSetBFHwConfigInProgess;
224 
225 	/*
226 	 * Target CSI report info.
227 	 * Keep the first SU CSI report info for 8822B HW bug workaround.
228 	 */
229 	u8 bEnableSUTxBFWorkAround;
230 	struct _RT_CSI_INFO TargetCSIInfo;
231 	/* Only peform sounding to the first SU BFee */
232 	struct beamformee_entry *TargetSUBFee;
233 
234 	/* For debug */
235 	s8 sounding_running;
236 };
237 
238 enum beamforming_cap rtw_bf_bfee_get_entry_cap_by_macid(void *mlmepriv, u8 mac_id);
239 struct beamformer_entry *rtw_bf_bfer_get_entry_by_addr(PADAPTER, u8 *ra);
240 struct beamformee_entry *rtw_bf_bfee_get_entry_by_addr(PADAPTER, u8 *ra);
241 void rtw_bf_get_ndpa_packet(PADAPTER, union recv_frame *);
242 u32 rtw_bf_get_report_packet(PADAPTER, union recv_frame *);
243 u8 rtw_bf_send_vht_gid_mgnt_packet(PADAPTER, u8 *ra, u8 *gid, u8 *position);
244 void rtw_bf_get_vht_gid_mgnt_packet(PADAPTER, union recv_frame *);
245 void rtw_bf_init(PADAPTER);
246 void rtw_bf_cmd_hdl(PADAPTER, u8 type, u8 *pbuf);
247 u8 rtw_bf_cmd(PADAPTER, s32 type, u8 *pbuf, s32 size, u8 enqueue);
248 void rtw_bf_update_attrib(PADAPTER, struct pkt_attrib *, struct sta_info *);
249 void rtw_bf_c2h_handler(PADAPTER, u8 id, u8 *buf, u8 buf_len);
250 void rtw_bf_update_traffic(PADAPTER);
251 
252 /* Compatible with old function name, only for using outside rtw_beamforming.c */
253 #define beamforming_get_entry_beam_cap_by_mac_id	rtw_bf_bfee_get_entry_cap_by_macid
254 #define rtw_beamforming_get_ndpa_frame			rtw_bf_get_ndpa_packet
255 #define rtw_beamforming_get_report_frame			rtw_bf_get_report_packet
256 #define rtw_beamforming_get_vht_gid_mgnt_frame		rtw_bf_get_vht_gid_mgnt_packet
257 #define beamforming_wk_hdl				rtw_bf_cmd_hdl
258 #define beamforming_wk_cmd				rtw_bf_cmd
259 #define update_attrib_txbf_info				rtw_bf_update_attrib
260 
261 #define HT_BF_CAP(adapter) ((adapter)->mlmepriv.htpriv.beamform_cap)
262 #define VHT_BF_CAP(adapter) ((adapter)->mlmepriv.vhtpriv.beamform_cap)
263 
264 #define IS_HT_BEAMFORMEE(adapter) \
265 		(HT_BF_CAP(adapter) & \
266 		(BEAMFORMING_HT_BEAMFORMEE_ENABLE))
267 
268 #define IS_VHT_BEAMFORMEE(adapter) \
269 		(VHT_BF_CAP(adapter) & \
270 		(BEAMFORMING_VHT_BEAMFORMEE_ENABLE | \
271 		 BEAMFORMING_VHT_MU_MIMO_STA_ENABLE))
272 
273 #define IS_BEAMFORMEE(adapter) (IS_HT_BEAMFORMEE(adapter) | \
274 				IS_VHT_BEAMFORMEE(adapter))
275 
276 #else /* !RTW_BEAMFORMING_VERSION_2 */
277 /*PHYDM_BF - (BEAMFORMING_SUPPORT == 1)*/
278 enum BEAMFORMING_CTRL_TYPE {
279 	BEAMFORMING_CTRL_ENTER = 0,
280 	BEAMFORMING_CTRL_LEAVE = 1,
281 	BEAMFORMING_CTRL_START_PERIOD = 2,
282 	BEAMFORMING_CTRL_END_PERIOD = 3,
283 	BEAMFORMING_CTRL_SOUNDING_FAIL = 4,
284 	BEAMFORMING_CTRL_SOUNDING_CLK = 5,
285 };
286 u32	rtw_beamforming_get_report_frame(PADAPTER	 Adapter, union recv_frame *precv_frame);
287 void	rtw_beamforming_get_ndpa_frame(PADAPTER	 Adapter, union recv_frame *precv_frame);
288 
289 void	beamforming_wk_hdl(_adapter *padapter, u8 type, u8 *pbuf);
290 u8	beamforming_wk_cmd(_adapter *padapter, s32 type, u8 *pbuf, s32 size, u8 enqueue);
291 void update_attrib_txbf_info(_adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta);
292 
293 #endif /* !RTW_BEAMFORMING_VERSION_2 */
294 
295 #endif /*#ifdef CONFIG_BEAMFORMING */
296 
297 #endif /*__RTW_BEAMFORMING_H_*/
298