1 | /** @file wlan_mac_queue.h |
---|
2 | * @brief Transmit Queue Framework |
---|
3 | * |
---|
4 | * This contains code for accessing the transmit queue. |
---|
5 | * |
---|
6 | * @copyright Copyright 2013-2019, 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 | /*************************** Constant Definitions ****************************/ |
---|
15 | #ifndef WLAN_MAC_QUEUE_H_ |
---|
16 | #define WLAN_MAC_QUEUE_H_ |
---|
17 | |
---|
18 | /***************************** Include Files *********************************/ |
---|
19 | |
---|
20 | #include "wlan_mac_high_sw_config.h" |
---|
21 | #include "xil_types.h" |
---|
22 | #include "wlan_common_types.h" |
---|
23 | #include "wlan_high_types.h" |
---|
24 | #include "wlan_mac_802_11_defs.h" |
---|
25 | |
---|
26 | //Forward declarations |
---|
27 | struct station_info_t; |
---|
28 | |
---|
29 | //----------------------------------------------- |
---|
30 | // Queue defines |
---|
31 | // |
---|
32 | #define QUEUE_ELEMENT_SIZE 0x1000 // 4KB |
---|
33 | |
---|
34 | typedef struct __attribute__((__packed__)) pyld_queue_hdr_t{ |
---|
35 | u32 buffer_length; // Number of bytes until next pyld_queue_hdr_t. Currently fixed at QUEUE_ELEMENT_SIZE |
---|
36 | //---- 4-bytes ---- |
---|
37 | dl_entry* dle; |
---|
38 | //---- 8-bytes ---- |
---|
39 | } pyld_queue_hdr_t; |
---|
40 | |
---|
41 | ASSERT_TYPE_SIZE(pyld_queue_hdr_t, 8); |
---|
42 | |
---|
43 | // Base stencil for every Pkt Queue Buffer |
---|
44 | typedef struct __attribute__((__packed__)) pkt_queue_buffer_t{ |
---|
45 | pyld_queue_hdr_t pyld_queue_hdr; |
---|
46 | u8 reserved[QUEUE_ELEMENT_SIZE - sizeof(pyld_queue_hdr_t)]; |
---|
47 | } pkt_queue_buffer_t; |
---|
48 | |
---|
49 | ASSERT_TYPE_SIZE(pkt_queue_buffer_t, QUEUE_ELEMENT_SIZE); |
---|
50 | |
---|
51 | // Stencil to use Pkt Queue Buffer for Tx Queue Buffer |
---|
52 | typedef struct __attribute__((__packed__)) tx_queue_buffer_t{ |
---|
53 | pyld_queue_hdr_t pyld_queue_hdr; |
---|
54 | //---- 8-bytes ---- |
---|
55 | u16 length; |
---|
56 | u16 seg0_len; |
---|
57 | //---- 12-bytes ---- |
---|
58 | u16 seg1_len; |
---|
59 | u8 seg1_offset; |
---|
60 | u8 reserved0; |
---|
61 | //---- 16-bytes ---- |
---|
62 | struct station_info_t* station_info; |
---|
63 | //---- 20-bytes ---- |
---|
64 | tx_queue_details_t tx_queue_details; |
---|
65 | //---- 32-bytes ---- |
---|
66 | u16 flags; |
---|
67 | u8 reserved1[6]; |
---|
68 | //---- 40-bytes ---- |
---|
69 | u8 pkt[QUEUE_ELEMENT_SIZE - 40]; |
---|
70 | } tx_80211_queue_buffer_t; |
---|
71 | |
---|
72 | ASSERT_TYPE_SIZE(tx_80211_queue_buffer_t, QUEUE_ELEMENT_SIZE); |
---|
73 | |
---|
74 | // Stencil to use Pkt Queue Buffer as Rx Eth Queue Buffer |
---|
75 | typedef struct __attribute__((__packed__)) eth_rx_queue_buffer_t{ |
---|
76 | pyld_queue_hdr_t pyld_queue_hdr; |
---|
77 | //---- 8-bytes ---- |
---|
78 | u16 length; |
---|
79 | u8 reserved[ 30 ]; |
---|
80 | //---- 40-bytes ---- |
---|
81 | u8 encap_eth_header_placeholder[ sizeof(mac_header_80211) + sizeof(llc_header_t) ]; |
---|
82 | //---- 72-bytes ---- |
---|
83 | u8 pkt[QUEUE_ELEMENT_SIZE - 72]; |
---|
84 | } eth_rx_queue_buffer_t; |
---|
85 | |
---|
86 | ASSERT_TYPE_SIZE(eth_rx_queue_buffer_t, QUEUE_ELEMENT_SIZE); |
---|
87 | ASSERT_FIELD_ALIGNMENT(eth_rx_queue_buffer_t, pkt, 8); //ensure 8-byte alignment on Ethernet frame for DMA |
---|
88 | |
---|
89 | // Stencil to use Pkt Queue Buffer as Rx wlan_exp Queue Buffer |
---|
90 | typedef struct __attribute__((__packed__)) wlan_exp_eth_rx_queue_buffer_t{ |
---|
91 | pyld_queue_hdr_t pyld_queue_hdr; |
---|
92 | //---- 8-bytes ---- |
---|
93 | u16 length; |
---|
94 | u8 reserved0[ 6 ]; |
---|
95 | //---- 16-bytes ---- |
---|
96 | sockaddr_in_t rx_from; |
---|
97 | u8 reserved1[ 40 ]; |
---|
98 | //---- 72-bytes ---- |
---|
99 | u8 pkt[QUEUE_ELEMENT_SIZE - 72]; |
---|
100 | } wlan_exp_eth_rx_queue_buffer_t; |
---|
101 | |
---|
102 | ASSERT_TYPE_SIZE(wlan_exp_eth_rx_queue_buffer_t, QUEUE_ELEMENT_SIZE); |
---|
103 | ASSERT_FIELD_ALIGNMENT(wlan_exp_eth_rx_queue_buffer_t, pkt, 8); //ensure 8-byte alignment on Ethernet frame for DMA |
---|
104 | |
---|
105 | // Stencil to use Pkt Queue Buffer as Tx Eth Queue Buffer |
---|
106 | typedef struct __attribute__((__packed__)) eth_tx_queue_buffer_t{ |
---|
107 | pyld_queue_hdr_t pyld_queue_hdr; |
---|
108 | //---- 8-bytes ---- |
---|
109 | u16 seg0_len; |
---|
110 | u16 seg1_len; |
---|
111 | //---- 12-bytes ---- |
---|
112 | u8* seg1_addr; |
---|
113 | //---- 16-bytes --- |
---|
114 | u8 seg0[QUEUE_ELEMENT_SIZE - 16]; |
---|
115 | } eth_tx_queue_buffer_t; |
---|
116 | |
---|
117 | ASSERT_TYPE_SIZE(eth_tx_queue_buffer_t, QUEUE_ELEMENT_SIZE); |
---|
118 | ASSERT_FIELD_ALIGNMENT(eth_tx_queue_buffer_t, seg0, 8); //ensure 8-byte alignment on Ethernet frame for DMA |
---|
119 | |
---|
120 | // The packet queue buffer types require certain field overlaps. The below macros enforce the necessary |
---|
121 | // overlap alignment |
---|
122 | ASSERT_FIELD_OVERLAP_ALIGNMENT(eth_rx_queue_buffer_t, pkt, wlan_exp_eth_rx_queue_buffer_t, pkt); |
---|
123 | ASSERT_FIELD_OVERLAP_ALIGNMENT(eth_rx_queue_buffer_t, encap_eth_header_placeholder, tx_80211_queue_buffer_t, pkt); |
---|
124 | |
---|
125 | |
---|
126 | #define TX_80211_QUEUE_BUFFER_FLAGS_FILL_TIMESTAMP 0x0001 |
---|
127 | #define TX_80211_QUEUE_BUFFER_FLAGS_FILL_DURATION 0x0002 |
---|
128 | #define TX_80211_QUEUE_BUFFER_FLAGS_FILL_UNIQ_SEQ 0x0004 |
---|
129 | #define TX_80211_QUEUE_BUFFER_FLAGS_BYPASS_RECOVERY 0x0008 |
---|
130 | #define TX_80211_QUEUE_BUFFER_FLAGS_TYPE_CTS 0x0010 |
---|
131 | #define TX_80211_QUEUE_BUFFER_FLAGS_TYPE_ACK 0x0020 |
---|
132 | |
---|
133 | /*************************** Function Prototypes *****************************/ |
---|
134 | |
---|
135 | void queue_init(); |
---|
136 | int queue_open(function_ptr_t queue_state_change_callback, u32 callback_arg, u32 max_len); |
---|
137 | int queue_set_max_len(int queue_id, u32 max_len); |
---|
138 | int queue_close(int queue_id); |
---|
139 | |
---|
140 | pkt_queue_buffer_t* queue_retrieve_buffer_from_index(u16 queue_id, u32 idx); |
---|
141 | |
---|
142 | #define queue_enqueue(a,b) enqueue_tail((a),(b)) |
---|
143 | #define queue_dequeue(a) dequeue_head(a) |
---|
144 | int enqueue_tail(u16 queue_id, dl_entry* queue_entry); |
---|
145 | int enqueue_head(u16 queue_id, dl_entry* queue_entry); |
---|
146 | dl_entry* dequeue_head(u16 queue_id); |
---|
147 | |
---|
148 | dl_entry* queue_checkout(); |
---|
149 | void queue_checkin(dl_entry* queue_entry); |
---|
150 | |
---|
151 | int queue_checkout_list(dl_list* new_list, u16 num_queue_entry); |
---|
152 | int queue_checkin_list(dl_list * list); |
---|
153 | |
---|
154 | u32 queue_num_free(); |
---|
155 | u32 queue_length(u16 queue_id); |
---|
156 | u8 queue_enqueue_allowed(int queue_id); |
---|
157 | u32 queue_total_size(); |
---|
158 | |
---|
159 | void queue_purge(u16 queue_id); |
---|
160 | |
---|
161 | #endif /* WLAN_MAC_QUEUE_H_ */ |
---|