1 /****************************************************************************** 2 * 3 * Copyright(c) 2019 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 _PHL_TWT_H_ 16 #define _PHL_TWT_H_ 17 18 #ifdef CONFIG_PHL_TWT 19 #define MIN_TWT_ELE_LEN 15 20 #define MAX_NUM_HW_TWT_CONFIG 4 21 #define CONTROL_LENGTH 1 22 #define REQUEST_TYPE_LENGTH 2 23 #define NOMINAL_MINIMUM_TWT_WAKE_DURATION_LENGTH 1 24 #define TARGET_WAKE_TIME_LENGTH 8 25 #define NOMINAL_MIN_TWT_WAKE_DURATION_LENGTH 1 26 #define TWT_WAKE_INTERVAL_MANTISSA_LENGTH 2 27 #define TWT_CHANNEL_LENGTH 1 28 #define TWT_FLOW_FIELD_LENGTH 1 29 #define TOKEN_OFFSET 2 30 #define TOKEN_LENGTH 1 31 #define ELEM_ID_LEN 1 /* Length of element id*/ 32 #define ELEM_LEN_LEN 1 /* Length of element Length*/ 33 #define C2H_FUN_WAIT_ANNC 0x0 34 35 #define get_twt_info(_phl) (struct phl_twt_info *)(_phl->phl_twt_info) 36 #define set_config_state(_state, set_state) (_state = set_state) 37 #define twt_init(_phl) (NULL != (get_twt_info(_phl))) 38 #define twt_sup(_phl) (((struct phl_info_t *)_phl)->phl_com->dev_cap.twt_sup) 39 40 enum phl_operate_config_type { 41 PHL_OP_TYPE_NONE = 0, 42 PHL_GET_NEW_CONFIG, 43 PHL_FREE_CONFIG, 44 PHL_GET_CONFIG_BY_ID, 45 PHL_GET_CONFIG_BY_ROLE, 46 PHL_GET_CONFIG_BY_PARA, 47 PHL_GET_NEXT_CONFIG, 48 PHL_GET_HEAD_CONFIG 49 }; 50 51 enum phl_twt_action { 52 PHL_TWT_ACTION_NONE = 0, 53 PHL_TWT_ACTION_FREE, 54 PHL_TWT_ACTION_ALLOC, 55 PHL_TWT_ACTION_ENABLE, 56 PHL_TWT_ACTION_DISABLE, 57 PHL_TWT_ACTION_UP_ERROR 58 }; 59 60 enum phl_wait_annc_type { 61 PHL_WAIT_ANNC_DISABLE = 0, 62 PHL_WAIT_ANNC_ENABLE = 1 63 }; 64 65 enum twt_config_state { 66 twt_config_state_free = 0, 67 twt_config_state_idle, 68 twt_config_state_enable, 69 twt_config_state_error, 70 twt_config_state_unknown 71 }; 72 73 struct phl_twt_config{ 74 u8 idx; 75 enum twt_config_state state; 76 struct rtw_wifi_role_t *role; 77 struct rtw_phl_twt_info twt_info; 78 struct phl_queue twt_sta_queue; /*struct rtw_twt_sta_info*/ 79 }; 80 81 struct phl_twt_cfg_info { 82 u8 twt_cfg_num; 83 void *twt_cfg_ring; /*struct phl_twt_config*/ 84 }; 85 86 struct phl_twt_info { 87 struct phl_twt_cfg_info twt_cfg_info; 88 struct phl_queue twt_annc_queue;/*struct _twt_announce_info*/ 89 }; 90 91 struct _twt_announce_info{ 92 _os_list list; 93 u8 map_offset; 94 u32 wait_macid_map; 95 }; 96 97 struct _twt_compare { 98 struct rtw_phl_twt_setup_info twt_setup; 99 struct rtw_wifi_role_t *role; 100 }; 101 102 struct _twt_teardown { 103 struct rtw_phl_stainfo_t *phl_sta; 104 enum rtw_phl_nego_type nego_type; 105 u8 id; 106 }; 107 108 /* TWT element */ 109 /*Control*/ 110 #define SET_TWT_CONTROL_NDP_PAGING_INDICATOR(_ele_start, _val) \ 111 SET_BITS_TO_LE_1BYTE(_ele_start, 0, 1, _val) 112 #define SET_TWT_CONTROL_RESPONDER_PM_MODE(_ele_start, _val) \ 113 SET_BITS_TO_LE_1BYTE(_ele_start, 1, 1, _val) 114 #define SET_TWT_CONTROL_NEGOTIATION_TYPE(_ele_start, _val) \ 115 SET_BITS_TO_LE_1BYTE(_ele_start, 2, 2, _val) 116 #define SET_TWT_CONTROL_TWT_INFORMATION_FRAME_DISABLE(_ele_start, _val) \ 117 SET_BITS_TO_LE_1BYTE(_ele_start, 4, 1, _val) 118 #define SET_TWT_CONTROL_WAKE_DURATION_UNIT(_ele_start, _val) \ 119 SET_BITS_TO_LE_1BYTE(_ele_start, 5, 1, _val) 120 121 /*Individual TWT Parameter Set field*/ 122 /*Request Type*/ 123 #define SET_TWT_REQ_TYPE_TWT_REQUEST(_ele_start, _val) \ 124 SET_BITS_TO_LE_1BYTE(_ele_start, 0, 1, _val) 125 #define SET_TWT_REQ_TYPE_TWT_SETUP_COMMAND(_ele_start, _val) \ 126 SET_BITS_TO_LE_1BYTE(_ele_start, 1, 3, _val) 127 #define SET_TWT_REQ_TYPE_TRIGGER(_ele_start, _val) \ 128 SET_BITS_TO_LE_1BYTE(_ele_start, 4, 1, _val) 129 #define SET_TWT_REQ_TYPE_IMPLICIT(_ele_start, _val) \ 130 SET_BITS_TO_LE_1BYTE(_ele_start, 5, 1, _val) 131 #define SET_TWT_REQ_TYPE_FLOW_TYPE(_ele_start, _val) \ 132 SET_BITS_TO_LE_1BYTE(_ele_start, 6, 1, _val) 133 #define SET_TWT_REQ_TYPE_TWT_FLOW_IDENTIFER(_ele_start, _val) \ 134 SET_BITS_TO_LE_2BYTE(_ele_start, 7, 3, _val) 135 #define SET_TWT_REQ_TYPE_TWT_WAKE_INTERVAL_EXPONENT(_ele_start, _val) \ 136 SET_BITS_TO_LE_2BYTE(_ele_start, 10, 5, _val) 137 #define SET_TWT_REQ_TYPE_TWT_PROTECTION(_ele_start, _val) \ 138 SET_BITS_TO_LE_2BYTE(_ele_start, 15, 1, _val) 139 140 #define SET_TWT_TARGET_WAKE_TIME_L(_ele_start, _val) \ 141 SET_BITS_TO_LE_4BYTE((_ele_start) + 2, 0, 32, _val) 142 143 #define SET_TWT_TARGET_WAKE_TIME_H(_ele_start, _val) \ 144 SET_BITS_TO_LE_4BYTE((_ele_start) + 6, 0, 32, _val) 145 /*twt group assignment*/ 146 147 148 #define SET_TWT_NOMINAL_MINIMUM_TWT_WAKE_DURATION(_ele_start, _offset, _val) \ 149 SET_BITS_TO_LE_1BYTE((_ele_start) + _offset, 0, 8, _val) 150 #define SET_TWT_TWT_WAKE_INTERVAL_MANTISSA(_ele_start, _offset, _val) \ 151 SET_BITS_TO_LE_2BYTE((_ele_start) + _offset, 0, 16, _val) 152 #define SET_TWT_TWT_CHANNEL(_ele_start, _offset, _val) \ 153 SET_BITS_TO_LE_1BYTE((_ele_start) + _offset, 0, 8, _val) 154 155 156 /*Broadcast TWT Parameter Set field*/ 157 158 159 /*TWT FLOW field*/ 160 #define SET_TWT_FLOW_ID(_ele_start, _val) \ 161 SET_BITS_TO_LE_1BYTE(_ele_start, 0, 3, _val) 162 #define SET_NEGOTIATION_TYPE(_ele_start, _val) \ 163 SET_BITS_TO_LE_1BYTE(_ele_start, 5, 2, _val) 164 #define SET_TEARDOWN_ALL_TWT(_ele_start, _val) \ 165 SET_BITS_TO_LE_1BYTE(_ele_start, 7, 1, _val) 166 167 #define SET_BROADCAST_TWT_ID(_ele_start, _val) \ 168 SET_BITS_TO_LE_1BYTE(_ele_start, 0, 5, _val) 169 170 /*Control*/ 171 /*Bit0*/ 172 #define GET_TWT_CONTROL_NDP_PAGING_INDICATOR(_buf) \ 173 LE_BITS_TO_1BYTE(_buf, 0, 1) 174 /*Bit1*/ 175 #define GET_TWT_CONTROL_RESPONDER_PM_MODE(_buf) \ 176 LE_BITS_TO_1BYTE(_buf, 1, 1) 177 /*Bit2-3*/ 178 #define GET_TWT_CONTROL_NEGOTIATION_TYPE(_buf) \ 179 LE_BITS_TO_1BYTE(_buf, 2, 2) 180 /*Bit4*/ 181 #define GET_TWT_CONTROL_TWT_INFORMATION_FRAME_DISABLE(_buf) \ 182 LE_BITS_TO_1BYTE(_buf, 4, 1) 183 /*Bit5*/ 184 #define GET_TWT_CONTROL_WAKE_DURATION_UNIT(_buf) \ 185 LE_BITS_TO_1BYTE(_buf, 5, 1) 186 187 /*Request Type*/ 188 /*Bit0*/ 189 #define GET_TWT_REQ_TYPE_TWT_REQUEST(_buf) \ 190 LE_BITS_TO_2BYTE(_buf, 0, 1) 191 /*Bit1-3*/ 192 #define GET_TWT_REQ_TYPE_TWT_SETUP_COMMAND(_buf) \ 193 LE_BITS_TO_2BYTE(_buf, 1, 3) 194 /*Bit4*/ 195 #define GET_TWT_REQ_TYPE_TRIGGER(_buf) \ 196 LE_BITS_TO_2BYTE(_buf, 4, 1) 197 /*Bit5*/ 198 #define GET_TWT_REQ_TYPE_IMPLICIT(_buf) \ 199 LE_BITS_TO_2BYTE(_buf, 5, 1) 200 /*Bit6*/ 201 #define GET_TWT_REQ_TYPE_FLOW_TYPE(_buf) \ 202 LE_BITS_TO_2BYTE(_buf, 6, 1) 203 /*Bit7-9*/ 204 #define GET_TWT_REQ_TYPE_TWT_FLOW_IDENTIFER(_buf) \ 205 LE_BITS_TO_2BYTE(_buf, 7, 3) 206 /*Bit10-14*/ 207 #define GET_TWT_REQ_TYPE_TWT_WAKE_INTERVAL_EXPONENT(_buf) \ 208 LE_BITS_TO_2BYTE(_buf, 10, 5) 209 /*Bit15*/ 210 #define GET_TWT_REQ_TYPE_TWT_PROTECTION(_buf) \ 211 LE_BITS_TO_2BYTE(_buf, 15, 1) 212 213 #define GET_TWT_TARGET_WAKE_TIME_L(_buf) \ 214 LE_BITS_TO_4BYTE(_buf, 0, 32) 215 #define GET_TWT_TARGET_WAKE_TIME_H(_buf) \ 216 LE_BITS_TO_4BYTE((_buf) + 4, 0, 32) 217 #define GET_TWT_NOMINAL_MINIMUM_TWT_WAKE_DURATION(_buf) \ 218 LE_BITS_TO_1BYTE(_buf, 0 , 8); 219 #define GET_TWT_TWT_WAKE_INTERVAL_MANTISSA(_buf) \ 220 LE_BITS_TO_2BYTE(_buf, 0, 16); 221 #define GET_TWT_TWT_CHANNEL(_buf) \ 222 LE_BITS_TO_1BYTE(_buf, 0 ,8); 223 224 /*TWT FLOW field*/ 225 /*Bit0-2*/ 226 #define GET_TWT_FLOW_ID(_buf) \ 227 LE_BITS_TO_1BYTE(_buf, 0, 3) 228 /*Bit5-6*/ 229 #define GET_NEGOTIATION_TYPE(_buf) \ 230 LE_BITS_TO_1BYTE(_buf, 5 , 2); 231 /*Bit7*/ 232 #define GET_TEARDOWN_ALL_TWT(_buf) \ 233 LE_BITS_TO_1BYTE(_buf, 7, 1) 234 /*Bit0-4*/ 235 #define GET_BROADCAST_TWT_ID(_buf) \ 236 LE_BITS_TO_1BYTE(_buf, 0, 5) 237 238 239 #define GET_ELE_ID(_buf) \ 240 LE_BITS_TO_1BYTE(_buf, 0, 8); 241 #define GET_ELE_LEN(_buf) \ 242 LE_BITS_TO_1BYTE(_buf, 0, 8); 243 #define GET_DIALOG_TOKEN(_buf) \ 244 LE_BITS_TO_1BYTE(_buf, 0, 8); 245 246 247 enum rtw_phl_status phl_twt_init(void *phl); 248 249 void phl_twt_deinit(void *phl); 250 251 enum rtw_phl_status 252 rtw_phl_twt_disable_all_twt_by_role(void *phl, struct rtw_wifi_role_t *role); 253 254 enum rtw_phl_status rtw_phl_twt_alloc_twt_config(void *phl, struct rtw_wifi_role_t *role, 255 struct rtw_phl_twt_setup_info setup_info, u8 benable, u8 *id); 256 257 enum rtw_phl_status rtw_phl_twt_free_twt_config(void *phl, u8 id); 258 259 enum rtw_phl_status rtw_phl_twt_add_sta_info(void *phl, struct rtw_phl_stainfo_t *phl_sta, 260 u8 config_id, u8 id); 261 262 #else 263 264 #define phl_twt_init(_phl) RTW_PHL_STATUS_SUCCESS 265 #define phl_twt_deinit(_phl) 266 267 #endif /* CONFIG_PHL_TWT */ 268 #endif /*_PHL_TWT_H_*/ 269