8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / include / rtw_vht.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef _RTW_VHT_H_
21 #define _RTW_VHT_H_
22
23 #define LDPC_VHT_ENABLE_RX                      BIT0
24 #define LDPC_VHT_ENABLE_TX                      BIT1
25 #define LDPC_VHT_TEST_TX_ENABLE         BIT2
26 #define LDPC_VHT_CAP_TX                         BIT3
27
28 #define STBC_VHT_ENABLE_RX                      BIT0
29 #define STBC_VHT_ENABLE_TX                      BIT1
30 #define STBC_VHT_TEST_TX_ENABLE         BIT2
31 #define STBC_VHT_CAP_TX                         BIT3
32
33 #define BEAMFORMING_VHT_BEAMFORMER_ENABLE       BIT0    // Declare our NIC supports beamformer
34 #define BEAMFORMING_VHT_BEAMFORMEE_ENABLE       BIT1    // Declare our NIC supports beamformee
35 #define BEAMFORMING_VHT_BEAMFORMER_TEST         BIT2    // Transmiting Beamforming no matter the target supports it or not
36
37 //VHT capability info
38 #define SET_VHT_CAPABILITY_ELE_MAX_MPDU_LENGTH(_pEleStart, _val)                        SET_BITS_TO_LE_1BYTE(_pEleStart, 0, 2, _val)
39 #define SET_VHT_CAPABILITY_ELE_CHL_WIDTH(_pEleStart, _val)                      SET_BITS_TO_LE_1BYTE(_pEleStart, 2, 2, _val)
40 #define SET_VHT_CAPABILITY_ELE_RX_LDPC(_pEleStart, _val)                        SET_BITS_TO_LE_1BYTE(_pEleStart, 4, 1, _val)
41 #define SET_VHT_CAPABILITY_ELE_SHORT_GI80M(_pEleStart, _val)                            SET_BITS_TO_LE_1BYTE(_pEleStart, 5, 1, _val)
42 #define SET_VHT_CAPABILITY_ELE_SHORT_GI160M(_pEleStart, _val)                           SET_BITS_TO_LE_1BYTE(_pEleStart, 6, 1, _val)
43 #define SET_VHT_CAPABILITY_ELE_TX_STBC(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE(_pEleStart, 7, 1, _val)
44 #define SET_VHT_CAPABILITY_ELE_RX_STBC(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 0, 3, _val)
45 #define SET_VHT_CAPABILITY_ELE_SU_BFER(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 3, 1, _val)
46 #define SET_VHT_CAPABILITY_ELE_SU_BFEE(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 4, 1, _val)
47 #define SET_VHT_CAPABILITY_ELE_BFER_ANT_SUPP(_pEleStart, _val)                          SET_BITS_TO_LE_1BYTE((_pEleStart)+1, 5, 3, _val)
48 #define SET_VHT_CAPABILITY_ELE_SOUNDING_DIMENSIONS(_pEleStart, _val)                            SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 0, 3, _val)
49 #define SET_VHT_CAPABILITY_ELE_MU_BFER(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 3, 1, _val)
50 #define SET_VHT_CAPABILITY_ELE_MU_BFEE(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 4, 1, _val)
51 #define SET_VHT_CAPABILITY_ELE_TXOP_PS(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 5, 1, _val)
52 #define SET_VHT_CAPABILITY_ELE_HTC_VHT(_pEleStart, _val)                                SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 6, 1, _val)
53 #define SET_VHT_CAPABILITY_ELE_MAX_RXAMPDU_FACTOR(_pEleStart, _val)             SET_BITS_TO_LE_2BYTE((_pEleStart)+2, 7, 3, _val) //B23~B25
54 #define SET_VHT_CAPABILITY_ELE_LINK_ADAPTION(_pEleStart, _val)                          SET_BITS_TO_LE_1BYTE((_pEleStart)+2, 2, 2, _val)
55 #define SET_VHT_CAPABILITY_ELE_MCS_RX_MAP(_pEleStart, _val)                             SET_BITS_TO_LE_2BYTE_16BIT((_pEleStart)+4, 0, 16, _val)   //B0~B15 indicate Rx MCS MAP, we write 0 to indicate MCS0~7. by page
56 #define SET_VHT_CAPABILITY_ELE_MCS_RX_HIGHEST_RATE(_pEleStart, _val)                            SET_BITS_TO_LE_2BYTE((_pEleStart)+6, 0, 13, _val)  
57 #define SET_VHT_CAPABILITY_ELE_MCS_TX_MAP(_pEleStart, _val)                             SET_BITS_TO_LE_2BYTE_16BIT((_pEleStart)+8, 0, 16, _val)   //B0~B15 indicate Tx MCS MAP, we write 0 to indicate MCS0~7. by page
58 #define SET_VHT_CAPABILITY_ELE_MCS_TX_HIGHEST_RATE(_pEleStart, _val)                            SET_BITS_TO_LE_2BYTE((_pEleStart)+10, 0, 13, _val)  
59
60
61 #define GET_VHT_CAPABILITY_ELE_MAX_MPDU_LENGTH(_pEleStart)                      LE_BITS_TO_1BYTE(_pEleStart, 0, 2)
62 #define GET_VHT_CAPABILITY_ELE_CHL_WIDTH(_pEleStart)                            LE_BITS_TO_1BYTE(_pEleStart, 2, 2)
63 #define GET_VHT_CAPABILITY_ELE_RX_LDPC(_pEleStart)                      LE_BITS_TO_1BYTE(_pEleStart, 4, 1)
64 #define GET_VHT_CAPABILITY_ELE_SHORT_GI80M(_pEleStart)                          LE_BITS_TO_1BYTE(_pEleStart, 5, 1)
65 #define GET_VHT_CAPABILITY_ELE_SHORT_GI160M(_pEleStart)                         LE_BITS_TO_1BYTE(_pEleStart, 6, 1)
66 #define GET_VHT_CAPABILITY_ELE_TX_STBC(_pEleStart)                              LE_BITS_TO_1BYTE(_pEleStart, 7, 1)
67 #define GET_VHT_CAPABILITY_ELE_RX_STBC(_pEleStart)                              LE_BITS_TO_1BYTE((_pEleStart)+1, 0, 3)
68 #define GET_VHT_CAPABILITY_ELE_SU_BFER(_pEleStart)                                      LE_BITS_TO_1BYTE((_pEleStart)+1, 3, 1)
69 #define GET_VHT_CAPABILITY_ELE_SU_BFEE(_pEleStart)                                      LE_BITS_TO_1BYTE((_pEleStart)+1, 4, 1)
70 #define GET_VHT_CAPABILITY_ELE_TXOP_PS(_pEleStart)                              LE_BITS_TO_1BYTE((_pEleStart)+2, 5, 1)
71 #define GET_VHT_CAPABILITY_ELE_MAX_RXAMPDU_FACTOR(_pEleStart)   LE_BITS_TO_2BYTE((_pEleStart)+2, 7, 3)
72 #define GET_VHT_CAPABILITY_ELE_RX_MCS(_pEleStart)                                              ((_pEleStart)+4)
73 #define GET_VHT_CAPABILITY_ELE_MCS_RX_HIGHEST_RATE(_pEleStart)                  LE_BITS_TO_2BYTE((_pEleStart)+6, 0, 13)  
74 #define GET_VHT_CAPABILITY_ELE_TX_MCS(_pEleStart)                                              ((_pEleStart)+8)
75 #define GET_VHT_CAPABILITY_ELE_MCS_TX_HIGHEST_RATE(_pEleStart)                  LE_BITS_TO_2BYTE((_pEleStart)+10, 0, 13)  
76
77
78 //VHT Operation Information Element
79 #define SET_VHT_OPERATION_ELE_CHL_WIDTH(_pEleStart, _val)                       SET_BITS_TO_LE_1BYTE_8BIT(_pEleStart, 0, 8, _val)
80 #define SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(_pEleStart, _val)                        SET_BITS_TO_LE_1BYTE_8BIT(_pEleStart+1, 0, 8, _val)
81 #define SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(_pEleStart, _val)                        SET_BITS_TO_LE_1BYTE_8BIT(_pEleStart+2, 0, 8, _val)
82 #define SET_VHT_OPERATION_ELE_BASIC_MCS_SET(_pEleStart, _val)                   SET_BITS_TO_LE_2BYTE_16BIT((_pEleStart)+3, 0, 16, _val)
83
84 #define GET_VHT_OPERATION_ELE_CHL_WIDTH(_pEleStart)             LE_BITS_TO_1BYTE(_pEleStart,0,8)
85 #define GET_VHT_OPERATION_ELE_CENTER_FREQ1(_pEleStart)  LE_BITS_TO_1BYTE((_pEleStart)+1,0,8)
86 #define GET_VHT_OPERATION_ELE_CENTER_FREQ2(_pEleStart)     LE_BITS_TO_1BYTE((_pEleStart)+2,0,8)
87
88 //VHT Operating Mode 
89 #define SET_VHT_OPERATING_MODE_FIELD_CHNL_WIDTH(_pEleStart, _val)               SET_BITS_TO_LE_1BYTE(_pEleStart, 0, 2, _val)
90 #define SET_VHT_OPERATING_MODE_FIELD_RX_NSS(_pEleStart, _val)                   SET_BITS_TO_LE_1BYTE(_pEleStart, 4, 3, _val)
91 #define SET_VHT_OPERATING_MODE_FIELD_RX_NSS_TYPE(_pEleStart, _val)      SET_BITS_TO_LE_1BYTE(_pEleStart, 7, 1, _val)
92 #define GET_VHT_OPERATING_MODE_FIELD_CHNL_WIDTH(_pEleStart)                     LE_BITS_TO_1BYTE(_pEleStart, 0, 2)
93 #define GET_VHT_OPERATING_MODE_FIELD_RX_NSS(_pEleStart)                         LE_BITS_TO_1BYTE(_pEleStart, 4, 3)
94 #define GET_VHT_OPERATING_MODE_FIELD_RX_NSS_TYPE(_pEleStart)            LE_BITS_TO_1BYTE(_pEleStart, 7, 1)
95
96 #define SET_EXT_CAPABILITY_ELE_OP_MODE_NOTIF(_pEleStart, _val)                  SET_BITS_TO_LE_1BYTE((_pEleStart)+7, 6, 1, _val)
97 #define GET_EXT_CAPABILITY_ELE_OP_MODE_NOTIF(_pEleStart)                                LE_BITS_TO_1BYTE((_pEleStart)+7, 6, 1)
98
99 struct vht_priv
100 {
101         u8      vht_option;
102
103         u8      ldpc_cap;
104         u8      stbc_cap;
105         u8      beamform_cap;
106
107         u8      sgi_80m;//short GI
108         u8      ampdu_len;
109
110         u8      vht_op_mode_notify;
111         u8      vht_highest_rate;
112         u8      vht_mcs_map[2];
113
114         u8      vht_cap[32];
115 };
116
117 u8      rtw_get_vht_highest_rate(u8 *pvht_mcs_map);
118 void    rtw_get_vht_nss(u8 *pvht_mcs_map);
119 u16     rtw_vht_mcs_to_data_rate(u8 bw, u8 short_GI, u8 vht_mcs_rate);
120 u64     rtw_vht_rate_to_bitmap(u8 *pVHTRate);
121 void    rtw_vht_use_default_setting(_adapter *padapter);
122 u32     rtw_build_vht_operation_ie(_adapter *padapter, u8 *pbuf, u8 channel);
123 u32     rtw_build_vht_op_mode_notify_ie(_adapter *padapter, u8 *pbuf, u8 bw);
124 u32     rtw_build_vht_cap_ie(_adapter *padapter, u8 *pbuf);
125 void    update_sta_vht_info_apmode(_adapter *padapter, PVOID psta);
126 void    update_hw_vht_param(_adapter *padapter);
127 void    VHT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
128 void    VHT_operation_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
129 void    rtw_process_vht_op_mode_notify(_adapter *padapter, u8 *pframe, PVOID sta);
130 u32     rtw_restructure_vht_ie(_adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len);
131 void    VHTOnAssocRsp(_adapter *padapter);
132
133 #endif  //_RTW_VHT_H_
134