1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef _WIFI_TX_SWDESC_H 16 #define _WIFI_TX_SWDESC_H 17 18 /** 19 **************************************************************************************** 20 * @defgroup TX_SWDESC TX_SWDESC 21 * @ingroup TX 22 * @brief Definition and management of Tx SW descriptors 23 * @{ 24 **************************************************************************************** 25 */ 26 27 /* 28 * INCLUDE FILES 29 **************************************************************************************** 30 */ 31 #include "wb_co_int.h" 32 #include "wb_co_bool.h" 33 #include "wb_co_list.h" 34 35 #include "rwnx_config.h" 36 #include "wifi_mac.h" 37 #include "wifi_mac_frame.h" 38 39 /* 40 * DEFINES 41 **************************************************************************************** 42 */ 43 44 #if NX_AMPDU_TX 45 ///AMDPU delimiter length in bytes 46 #define DELIMITER_LEN 4 47 #endif //(NX_AMPDU_TX) 48 49 #define RATE_CONTROL_STEPS 4 50 51 /// Singleton frame can be transmitted using beamforming 52 #define TX_SWDESC_UMAC_BEAMFORM_BIT (CO_BIT(0)) 53 /// Singleton trial frame can be transmitted using beamforming 54 #define TX_SWDESC_UMAC_TRIAL_BEAMFORM_BIT (CO_BIT(1)) 55 /// Trial frame can be transmitted using STBC 56 #define TX_SWDESC_UMAC_TRIAL_STBC_BIT (CO_BIT(2)) 57 58 /* 59 * TYPE and STRUCT DEFINITIONS 60 **************************************************************************************** 61 */ 62 63 /// Structure indicating the status and other information about the transmission 64 struct tx_cfm_tag 65 { 66 /// PN that was used for the transmission 67 uint16_t pn[4]; 68 /// Sequence number of the packet 69 uint16_t sn; 70 /// Timestamp of first transmission of this MPDU 71 uint16_t timestamp; 72 /// Number of flow control credits allocated 73 int8_t credits; 74 /// Size (in mdpu) of the A-MPDU in which this frame as been transmitted. 75 /// Valid only for singleton (=1) or last frame of the A-MPDU 76 uint8_t ampdu_size; 77 #if NX_AMSDU_TX 78 /// Size allowed for AMSDU 79 uint16_t amsdu_size; 80 #endif 81 82 /// TX status 83 uint32_t status; 84 }; 85 86 87 /// Descriptor filled by the Host 88 struct hostdesc 89 { 90 #if NX_AMSDU_TX 91 /// Pointers to packet payloads 92 uint32_t packet_addr[NX_TX_PAYLOAD_MAX]; 93 /// Sizes of the MPDU/MSDU payloads 94 uint16_t packet_len[NX_TX_PAYLOAD_MAX]; 95 /// Number of payloads forming the MPDU 96 uint8_t packet_cnt; 97 #else 98 /// Pointer to packet payload 99 uint32_t packet_addr; 100 /// Size of the payload 101 uint16_t packet_len; 102 #endif //(NX_AMSDU_TX) 103 104 /// Address of the status descriptor in host memory (used for confirmation upload) 105 uint32_t status_desc_addr; 106 /// Destination Address 107 struct mac_addr eth_dest_addr; 108 /// Source Address 109 struct mac_addr eth_src_addr; 110 /// Ethernet Type 111 uint16_t ethertype; 112 /// PN that was used for first transmission of this MPDU 113 uint16_t pn[4]; 114 /// Sequence Number used for first transmission of this MPDU 115 uint16_t sn; 116 /// Timestamp of first transmission of this MPDU 117 uint16_t timestamp; 118 119 /// Packet TID 120 uint8_t tid; 121 /// VIF index 122 uint8_t vif_idx; 123 /// Station Id (0xFF if station is unknown) 124 uint8_t staid; 125 #if RW_MUMIMO_TX_EN 126 /// MU-MIMO information (GroupId and User Position in the group) - The GroupId 127 /// is located on bits 0-5 and the User Position on bits 6-7. The GroupId value is set 128 /// to 63 if MU-MIMO shall not be used 129 uint8_t mumimo_info; 130 #endif 131 132 /// TX flags 133 uint16_t flags; 134 135 /// TX confirmation callback (Only used for mgmt frame) 136 void *cfm_cb; 137 /// TX confirmation callback argument 138 void *cfm_cb_arg; 139 /// TX confirmation info 140 struct tx_cfm_tag cfm; 141 }; 142 /// Policy Table Structure used to store Policy Table Information used by MAC HW to 143 /// prepare transmit vector to used by PHY. 144 struct tx_policy_tbl 145 { 146 /// Unique Pattern at the start of Policy Table 147 uint32_t upatterntx; 148 /// PHY Control Information 1 used by MAC HW 149 uint32_t phycntrlinfo1; 150 /// PHY Control Information 2 used by MAC HW 151 uint32_t phycntrlinfo2; 152 /// MAC Control Information 1 used by MAC HW 153 uint32_t maccntrlinfo1; 154 /// MAC Control Information 2 used by MAC HW 155 uint32_t maccntrlinfo2; 156 /// Rate Control Information used by MAC HW 157 uint32_t ratecntrlinfo[RATE_CONTROL_STEPS]; 158 /// Power Control Information used by MAC HW 159 uint32_t powercntrlinfo[RATE_CONTROL_STEPS]; 160 }; 161 /// Compressed Policy Table Structure used to store Policy Table Information used by MAC HW 162 /// to get TX information for secondary users in case of MU-MIMO PPDU transmission. 163 struct tx_compressed_policy_tbl 164 { 165 /// Unique Pattern at the start of Policy Table 166 uint32_t upatterntx; 167 /// Secondary User Control Information 168 uint32_t sec_user_control; 169 }; 170 171 /// Packet descriptor 172 struct txl_buffer_control 173 { 174 union 175 { 176 /// Policy table (filled by the upper MAC) 177 struct tx_policy_tbl policy_tbl; 178 /// Compressed policy table (used for MU-MIMO if enabled) 179 struct tx_compressed_policy_tbl comp_pol_tbl; 180 }; 181 /// MAC Control Information field (filled by the upper MAC) 182 uint32_t mac_control_info; 183 /// PHY Control Information field (filled by the upper MAC) 184 uint32_t phy_control_info; 185 /** 186 * Flags from UMAC which do not fit with tx_hd.macctrlinfo2 format 187 * Bit 0 - Indicate if frame can be beamformed when sent as a singleton 188 * Bit 1 - Indicate if trial frame can be beamformed when sent as a singleton 189 * Bit 2 - Indicate if trial frame can be sent using STBC 190 */ 191 uint32_t tx_flags; 192 }; 193 194 /// Descriptor filled by the UMAC 195 struct umacdesc 196 { 197 #if NX_AMPDU_TX 198 ///First Sequence Number of the BlockAck window 199 uint16_t sn_win; 200 /// Flags from UMAC (match tx_hd.macctrlinfo2 format) 201 uint32_t flags; 202 /// PHY related flags field - nss, rate, GI type, BW type - filled by driver 203 uint32_t phy_flags; 204 #endif //(NX_AMPDU_TX) 205 /// Pointer to the buffer control to use 206 struct txl_buffer_control *buf_control; 207 /// Length of the payload 208 uint16_t payl_len; 209 /// Header length (MAC + IV + EIV + 802.2 Header) 210 uint8_t head_len; 211 /// 802.2 header length 212 uint8_t hdr_len_802_2; 213 /// Tail length (MIC + ICV) 214 uint8_t tail_len; 215 #if (RW_MESH_EN) 216 /// Indicate if Mesh Control field is present in the sent frame 217 bool has_mesh_ctrl; 218 /// Number of External Addresses to be inserted in the Mesh Control field 219 uint8_t nb_ext_addr; 220 /// Index of the path to be used 221 uint8_t path_idx; 222 /// Index of the proxy information to be used 223 uint8_t proxy_idx; 224 #endif //(RW_MESH_EN) 225 }; 226 227 /// Definition of a TX header descriptor. 228 struct tx_hd 229 { 230 /// Unique pattern for transmit DMA. 231 uint32_t upatterntx; 232 /// Starting descriptor of the next atomic frame exchange sequence. 233 uint32_t nextfrmexseq_ptr; 234 /// Next MPDU in the frame exchange. 235 uint32_t nextmpdudesc_ptr; 236 /// First payload buffer descriptor/Secondary user 1 THD address 237 union { 238 /// First payload buffer descriptor 239 uint32_t first_pbd_ptr; 240 /// Secondary user 1 THD address 241 uint32_t sec_user1_ptr; 242 }; 243 /// Data buffer start/Secondary user 2 THD address. 244 union { 245 /// Data buffer start 246 uint32_t datastartptr; 247 /// Secondary user 2 THD address 248 uint32_t sec_user2_ptr; 249 }; 250 /// Data buffer end /Secondary user 3 THD address. 251 union { 252 /// Data buffer end 253 uint32_t dataendptr; 254 /// Secondary user 3 THD address 255 uint32_t sec_user3_ptr; 256 }; 257 /// Total length of the frame on air. 258 uint32_t frmlen; 259 /// MSDU lifetime parameter (for EDCA frame). 260 uint32_t frmlifetime; 261 /// Valid only for A-MPDU header descriptor and for singleton MPDUs. 262 uint32_t phyctrlinfo; 263 /// Valid only for A-MPDU header descriptor and for singleton MPDUs. 264 uint32_t policyentryaddr; 265 /// Optional length fields in case of BW drop 266 uint32_t optlen[3]; 267 /// Valid only for A-MPDU header descriptor and for singleton MPDUs. 268 uint32_t macctrlinfo1; 269 /// Valid only for MPDU header descriptor and for singleton MPDUs. 270 uint32_t macctrlinfo2; 271 /// Valid only for A-MPDU header descriptor and for singleton MPDUs. 272 uint32_t statinfo; 273 /// Medium time used. 274 uint32_t mediumtimeused; 275 }; 276 277 /// Definition of a TX payload buffer descriptor. 278 struct tx_pbd 279 { 280 /// Unique pattern for transmit buffer descriptor. 281 uint32_t upatterntx; 282 /// Next buffer descriptor of the MPDU when the MPDU is split over several buffers. 283 uint32_t next; 284 /// Data start in the buffer associated with this buffer descriptor. 285 uint32_t datastartptr; 286 /// Data end in the buffer associated with this buffer descriptor (inclusive). 287 uint32_t dataendptr; 288 /// Buffer control for transmit DMA. 289 uint32_t bufctrlinfo; 290 }; 291 292 293 /// Aggregation descriptor, containing AMPDU THD, BAR descriptor, BAR payload and Policy Table 294 struct tx_agg_desc 295 { 296 /// Pointer to the next element in the queue 297 struct co_list_hdr list_hdr; 298 /// Current status of the aggregation process 299 uint16_t status; 300 /// Amount of data currently downloaded for this A-MPDU 301 uint16_t available_len; 302 /// Number of MPDUs downloaded for this A-MPDU 303 uint8_t available_cnt; 304 /// STA IDX for which AMPDU is being built 305 uint8_t sta_idx; 306 /// TID for which AMPDU is being built 307 uint8_t tid; 308 /// Number of "users" currently sharing this descriptor 309 /// The descriptor will be freed only when no more SW modules are using it 310 uint8_t user_cnt; 311 /// AMPDU THD (no payload) 312 struct tx_hd a_thd; 313 /// BAR THD 314 struct tx_hd bar_thd; 315 /// BAR payload space (no FCS) 316 struct bar_frame bar_payl; 317 /// Policy table for explicit BAR frame 318 struct tx_policy_tbl bar_pol_tbl; 319 /// Pointer to the BA SSC + bitmap 320 struct ba_ssc_bitmap *ssc_bitmap; 321 /// Pointer to the BA SSC + bitmap 322 struct ba_ssc_bitmap_256 ssc_bitmap_tab; 323 #if NX_MAC_HE 324 /// Policy table for A-MPDU 325 struct tx_policy_tbl pol_tbl; 326 /// Pointer to last TX descriptor of the A-MPDU 327 struct txdesc *txdesc_last; 328 #endif 329 #if NX_BW_LEN_ADAPT 330 /// Pointer to TX descriptors finishing a BW step 331 struct txdesc *txdesc[NX_BW_LEN_STEPS - 1]; 332 #endif 333 #if RW_MUMIMO_TX_EN 334 /// List containing the descriptors to be confirmed once BA is received for this 335 /// secondary user 336 struct co_list cfm; 337 /// Pointer to the primary TX descriptor 338 struct tx_agg_desc *prim_agg_desc; 339 /// Pointer to the last BAR THD of the MU-MIMO frame exchange 340 struct tx_hd *last_bar_thd; 341 /// Bitfield indicating which user indexes have still data to download before being 342 /// able to be chained to HW 343 uint8_t download; 344 #endif 345 /// List in which the A-MPDU descriptor has to be pushed back after transmission 346 struct co_list *free_list; 347 }; 348 349 /// Definition of a TX confirmation descriptor 350 struct tx_hw_desc 351 { 352 /// TX header descriptor attached to the MPDU 353 struct tx_hd thd; 354 }; 355 356 /// LMAC Tx Descriptor 357 struct txdesc 358 { 359 /// Pointer to the next element in the queue 360 struct co_list_hdr list_hdr; 361 /// Information provided by Host 362 struct hostdesc host; 363 }; 364 365 /// Description of the TX API 366 struct txdesc_api 367 { 368 /// Information provided by Host 369 struct hostdesc host; 370 }; 371 372 #if 0 373 /// Descriptor used for Host/Emb TX frame information exchange 374 struct txdesc_host 375 { 376 /// Flag indicating if the TX descriptor is ready (different from 0) or not (equal to 0) 377 uint32_t ready; 378 379 /// API of the embedded part 380 struct txdesc_api api; 381 }; 382 383 #endif 384 385 #endif // _WIFI_TX_SWDESC_H 386