[6319] | 1 | /** @file wlan_mac_pkt_buf_util.h |
---|
| 2 | * @brief Packet Buffer Definitions |
---|
| 3 | * |
---|
| 4 | * This contains code common to both CPU_LOW and CPU_HIGH that allows them |
---|
| 5 | * to use the packet buffers. |
---|
| 6 | * |
---|
| 7 | * @copyright Copyright 2013-2019, Mango Communications. All rights reserved. |
---|
| 8 | * Distributed under the Mango Communications Reference Design License |
---|
| 9 | * See LICENSE.txt included in the design archive or |
---|
| 10 | * at http://mangocomm.com/802.11/license |
---|
| 11 | * |
---|
| 12 | * This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11) |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | /*************************** Constant Definitions ****************************/ |
---|
| 17 | |
---|
| 18 | #ifndef WLAN_MAC_PKT_BUF_UTIL_H_ |
---|
| 19 | #define WLAN_MAC_PKT_BUF_UTIL_H_ |
---|
| 20 | |
---|
| 21 | #include "xil_types.h" |
---|
| 22 | #include "wlan_common_types.h" |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | // Base index of mutex for Tx/Rx packet buffers |
---|
| 26 | #define PKT_BUF_MUTEX_TX_BASE 0 |
---|
| 27 | #define PKT_BUF_MUTEX_RX_BASE 16 |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | // Mutex status values |
---|
| 31 | #define PKT_BUF_MUTEX_SUCCESS 0 |
---|
| 32 | #define PKT_BUF_MUTEX_FAIL_INVALID_BUF -1 |
---|
| 33 | #define PKT_BUF_MUTEX_FAIL_ALREADY_LOCKED -2 |
---|
| 34 | #define PKT_BUF_MUTEX_FAIL_NOT_LOCK_OWNER -3 |
---|
| 35 | #define PKT_BUF_MUTEX_ALREADY_UNLOCKED -4 |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | //----------------------------------------------- |
---|
| 39 | // Packet buffer defines |
---|
| 40 | // |
---|
| 41 | #define NUM_TX_PKT_BUFS 16 |
---|
| 42 | #define NUM_RX_PKT_BUFS 8 |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | // Packet buffer size (in bytes) |
---|
| 46 | #define PKT_BUF_SIZE 4096 |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // Tx packet buffer assignments |
---|
| 50 | // The definitions for the MPDU packet buffers are not directly |
---|
| 51 | // used. Instead, the actual packet buffer values are used to |
---|
| 52 | // make iteration easier. |
---|
| 53 | // |
---|
| 54 | // Packet Buffers owned by CPU_HIGH at boot |
---|
| 55 | |
---|
| 56 | #define NUM_TX_PKT_BUF_MPDU 6 |
---|
| 57 | |
---|
| 58 | #define TX_PKT_BUF_MPDU_1 0 |
---|
| 59 | #define TX_PKT_BUF_MPDU_2 1 |
---|
| 60 | #define TX_PKT_BUF_MPDU_3 2 |
---|
| 61 | #define TX_PKT_BUF_MPDU_4 3 |
---|
| 62 | #define TX_PKT_BUF_MPDU_5 4 |
---|
| 63 | #define TX_PKT_BUF_MPDU_6 5 |
---|
| 64 | #define TX_PKT_BUF_BEACON 6 |
---|
| 65 | // Packet Buffers owned by CPU_LOW at boot |
---|
| 66 | #define TX_PKT_BUF_RTS 7 |
---|
| 67 | #define TX_PKT_BUF_ACK_CTS 8 |
---|
| 68 | |
---|
| 69 | //#define TX_PKT_BUF_DTIM_MCAST 0x80 |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | // Tx / Rx packet buffer macros |
---|
| 73 | // |
---|
| 74 | // Packet buffer memory format: |
---|
| 75 | // - [(M - 1): 0] - Frame info structure (M is the size of the frame info for Tx / Rx) |
---|
| 76 | // - See definitions below for rx_frame_info / tx_frame_info |
---|
| 77 | // |
---|
| 78 | // - [(M + 15): M] - PHY Header (16 bytes) |
---|
| 79 | // - 11a: |
---|
| 80 | // [ 2: 0] SIGNAL |
---|
| 81 | // [ 4: 3] SERVICE (must be 0) |
---|
| 82 | // [15: 5] Reserved (should be 0) |
---|
| 83 | // [ N:16] MAC payload - first header byte at [16] |
---|
| 84 | // - 11n: |
---|
| 85 | // [ 2: 0] L-SIG (same format as 11a SIGNAL) |
---|
| 86 | // [ 8: 3] HT-SIG |
---|
| 87 | // [10: 9] SERVICE (must be 0) |
---|
| 88 | // [15:11] Reserved (should be 0) |
---|
| 89 | // [ N:16] MAC payload - first header byte at [16] |
---|
| 90 | // |
---|
| 91 | // - [(M + N):(M + 16)] - MAC payload (N is the size of the MAC payload) |
---|
| 92 | // - Standard 802.11 MAC payload |
---|
| 93 | // |
---|
| 94 | |
---|
| 95 | #define CALC_PKT_BUF_ADDR(baseaddr, buf_idx) ( (baseaddr) + (((buf_idx) & 0xF) * PKT_BUF_SIZE) ) |
---|
| 96 | |
---|
| 97 | #define PHY_RX_PKT_BUF_PHY_HDR_OFFSET (sizeof(rx_frame_info_t)) |
---|
| 98 | #define PHY_TX_PKT_BUF_PHY_HDR_OFFSET (sizeof(tx_frame_info_t)) |
---|
| 99 | |
---|
| 100 | #define PHY_RX_PKT_BUF_PHY_HDR_SIZE 0x10 |
---|
| 101 | #define PHY_TX_PKT_BUF_PHY_HDR_SIZE 0x10 |
---|
| 102 | |
---|
| 103 | #define PHY_RX_PKT_BUF_MPDU_OFFSET (PHY_RX_PKT_BUF_PHY_HDR_SIZE + PHY_RX_PKT_BUF_PHY_HDR_OFFSET) |
---|
| 104 | #define PHY_TX_PKT_BUF_MPDU_OFFSET (PHY_TX_PKT_BUF_PHY_HDR_SIZE + PHY_TX_PKT_BUF_PHY_HDR_OFFSET) |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | /*********************** Global Structure Definitions ************************/ |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | //----------------------------------------------- |
---|
| 113 | // Packet buffer state |
---|
| 114 | // |
---|
| 115 | |
---|
| 116 | typedef enum __attribute__ ((__packed__)) { |
---|
| 117 | TX_PKT_BUF_UNINITIALIZED = 0, |
---|
| 118 | TX_PKT_BUF_HIGH_CTRL = 1, |
---|
| 119 | TX_PKT_BUF_READY = 2, |
---|
| 120 | TX_PKT_BUF_LOW_CTRL = 3, |
---|
| 121 | TX_PKT_BUF_DONE = 4 |
---|
| 122 | } tx_pkt_buf_state_t; |
---|
| 123 | |
---|
| 124 | typedef enum __attribute__ ((__packed__)) { |
---|
| 125 | RX_PKT_BUF_UNINITIALIZED = 0, |
---|
| 126 | RX_PKT_BUF_HIGH_CTRL = 1, |
---|
| 127 | RX_PKT_BUF_READY = 2, |
---|
| 128 | RX_PKT_BUF_LOW_CTRL = 3 |
---|
| 129 | } rx_pkt_buf_state_t; |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | //----------------------------------------------- |
---|
| 134 | // Meta-data about transmissions from CPU Low |
---|
| 135 | // - This struct must be padded to be an integer number of u32 words. |
---|
| 136 | // |
---|
| 137 | typedef struct __attribute__ ((__packed__)) wlan_mac_low_tx_details_t{ |
---|
| 138 | u64 tx_start_timestamp_mpdu; |
---|
| 139 | u64 tx_start_timestamp_ctrl; |
---|
| 140 | phy_tx_params_t phy_params_mpdu; |
---|
| 141 | phy_tx_params_t phy_params_ctrl; |
---|
| 142 | |
---|
| 143 | u8 tx_details_type; |
---|
| 144 | u8 chan_num; |
---|
| 145 | u16 duration; |
---|
| 146 | |
---|
| 147 | s16 num_slots; |
---|
| 148 | u16 cw; |
---|
| 149 | |
---|
| 150 | u8 tx_start_timestamp_frac_mpdu; |
---|
| 151 | u8 tx_start_timestamp_frac_ctrl; |
---|
| 152 | u8 src; |
---|
| 153 | u8 lrc; |
---|
| 154 | |
---|
| 155 | u16 ssrc; |
---|
| 156 | u16 slrc; |
---|
| 157 | |
---|
| 158 | u8 flags; |
---|
| 159 | u8 reserved; |
---|
| 160 | u16 attempt_number; |
---|
| 161 | |
---|
| 162 | } wlan_mac_low_tx_details_t; |
---|
| 163 | ASSERT_TYPE_SIZE(wlan_mac_low_tx_details_t, 44); |
---|
| 164 | |
---|
| 165 | #define TX_DETAILS_FLAGS_RECEIVED_RESPONSE 1 |
---|
| 166 | |
---|
| 167 | // tx_details_type defines |
---|
| 168 | #define TX_DETAILS_MPDU 0 |
---|
| 169 | #define TX_DETAILS_RTS_ONLY 1 |
---|
| 170 | #define TX_DETAILS_RTS_MPDU 2 |
---|
| 171 | #define TX_DETAILS_CTS 3 |
---|
| 172 | #define TX_DETAILS_ACK 4 |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | //----------------------------------------------- |
---|
| 176 | // RX PHY details |
---|
| 177 | // - Information recorded from the RX PHY when receiving a packet |
---|
| 178 | // - While N_DBPS can be calculated from (mcs, phy_mode), it is easier to calculate |
---|
| 179 | // the value once in CPU Low and pass it up vs re-calculating it in CPU High. |
---|
| 180 | // - This structure must be 32-bit aligned |
---|
| 181 | // |
---|
| 182 | typedef struct phy_rx_details_t{ |
---|
| 183 | u8 mcs; |
---|
| 184 | u8 phy_mode; |
---|
| 185 | u16 length; |
---|
| 186 | } phy_rx_details_t; |
---|
| 187 | ASSERT_TYPE_SIZE(phy_rx_details_t, 4); |
---|
| 188 | |
---|
| 189 | //----------------------------------------------- |
---|
| 190 | // TX frame information |
---|
| 191 | // - Defines the information passed in the packet buffer between CPU High and |
---|
| 192 | // CPU Low as part of transmitting packets. |
---|
| 193 | // |
---|
| 194 | // IMPORTANT: This structure must be 8-byte aligned. |
---|
| 195 | // |
---|
| 196 | typedef struct tx_frame_info_t{ |
---|
| 197 | u64 timestamp_accept; ///< Time in microseconds between timestamp_create and packet acceptance by CPU Low |
---|
| 198 | u64 timestamp_done; ///< Time in microseconds between acceptance and transmit completion |
---|
| 199 | //----- 8-byte boundary ------ |
---|
| 200 | u64 unique_seq; ///< Unique sequence number for this packet (12 LSB used as 802.11 MAC sequence number) |
---|
| 201 | //----- 8-byte boundary ------ |
---|
| 202 | tx_queue_details_t queue_info; ///< Information about the TX queue used for the packet (4 bytes) |
---|
| 203 | u16 num_tx_attempts; ///< Number of transmission attempts for this frame |
---|
| 204 | u8 tx_result; ///< Result of transmission attempt - TX_MPDU_RESULT_SUCCESS or TX_MPDU_RESULT_FAILURE |
---|
| 205 | u8 tx_details_type; ///< Type that should be included in Tx Details report |
---|
| 206 | //----- 8-byte boundary ------ |
---|
| 207 | volatile tx_pkt_buf_state_t tx_pkt_buf_state; ///< State of the Tx Packet Buffer |
---|
| 208 | u8 flags; ///< Bit flags en/disabling certain operations by the lower-level MAC |
---|
| 209 | u8 phy_samp_rate; ///< PHY Sampling Rate |
---|
| 210 | u8 padding0; ///< Used for alignment of fields (can be appropriated for any future use) |
---|
| 211 | |
---|
| 212 | u16 length; ///< Number of bytes in MAC packet, including MAC header and FCS |
---|
| 213 | u16 reserved1; |
---|
| 214 | //----- 8-byte boundary ------ |
---|
| 215 | |
---|
| 216 | // |
---|
| 217 | // Place additional fields here. Make sure the new fields keep the structure 8-byte aligned |
---|
| 218 | // |
---|
| 219 | |
---|
| 220 | //----- 8-byte boundary ------ |
---|
| 221 | tx_params_t params; ///< Additional lower-level MAC and PHY parameters (8 bytes) |
---|
| 222 | } tx_frame_info_t; |
---|
| 223 | |
---|
| 224 | // The above structure assumes that pkt_buf_state_t is a u8. However, that is architecture dependent. |
---|
| 225 | // Therefore, the code will check the size of the structure using a compile-time assertion. This check |
---|
| 226 | // will need to be updated if fields are added to the structure |
---|
| 227 | // |
---|
| 228 | ASSERT_TYPE_SIZE(tx_frame_info_t, 56); |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | // Defines for tx_result field |
---|
| 232 | #define TX_FRAME_INFO_RESULT_SUCCESS 0 |
---|
| 233 | #define TX_FRAME_INFO_RESULT_FAILURE 1 |
---|
| 234 | |
---|
| 235 | // Defines for flags field |
---|
| 236 | #define TX_FRAME_INFO_FLAGS_REQ_TO 0x01 |
---|
| 237 | #define TX_FRAME_INFO_FLAGS_FILL_TIMESTAMP 0x02 |
---|
| 238 | #define TX_FRAME_INFO_FLAGS_FILL_DURATION 0x04 |
---|
| 239 | #define TX_FRAME_INFO_FLAGS_WAIT_FOR_LOCK 0x10 |
---|
| 240 | #define TX_FRAME_INFO_FLAGS_FILL_UNIQ_SEQ 0x20 |
---|
| 241 | #define TX_FRAME_INFO_FLAGS_PKT_BUF_PREPARED 0x80 |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | //----------------------------------------------- |
---|
| 245 | // RX frame information |
---|
| 246 | // - Defines the information passed in the packet buffer between CPU High and |
---|
| 247 | // CPU Low as part of receiving packets. |
---|
| 248 | // - The struct is padded to give space for the PHY to fill in channel estimates. |
---|
| 249 | // |
---|
| 250 | // IMPORTANT: This structure must be 8-byte aligned. |
---|
| 251 | // |
---|
| 252 | typedef struct __attribute__ ((__packed__)) rx_frame_info_t{ |
---|
| 253 | u8 flags; ///< Bit flags |
---|
| 254 | u8 ant_mode; ///< Rx antenna selection |
---|
| 255 | s8 rx_power; ///< Rx power, in dBm |
---|
| 256 | u8 rx_gain_index; ///< Rx gain index - interpretation is radio-specific |
---|
| 257 | u8 channel; ///< Channel index |
---|
| 258 | volatile rx_pkt_buf_state_t rx_pkt_buf_state; ///< State of the Rx Packet Buffer |
---|
| 259 | u16 reserved0; |
---|
| 260 | //----- 8-byte boundary ------ |
---|
| 261 | u32 cfo_est; ///< Carrier Frequency Offset Estimate |
---|
| 262 | phy_rx_details_t phy_details; ///< Details from PHY used in this reception |
---|
| 263 | //----- 8-byte boundary ------ |
---|
| 264 | u8 timestamp_frac; ///< Fractional timestamp beyond usec timestamp for time of reception |
---|
| 265 | u8 phy_samp_rate; ///< PHY Sampling Rate |
---|
| 266 | u8 reserved2[2]; ///< Reserved bytes for alignment |
---|
| 267 | u32 reserved3; |
---|
| 268 | //----- 8-byte boundary ------ |
---|
| 269 | wlan_mac_low_tx_details_t resp_low_tx_details; ///< Tx Low Details for a control resonse (e.g. ACK or CTS) |
---|
| 270 | u32 reservedr; |
---|
| 271 | //----- 8-byte boundary ------ |
---|
| 272 | u64 timestamp; ///< MAC timestamp at time of reception |
---|
| 273 | //----- 8-byte boundary ------ |
---|
| 274 | u32 channel_est[64]; ///< Rx PHY channel estimates |
---|
| 275 | } rx_frame_info_t; |
---|
| 276 | // The above structure assumes that pkt_buf_state_t is a u8. However, that is architecture dependent. |
---|
| 277 | // Therefore, the code will check the size of the structure using a compile-time assertion. This check |
---|
| 278 | // will need to be updated if fields are added to the structure |
---|
| 279 | // |
---|
| 280 | ASSERT_TYPE_SIZE(rx_frame_info_t, 336); |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | // Defines for flags field |
---|
| 284 | #define RX_FRAME_INFO_FLAGS_CTRL_RESP_TX 0x1 |
---|
| 285 | #define RX_FRAME_INFO_FLAGS_RETRY 0x2 |
---|
| 286 | #define RX_FRAME_INFO_FLAGS_FCS_GOOD 0x4 |
---|
| 287 | #define RX_FRAME_INFO_UNEXPECTED_RESPONSE 0x8 |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | /*************************** Function Prototypes *****************************/ |
---|
| 291 | |
---|
| 292 | int init_pkt_buf(); |
---|
| 293 | |
---|
| 294 | // TX packet buffer functions |
---|
| 295 | int lock_tx_pkt_buf(u8 pkt_buf_ind); |
---|
| 296 | int force_lock_tx_pkt_buf(u8 pkt_buf_ind); |
---|
| 297 | int unlock_tx_pkt_buf(u8 pkt_buf_ind); |
---|
| 298 | int get_tx_pkt_buf_status(u8 pkt_buf_ind, u32* locked, u32 *owner); |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | // RX packet buffer functions |
---|
| 302 | int lock_rx_pkt_buf(u8 pkt_buf_ind); |
---|
| 303 | int force_lock_rx_pkt_buf(u8 pkt_buf_ind); |
---|
| 304 | int unlock_rx_pkt_buf(u8 pkt_buf_ind); |
---|
| 305 | int get_rx_pkt_buf_status(u8 pkt_buf_ind, u32* locked, u32 *owner); |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | #endif /* WLAN_MAC_IPC_UTIL_H_ */ |
---|