• 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_VHT_H_
16 #define _RTW_VHT_H_
17 
18 #define VHT_CAP_IE_LEN 12
19 #define VHT_OP_IE_LEN 5
20 
21 #define	LDPC_VHT_ENABLE_RX			BIT0
22 #define	LDPC_VHT_ENABLE_TX			BIT1
23 #define	LDPC_VHT_TEST_TX_ENABLE		BIT2
24 #define	LDPC_VHT_CAP_TX				BIT3
25 
26 #define	STBC_VHT_ENABLE_RX			BIT0
27 #define	STBC_VHT_ENABLE_TX			BIT1
28 #define	STBC_VHT_TEST_TX_ENABLE		BIT2
29 #define	STBC_VHT_CAP_TX				BIT3
30 
31 #define	BEAMFORMING_VHT_BEAMFORMER_ENABLE	BIT(0)	/*Declare sta support beamformer*/
32 #define	BEAMFORMING_VHT_BEAMFORMEE_ENABLE		BIT(1)	/*Declare sta support beamformee*/
33 #define	BEAMFORMING_VHT_MU_MIMO_AP_ENABLE	BIT(2)	/*Declare sta support MU beamformer*/
34 #define	BEAMFORMING_VHT_MU_MIMO_STA_ENABLE	BIT(3)	/*Declare sta support MU beamformer*/
35 #define	BEAMFORMING_VHT_BEAMFORMER_TEST		BIT(4)	/*Transmiting Beamforming no matter the target supports it or not*/
36 #define	BEAMFORMING_VHT_BEAMFORMER_STS_CAP	(BIT(8)|BIT(9)|BIT(10)) /*Sta BFee's capability*/
37 #define	BEAMFORMING_VHT_BEAMFORMEE_SOUND_DIM (BIT(12)|BIT(13)|BIT(14))	/*Sta Bfer's capability*/
38 
39 /* VHT capability info */
40 #define SET_VHT_CAPABILITY_ELE_MAX_MPDU_LENGTH(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart, 0, 2, _val)
41 #define SET_VHT_CAPABILITY_ELE_CHL_WIDTH(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart, 2, 2, _val)
42 #define SET_VHT_CAPABILITY_ELE_RX_LDPC(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart, 4, 1, _val)
43 #define SET_VHT_CAPABILITY_ELE_SHORT_GI80M(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE(_pEleStart, 5, 1, _val)
44 #define SET_VHT_CAPABILITY_ELE_SHORT_GI160M(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE(_pEleStart, 6, 1, _val)
45 #define SET_VHT_CAPABILITY_ELE_TX_STBC(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE(_pEleStart, 7, 1, _val)
46 #define SET_VHT_CAPABILITY_ELE_RX_STBC(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 0, 3, _val)
47 #define SET_VHT_CAPABILITY_ELE_SU_BFER(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 3, 1, _val)
48 #define SET_VHT_CAPABILITY_ELE_SU_BFEE(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 4, 1, _val)
49 /* #define SET_VHT_CAPABILITY_ELE_BFER_ANT_SUPP(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 5, 3, _val) */
50 #define SET_VHT_CAPABILITY_ELE_SU_BFEE_STS_CAP(_pEleStart, _val)		SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 5, 3, _val)
51 #define SET_VHT_CAPABILITY_ELE_SOUNDING_DIMENSIONS(_pEleStart, _val)	SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 0, 3, _val) /* B16~B18 */
52 
53 #define SET_VHT_CAPABILITY_ELE_MU_BFER(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 3, 1, _val)
54 #define SET_VHT_CAPABILITY_ELE_MU_BFEE(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 4, 1, _val)
55 #define SET_VHT_CAPABILITY_ELE_TXOP_PS(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 5, 1, _val)
56 #define SET_VHT_CAPABILITY_ELE_HTC_VHT(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 6, 1, _val)
57 #define SET_VHT_CAPABILITY_ELE_MAX_RXAMPDU_FACTOR(_pEleStart, _val)		SET_BITS_TO_LE_2BYTE((_pEleStart)+2, 7, 3, _val) /* B23~B25 */
58 #define SET_VHT_CAPABILITY_ELE_LINK_ADAPTION(_pEleStart, _val)				SET_BITS_TO_LE_1BYTE((_pEleStart)+3, 2, 2, _val)
59 #define SET_VHT_CAPABILITY_ELE_MCS_RX_MAP(_pEleStart, _val)				SET_BITS_TO_LE_2BYTE((_pEleStart)+4, 0, 16, _val)   /* B0~B15 indicate Rx MCS MAP, we write 0 to indicate MCS0~7. by page */
60 #define SET_VHT_CAPABILITY_ELE_MCS_RX_HIGHEST_RATE(_pEleStart, _val)				SET_BITS_TO_LE_2BYTE((_pEleStart)+6, 0, 13, _val)
61 #define SET_VHT_CAPABILITY_ELE_MCS_TX_MAP(_pEleStart, _val)				SET_BITS_TO_LE_2BYTE((_pEleStart)+8, 0, 16, _val)   /* B0~B15 indicate Tx MCS MAP, we write 0 to indicate MCS0~7. by page */
62 #define SET_VHT_CAPABILITY_ELE_MCS_TX_HIGHEST_RATE(_pEleStart, _val)				SET_BITS_TO_LE_2BYTE((_pEleStart)+10, 0, 13, _val)
63 #define SET_VHT_CAPABILITY_ELE_RX_ANT_PATTERN(_pEleStart, _val)		SET_BITS_TO_LE_1BYTE((_pEleStart)+3, 4, 1, _val)
64 #define SET_VHT_CAPABILITY_ELE_TX_ANT_PATTERN(_pEleStart, _val)		SET_BITS_TO_LE_1BYTE((_pEleStart)+3, 5, 1, _val)
65 #define SET_VHT_CAPABILITY_ELE_EXT_NSS_BW(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE((_pEleStart)+3, 6, 2, _val)
66 
67 #define GET_VHT_CAPABILITY_ELE_MAX_MPDU_LENGTH(_pEleStart)			LE_BITS_TO_1BYTE(_pEleStart, 0, 2)
68 #define GET_VHT_CAPABILITY_ELE_CHL_WIDTH(_pEleStart)				LE_BITS_TO_1BYTE(_pEleStart, 2, 2)
69 #define GET_VHT_CAPABILITY_ELE_RX_LDPC(_pEleStart)			LE_BITS_TO_1BYTE(_pEleStart, 4, 1)
70 #define GET_VHT_CAPABILITY_ELE_SHORT_GI80M(_pEleStart)				LE_BITS_TO_1BYTE(_pEleStart, 5, 1)
71 #define GET_VHT_CAPABILITY_ELE_SHORT_GI160M(_pEleStart)				LE_BITS_TO_1BYTE(_pEleStart, 6, 1)
72 #define GET_VHT_CAPABILITY_ELE_TX_STBC(_pEleStart)				LE_BITS_TO_1BYTE(_pEleStart, 7, 1)
73 #define GET_VHT_CAPABILITY_ELE_RX_STBC(_pEleStart)				LE_BITS_TO_1BYTE((_pEleStart)+1, 0, 3)
74 #define GET_VHT_CAPABILITY_ELE_SU_BFER(_pEleStart)					LE_BITS_TO_1BYTE((_pEleStart)+1, 3, 1)
75 #define GET_VHT_CAPABILITY_ELE_SU_BFEE(_pEleStart)					LE_BITS_TO_1BYTE((_pEleStart)+1, 4, 1)
76 /*phydm-beamforming*/
77 #define GET_VHT_CAPABILITY_ELE_SU_BFEE_STS_CAP(_pEleStart)	LE_BITS_TO_1BYTE((_pEleStart)+1, 5, 3)
78 #define GET_VHT_CAPABILITY_ELE_SU_BFER_SOUND_DIM_NUM(_pEleStart)	LE_BITS_TO_2BYTE((_pEleStart)+2, 0, 3)
79 #define GET_VHT_CAPABILITY_ELE_MU_BFER(_pEleStart)				LE_BITS_TO_1BYTE((_pEleStart)+2, 3, 1)
80 #define GET_VHT_CAPABILITY_ELE_MU_BFEE(_pEleStart)				LE_BITS_TO_1BYTE((_pEleStart)+2, 4, 1)
81 #define GET_VHT_CAPABILITY_ELE_TXOP_PS(_pEleStart)				LE_BITS_TO_1BYTE((_pEleStart)+2, 5, 1)
82 #define GET_VHT_CAPABILITY_ELE_HTC_VHT(_pEleStart)			LE_BITS_TO_1BYTE((_pEleStart)+2, 6, 1)
83 #define GET_VHT_CAPABILITY_ELE_MAX_RXAMPDU_FACTOR(_pEleStart)	LE_BITS_TO_2BYTE((_pEleStart)+2, 7, 3)
84 #define GET_VHT_CAPABILITY_ELE_LINK_ADAPTION(_pEleStart)			LE_BITS_TO_1BYTE((_pEleStart)+3, 2, 2)
85 #define GET_VHT_CAPABILITY_ELE_RX_ANT_PATTERN(_pEleStart)		LE_BITS_TO_1BYTE((_pEleStart)+3, 4, 1)
86 #define GET_VHT_CAPABILITY_ELE_TX_ANT_PATTERN(_pEleStart)		LE_BITS_TO_1BYTE((_pEleStart)+3, 5, 1)
87 #define GET_VHT_CAPABILITY_ELE_EXT_NSS_BW(_pEleStart)			LE_BITS_TO_1BYTE((_pEleStart)+3, 6, 2)
88 #define GET_VHT_CAPABILITY_ELE_RX_MCS(_pEleStart)					((_pEleStart)+4)
89 #define GET_VHT_CAPABILITY_ELE_MCS_RX_HIGHEST_RATE(_pEleStart)	LE_BITS_TO_2BYTE((_pEleStart)+6, 0, 13)
90 #define GET_VHT_CAPABILITY_ELE_TX_MCS(_pEleStart)					((_pEleStart)+8)
91 #define GET_VHT_CAPABILITY_ELE_MCS_TX_HIGHEST_RATE(_pEleStart)	LE_BITS_TO_2BYTE((_pEleStart)+10, 0, 13)
92 
93 
94 /* VHT Operation Information Element */
95 #define SET_VHT_OPERATION_ELE_CHL_WIDTH(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart, 0, 8, _val)
96 #define SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart+1, 0, 8, _val)
97 #define SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart+2, 0, 8, _val)
98 #define SET_VHT_OPERATION_ELE_BASIC_MCS_SET(_pEleStart, _val)			SET_BITS_TO_LE_2BYTE((_pEleStart)+3, 0, 16, _val)
99 
100 #define GET_VHT_OPERATION_ELE_CHL_WIDTH(_pEleStart)		LE_BITS_TO_1BYTE(_pEleStart, 0, 8)
101 #define GET_VHT_OPERATION_ELE_CENTER_FREQ1(_pEleStart)	LE_BITS_TO_1BYTE((_pEleStart)+1, 0, 8)
102 #define GET_VHT_OPERATION_ELE_CENTER_FREQ2(_pEleStart)     LE_BITS_TO_1BYTE((_pEleStart)+2, 0, 8)
103 #define GET_VHT_OPERATION_ELE_BASIC_MCS_SET(_pEleStart)	LE_BITS_TO_2BYTE((_pEleStart)+3, 0, 16)
104 
105 /* VHT Operating Mode */
106 #define SET_VHT_OPERATING_MODE_FIELD_CHNL_WIDTH(_pEleStart, _val)		SET_BITS_TO_LE_1BYTE(_pEleStart, 0, 2, _val)
107 #define SET_VHT_OPERATING_MODE_FIELD_RX_NSS(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE(_pEleStart, 4, 3, _val)
108 #define SET_VHT_OPERATING_MODE_FIELD_RX_NSS_TYPE(_pEleStart, _val)	SET_BITS_TO_LE_1BYTE(_pEleStart, 7, 1, _val)
109 #define GET_VHT_OPERATING_MODE_FIELD_CHNL_WIDTH(_pEleStart)			LE_BITS_TO_1BYTE(_pEleStart, 0, 2)
110 #define GET_VHT_OPERATING_MODE_FIELD_RX_NSS(_pEleStart)				LE_BITS_TO_1BYTE(_pEleStart, 4, 3)
111 #define GET_VHT_OPERATING_MODE_FIELD_RX_NSS_TYPE(_pEleStart)		LE_BITS_TO_1BYTE(_pEleStart, 7, 1)
112 
113 #define SET_EXT_CAPABILITY_ELE_OP_MODE_NOTIF(_pEleStart, _val)			SET_BITS_TO_LE_1BYTE((_pEleStart)+7, 6, 1, _val)
114 #define GET_EXT_CAPABILITY_ELE_OP_MODE_NOTIF(_pEleStart)				LE_BITS_TO_1BYTE((_pEleStart)+7, 6, 1)
115 
116 #define VHT_MAX_MPDU_LEN_MAX 3
117 extern const u16 _vht_max_mpdu_len[];
118 #define vht_max_mpdu_len(val) (((val) >= VHT_MAX_MPDU_LEN_MAX) ? _vht_max_mpdu_len[VHT_MAX_MPDU_LEN_MAX] : _vht_max_mpdu_len[(val)])
119 
120 #define VHT_SUP_CH_WIDTH_SET_MAX 3
121 extern const u8 _vht_sup_ch_width_set_to_bw_cap[];
122 #define vht_sup_ch_width_set_to_bw_cap(set) (((set) >= VHT_SUP_CH_WIDTH_SET_MAX) ? _vht_sup_ch_width_set_to_bw_cap[VHT_SUP_CH_WIDTH_SET_MAX] : _vht_sup_ch_width_set_to_bw_cap[(set)])
123 #define VHT_MAX_AMPDU_LEN(f) ((1 << (13 + f)) - 1)
124 
125 #ifdef CONFIG_RTW_DEBUG
126 extern const char *const _vht_sup_ch_width_set_str[];
127 #define vht_sup_ch_width_set_str(set) (((set) >= VHT_SUP_CH_WIDTH_SET_MAX) ? _vht_sup_ch_width_set_str[VHT_SUP_CH_WIDTH_SET_MAX] : _vht_sup_ch_width_set_str[(set)])
128 
129 void dump_vht_cap_ie(void *sel, const u8 *ie, u32 ie_len);
130 
131 #define VHT_OP_CH_WIDTH_MAX 4
132 extern const char *const _vht_op_ch_width_str[];
133 #define vht_op_ch_width_str(ch_width) (((ch_width) >= VHT_OP_CH_WIDTH_MAX) ? _vht_op_ch_width_str[VHT_OP_CH_WIDTH_MAX] : _vht_op_ch_width_str[(ch_width)])
134 
135 void dump_vht_op_ie(void *sel, const u8 *ie, u32 ie_len);
136 #endif
137 
138 struct vht_bf_cap {
139 	u8 is_mu_bfer;
140 	u8 su_sound_dim;
141 };
142 
143 struct vht_priv {
144 	/* VHT IE is configured by upper layer or not (hostapd or wpa_supplicant) */
145 	u8 upper_layer_setting;
146 
147 	u8 vht_option;
148 
149 	u8	ldpc_cap;
150 	u8	stbc_cap;
151 	u8 rx_stbc_nss; /* Support nss spatial stream */
152 	u16 beamform_cap;
153 	u8 ap_is_mu_bfer;
154 	struct	vht_bf_cap ap_bf_cap;
155 	u8 sgi_80m;
156 	u8 sgi_160m;
157 
158 	u8 ampdu_len; /* A-MPDU length exponent : 0 to 7 */
159 
160 	u8 vht_highest_rate;
161 	u8 vht_mcs_map[2];
162 
163 	u8 txop_ps; /* TXOP power save mode*/
164 	u8 htc_vht; /* VHT variant HT Control*/
165 	u8 link_adap_cap; /* VHT Link Adaptation Capable */
166 	u8 tx_ant_pattern; /* Tx Antenna Pattern Consistency */
167 	u8 rx_ant_pattern; /* Rx Antenna Pattern Consistency */
168 	u8 ext_nss_bw; /* Extended NSS BW Support */
169 
170 	u8 op_present:1; /* vht_op is present */
171 	u8 notify_present:1; /* vht_op_mode_notify is present */
172 
173 	u8 vht_cap[32];
174 	u8 vht_op[VHT_OP_IE_LEN];
175 	u8 vht_op_mode_notify;
176 
177 	/* Backup these two VHT IEs from hostapd/wpa_supplicant for restore usage */
178 	u8 vht_cap_ie_backup[VHT_CAP_IE_LEN];
179 	u8 vht_op_ie_backup[VHT_OP_IE_LEN];
180 };
181 
182 #ifdef ROKU_PRIVATE
183 struct vht_priv_infra_ap {
184 
185 	/* Infra mode, only store for AP's info, not intersection of STA and AP*/
186 	u8	ldpc_cap_infra_ap;
187 	u8	stbc_cap_infra_ap;
188 	u16	beamform_cap_infra_ap;
189 	u8	vht_mcs_map_infra_ap[2];
190 	u8	vht_mcs_map_tx_infra_ap[2];
191 	u8	channel_width_infra_ap;
192 	u8	number_of_streams_infra_ap;
193 };
194 #endif /* ROKU_PRIVATE */
195 
196 u8	rtw_get_vht_highest_rate(u8 *pvht_mcs_map);
197 u16	rtw_vht_mcs_to_data_rate(u8 bw, u8 short_GI, u8 vht_mcs_rate);
198 u64	rtw_vht_mcs_map_to_bitmap(u8 *mcs_map, u8 nss);
199 void	rtw_vht_use_default_setting(_adapter *padapter);
200 u32	rtw_build_vht_operation_ie(_adapter *padapter, u8 *pbuf, u8 channel);
201 u32	rtw_build_vht_op_mode_notify_ie(_adapter *padapter, u8 *pbuf, u8 bw);
202 u32	rtw_build_vht_cap_ie(_adapter *padapter, u8 *pbuf);
203 void	update_sta_vht_info_apmode(_adapter *padapter, void *psta);
204 void	update_hw_vht_param(_adapter *padapter);
205 void	VHT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
206 #ifdef ROKU_PRIVATE
207 void	VHT_caps_handler_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
208 #endif /* ROKU_PRIVATE */
209 void	VHT_operation_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
210 void	rtw_process_vht_op_mode_notify(_adapter *padapter, u8 *pframe, void *sta);
211 u32	rtw_restructure_vht_ie(_adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, struct country_chplan *req_chplan);
212 void	VHTOnAssocRsp(_adapter *padapter);
213 u8	rtw_vht_mcsmap_to_nss(u8 *pvht_mcs_map);
214 void rtw_vht_nss_to_mcsmap(u8 nss, u8 *target_mcs_map, u8 *cur_mcs_map);
215 void rtw_vht_ies_attach(_adapter *padapter, WLAN_BSSID_EX *pcur_network);
216 void rtw_vht_ies_detach(_adapter *padapter, WLAN_BSSID_EX *pcur_network);
217 void rtw_check_for_vht20(_adapter *adapter, u8 *ies, int ies_len);
218 #ifdef CONFIG_AP_MODE
219 void rtw_update_drv_vht_cap(_adapter *padapter, u8 *vht_cap_ie);
220 void rtw_set_vht_ext_cap(_adapter *padapter, WLAN_BSSID_EX *pnetwork);
221 void rtw_check_vht_ies(_adapter *padapter, WLAN_BSSID_EX *pnetwork);
222 void rtw_reattach_vht_ies(_adapter *padapter, WLAN_BSSID_EX *pnetwork);
223 #endif
224 #endif /* _RTW_VHT_H_ */
225