source: ReferenceDesigns/w3_802.11/c/wlan_mac_high_framework/include/wlan_mac_high.h

Last change on this file was 6117, checked in by chunter, 5 months ago

moved malloc initialization to common framework

File size: 14.9 KB
Line 
1/** @file wlan_mac_high.h
2 *  @brief Top-level WLAN MAC High Framework
3 *
4 *  This contains the top-level code for accessing the WLAN MAC High Framework.
5 *
6 *  @copyright Copyright 2014-2017, Mango Communications. All rights reserved.
7 *          Distributed under the Mango Communications Reference Design License
8 *                See LICENSE.txt included in the design archive or
9 *                at http://mangocomm.com/802.11/license
10 *
11 *  This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11)
12 */
13
14
15/*************************** Constant Definitions ****************************/
16#ifndef WLAN_MAC_HIGH_H_
17#define WLAN_MAC_HIGH_H_
18
19#include "wlan_mac_high_sw_config.h"
20#include "xil_types.h"
21#include "wlan_common_types.h"
22#include "wlan_high_types.h"
23
24// Forward declarations
25struct mac_header_80211_common;
26struct wlan_ipc_msg_t;
27struct beacon_txrx_configure_t;
28struct network_info_t;
29enum userio_input_mask_t;
30struct station_info_t;
31
32/********************************************************************
33 * Auxiliary (AUX) BRAM and DRAM (DDR) Memory Maps
34
35 * The 802.11 Reference Design hardware includes a 64 KB BRAM block named
36 * AUX BRAM. This block is mapped into the address space of CPU High
37 * and provides a low-latency memory block for data storage beyond the
38 * DLMB. The AUX BRAM is also accessible by the Ethernet DMAs and CDMA (the
39 * DMAs cannot access the MicroBlaze DLMB memory area).
40 *
41 * The reference code uses the AUX BRAM to store various data structures
42 * that provides references to larger blocks in DRAM. These data structures
43 * benefit from the low-latency access of the BRAM block.
44 *
45 * For example, the doubly-linked list of Tx Queue entries is stored in the
46 * AUX BRAM. Each list entry points to a dedicated 4KB buffer in DRAM. The C code
47 * can manage a queue with quick list operations in BRAM while the queued packets
48 * themselves are stored in the slower but *much* larger DRAM.
49 *
50 * The 64 KB AUX BRAM block is divided as follows:
51 *
52 * ***************************** AUX BRAM Map *********************************************
53 * Description                                            | Size
54 * -------------------------------------------------------------------------------------------------
55 * Tx Queue list entries (entry.data points to DRAM)      | 40960 B (TX_QUEUE_DL_ENTRY_MEM_SIZE)
56 * BSS Info list entries (entry.data points to DRAM)      |  2560 B (BSS_INFO_DL_ENTRY_MEM_SIZE)
57 * Station Info list entries (entry.data points to DRAM)  |  6656 B (STATION_INFO_DL_ENTRY_MEM_SIZE)
58 * Space for wlan_platform_ethernet use                   | 15360 B (ETH_MEM_SIZE)
59 * -------------------------------------------------------------------------------------------------
60 *
61 * DRAM is mapped into the address space of CPU High.
62 * This memory space is used as follows:
63 *
64 * ******************************* DRAM Map *********************************************************
65 * Description                      | Size
66 * --------------------------------------------------------------------------------------------------
67 * wlan_exp Eth buffers             |    1024 KB (WLAN_EXP_ETH_BUFFERS_SECTION_SIZE)
68 * Tx queue buffers                 |    1400 KB (TX_QUEUE_BUFFER_SIZE)
69 * BSS Info buffers                 |      27 KB (BSS_INFO_BUFFER_SIZE)
70 * Station Info buffers             |      69 KB (STATION_INFO_BUFFER_SIZE)
71 * User scratch space               |   10000 KB (USER_SCRATCH_SIZE)
72 * Event log                        | 1036056 KB (EVENT_LOG_SIZE)
73 * --------------------------------------------------------------------------------------------------
74 *
75 * Platform must define:
76 *  AUX_BRAM_BASEADDR - base address of AUX BRAM
77 *  AUX_BRAM_HIGHADDR - high address of AUX BRAM
78 *
79 *  DRAM_BASEADDR - base address of DRAM
80 *  DRAM_HIGHADDR - high address of DRAM
81 *
82 *  The per-section macros below are derived from these AUX_BRAM and DRAM address macros.
83 *
84 ************************************************************************************************/
85
86
87
88#define CALC_HIGH_ADDR(base, size)         ((base)+((size)-1))
89
90/********************************************************************
91 * wlan_exp and IP/UDP library Ethernet buffers
92 *
93 * The wlan_exp Ethernet handling code uses large buffers for constructing packets
94 * for transmission and for processing received packets. The IP/UDP library uses
95 * multiple buffers to pipeline Ethernet operations. The library also supports jumbo
96 * frames. As a result the wlan_exp and IP/UDP library Ethernet buffers are too large
97 * to store in on-chip BRAM. Instead the first 1MB of the DRAM is reserved for use
98 * by the wlan_exp Ethernet code.
99 *
100 * The linker script for CPU High *must* include a dedicated section allocated at the
101 * base of the DRAM address range. The macros below assume this section exist and
102 * are used to verify the wlan_exp and IP/UDP library code does not overflow the
103 * DRAM allocation.
104 *
105 ********************************************************************/
106#define WLAN_EXP_ETH_BUFFERS_SECTION_BASE   (platform_high_dev_info.dram_baseaddr)
107#define WLAN_EXP_ETH_BUFFERS_SECTION_SIZE   (1024 * 1024)
108#define WLAN_EXP_ETH_BUFFERS_SECTION_HIGH   CALC_HIGH_ADDR(WLAN_EXP_ETH_BUFFERS_SECTION_BASE, WLAN_EXP_ETH_BUFFERS_SECTION_SIZE)
109
110
111/********************************************************************
112 * TX Queue
113 *
114 * The Tx Queue consists of two pieces:
115 *     (1) dl_entry structs that live in the AUX BRAM
116 *     (2) Data buffers for the packets themselves than live in DRAM
117 *
118 * The definitions below reserve memory for these two pieces.  The default
119 * value of 40 kB do the dl_entry memory space was chosen. Because each dl_entry has a
120 * size of 12 bytes, this space allows for a potential of 3413 dl_entry structs describing
121 * Tx queue elements.
122 *
123 * As far as the actual payload space in DRAM, 14000 kB was chosen because this is enough
124 * to store each of the 3413 Tx queue elements. Each queue element points to a unique 4KB-sized
125 * buffer.
126 *
127 ********************************************************************/
128
129#define TX_QUEUE_DL_ENTRY_MEM_BASE         (platform_high_dev_info.aux_bram_baseaddr)
130#define TX_QUEUE_DL_ENTRY_MEM_SIZE         (40 * 1024)
131#define TX_QUEUE_DL_ENTRY_MEM_HIGH          CALC_HIGH_ADDR(TX_QUEUE_DL_ENTRY_MEM_BASE, TX_QUEUE_DL_ENTRY_MEM_SIZE)
132
133#define TX_QUEUE_BUFFER_BASE               (WLAN_EXP_ETH_BUFFERS_SECTION_HIGH + 1)
134#define TX_QUEUE_BUFFER_SIZE               (14000 * 1024)
135#define TX_QUEUE_BUFFER_HIGH                CALC_HIGH_ADDR(TX_QUEUE_BUFFER_BASE, TX_QUEUE_BUFFER_SIZE)
136
137
138
139/********************************************************************
140 * BSS Info
141 *
142 * The BSS Info storage consists of two pieces:
143 *     (1) dl_entry structs that live in the aux. BRAM and
144 *     (2) network_info_t buffers with the actual content that live in DRAM
145 *
146 ********************************************************************/
147#define BSS_INFO_DL_ENTRY_MEM_BASE         (TX_QUEUE_DL_ENTRY_MEM_BASE + TX_QUEUE_DL_ENTRY_MEM_SIZE)
148#define BSS_INFO_DL_ENTRY_MEM_SIZE         (2560)
149#define BSS_INFO_DL_ENTRY_MEM_HIGH          CALC_HIGH_ADDR(BSS_INFO_DL_ENTRY_MEM_BASE, BSS_INFO_DL_ENTRY_MEM_SIZE)
150
151#define BSS_INFO_BUFFER_BASE               (TX_QUEUE_BUFFER_HIGH + 1)
152#define BSS_INFO_BUFFER_SIZE               ((BSS_INFO_DL_ENTRY_MEM_SIZE/sizeof(dl_entry))*sizeof(network_info_t))
153#define BSS_INFO_BUFFER_HIGH                CALC_HIGH_ADDR(BSS_INFO_BUFFER_BASE, BSS_INFO_BUFFER_SIZE)
154
155
156/********************************************************************
157 * Station Info
158 *
159 * The Station Info storage consists of two pieces:
160 *     (1) dl_entry structs that live in the aux. BRAM and
161 *     (2) station_info_t buffers with the actual content that live in DRAM
162 *
163 ********************************************************************/
164#define STATION_INFO_DL_ENTRY_MEM_BASE     (BSS_INFO_DL_ENTRY_MEM_HIGH + 1)
165#define STATION_INFO_DL_ENTRY_MEM_SIZE     (6656)
166#define STATION_INFO_DL_ENTRY_MEM_NUM      (STATION_INFO_DL_ENTRY_MEM_SIZE/sizeof(dl_entry))
167#define STATION_INFO_DL_ENTRY_MEM_HIGH      CALC_HIGH_ADDR(STATION_INFO_DL_ENTRY_MEM_BASE, STATION_INFO_DL_ENTRY_MEM_SIZE)
168
169#define STATION_INFO_BUFFER_BASE          (BSS_INFO_BUFFER_HIGH + 1)
170#define STATION_INFO_BUFFER_SIZE          ((STATION_INFO_DL_ENTRY_MEM_SIZE/sizeof(dl_entry))*sizeof(station_info_t))
171#define STATION_INFO_BUFFER_HIGH           CALC_HIGH_ADDR(STATION_INFO_BUFFER_BASE, STATION_INFO_BUFFER_SIZE)
172
173/********************************************************************
174 * User Scratch Space
175 *
176 * We have set aside 10MB of space for users to use the DRAM in their applications.
177 * We do not use the below definitions in any part of the reference design.
178 *
179 ********************************************************************/
180#define USER_SCRATCH_BASE                  (STATION_INFO_BUFFER_HIGH + 1)
181#define USER_SCRATCH_SIZE                  (10000 * 1024)
182#define USER_SCRATCH_HIGH                   CALC_HIGH_ADDR(USER_SCRATCH_BASE, USER_SCRATCH_SIZE)
183
184
185/********************************************************************
186 * Event Log
187 *
188 * The remaining space in DRAM is used for the WLAN Experiment Framework event log. The above
189 * sections in DRAM are much smaller than the space set aside for the event log. In the current
190 * implementation, the event log is ~995 MB.
191 *
192 ********************************************************************/
193#define EVENT_LOG_BASE                     (USER_SCRATCH_HIGH + 1)
194#define EVENT_LOG_SIZE                     ((CALC_HIGH_ADDR(platform_high_dev_info.dram_baseaddr, platform_high_dev_info.dram_size)) - EVENT_LOG_BASE + 1) // log occupies all remaining DRAM
195#define EVENT_LOG_HIGH                      CALC_HIGH_ADDR(EVENT_LOG_BASE, EVENT_LOG_SIZE)
196
197//-----------------------------------------------
198// WLAN Constants
199//
200
201//-----------------------------------------------
202// Callback Return Flags
203//
204#define MAC_RX_CALLBACK_RETURN_FLAG_DUP                         0x00000001
205#define MAC_RX_CALLBACK_RETURN_FLAG_NO_COUNTS                   0x00000002
206#define MAC_RX_CALLBACK_RETURN_FLAG_NO_LOG_ENTRY                0x00000004
207
208
209
210/************************** Global Type Definitions **************************/
211
212typedef enum interrupt_state_t{
213    INTERRUPTS_DISABLED,
214    INTERRUPTS_ENABLED
215} interrupt_state_t;
216
217
218/******************** Global Structure/Enum Definitions **********************/
219
220/***************************** Global Constants ******************************/
221
222extern const  u8 bcast_addr[MAC_ADDR_LEN];
223extern const  u8 zero_addr[MAC_ADDR_LEN];
224
225
226/*************************** Function Prototypes *****************************/
227void               wlan_mac_high_init();
228
229int                wlan_mac_high_interrupt_init();
230void                         wlan_mac_high_uart_rx_callback(u8 rxByte);
231int                wlan_mac_high_interrupt_restore_state(interrupt_state_t new_interrupt_state);
232interrupt_state_t  wlan_mac_high_interrupt_stop();
233
234void               wlan_mac_high_userio_inputs_callback(u32 userio_state, enum userio_input_mask_t userio_delta);
235
236void               wlan_mac_high_set_press_pb_0_callback(function_ptr_t callback);
237void               wlan_mac_high_set_release_pb_0_callback(function_ptr_t callback);
238void               wlan_mac_high_set_press_pb_1_callback(function_ptr_t callback);
239void               wlan_mac_high_set_release_pb_1_callback(function_ptr_t callback);
240void               wlan_mac_high_set_press_pb_2_callback(function_ptr_t callback);
241void               wlan_mac_high_set_release_pb_2_callback(function_ptr_t callback);
242
243void               wlan_mac_high_set_uart_rx_callback(function_ptr_t callback);
244void               wlan_mac_high_set_mpdu_tx_high_done_callback(function_ptr_t callback);
245void               wlan_mac_high_set_mpdu_tx_low_done_callback(function_ptr_t callback);
246void               wlan_mac_high_set_beacon_tx_done_callback(function_ptr_t callback);
247void               wlan_mac_high_set_mpdu_rx_callback(function_ptr_t callback);
248void               wlan_mac_high_set_poll_tx_queues_callback(function_ptr_t callback);
249void               wlan_mac_high_set_mpdu_dequeue_callback(function_ptr_t callback);
250void               wlan_mac_high_set_cpu_low_reboot_callback(function_ptr_t callback);
251
252void*              wlan_mac_high_malloc(u32 size);
253void*              wlan_mac_high_calloc(u32 size);
254void*              wlan_mac_high_realloc(void* addr, u32 size);
255void               wlan_mac_high_free(void* addr);
256void               wlan_mac_high_display_mallinfo();
257
258int                wlan_mac_high_memory_test();
259int                wlan_mac_high_right_shift_test();
260
261int                wlan_mac_high_cdma_start_transfer(void* dest, void* src, u32 size);
262void               wlan_mac_high_cdma_finish_transfer();
263
264void               wlan_mac_high_mpdu_transmit(dl_entry* packet, int tx_pkt_buf);
265
266void               wlan_mac_high_setup_tx_header(struct mac_header_80211_common* header, u8* addr_1, u8* addr_3);
267
268void               wlan_mac_high_process_ipc_msg(struct wlan_ipc_msg_t* msg, u32* ipc_msg_from_low_payload);
269
270void               wlan_mac_high_set_srand(u32 seed);
271u8                 wlan_mac_high_bss_channel_spec_to_radio_chan(chan_spec_t chan_spec);
272void               wlan_mac_high_set_radio_channel(u32 mac_channel);
273void               wlan_mac_high_enable_mcast_buffering(u8 enable);
274
275void               wlan_mac_high_config_txrx_beacon(struct beacon_txrx_configure_t* beacon_txrx_configure);
276void               wlan_mac_high_set_rx_ant_mode(u8 ant_mode);
277void               wlan_mac_high_set_tx_ctrl_power(s8 pow);
278void               wlan_mac_high_set_radio_tx_power(s8 pow);
279void               wlan_mac_high_set_rx_filter_mode(u32 filter_mode);
280void               wlan_mac_high_set_dsss(u32 dsss_value);
281
282int                wlan_mac_high_write_low_mem(u32 num_words, u32* payload);
283int                wlan_mac_high_read_low_mem(u32 num_words, u32 baseaddr, u32* payload);
284int                wlan_mac_high_write_low_param(u32 num_words, u32* payload);
285
286void               wlan_mac_high_request_low_state();
287int                wlan_mac_high_is_cpu_low_initialized();
288int                wlan_mac_num_tx_pkt_buf_available(pkt_buf_group_t pkt_buf_group);
289int                wlan_mac_high_get_empty_tx_packet_buffer();
290u8                 wlan_mac_high_is_pkt_ltg(void* mac_payload, u16 length);
291
292int                wlan_mac_high_configure_beacon_tx_template(struct mac_header_80211_common* tx_header_common_ptr, struct network_info_t* network_info, tx_params_t* tx_params_ptr, u8 flags);
293int                wlan_mac_high_update_beacon_tx_params(tx_params_t* tx_params_ptr);
294tx_params_t        wlan_mac_sanitize_tx_params(struct station_info_t* station_info, tx_params_t* tx_params);
295
296
297
298
299// Common functions that must be implemented by users of the framework
300// TODO: Make these into callback. We should not require these implementations
301dl_list*     get_network_member_list();
302
303#endif /* WLAN_MAC_HIGH_H_ */
Note: See TracBrowser for help on using the repository browser.