[PATCH] mac80211: revamp interface and filter configuration
[linux-block.git] / drivers / net / wireless / rt2x00 / rt2x00ring.h
CommitLineData
95ea3627
ID
1/*
2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2x00
23 Abstract: rt2x00 ring datastructures and routines
24 */
25
26#ifndef RT2X00RING_H
27#define RT2X00RING_H
28
29/*
30 * data_desc
31 * Each data entry also contains a descriptor which is used by the
32 * device to determine what should be done with the packet and
33 * what the current status is.
34 * This structure is greatly simplified, but the descriptors
35 * are basically a list of little endian 32 bit values.
36 * Make the array by default 1 word big, this will allow us
37 * to use sizeof() correctly.
38 */
39struct data_desc {
40 __le32 word[1];
41};
42
43/*
4150c572
JB
44 * rxdata_entry_desc
45 * Summary of information that has been read from the
46 * RX frame descriptor.
47 */
48struct rxdata_entry_desc {
49 int signal;
50 int rssi;
51 int ofdm;
52 int size;
53 int flags;
54};
55
56/*
57 * txdata_entry_desc
95ea3627
ID
58 * Summary of information that should be written into the
59 * descriptor for sending a TX frame.
60 */
4150c572 61struct txdata_entry_desc {
95ea3627
ID
62 unsigned long flags;
63#define ENTRY_TXDONE 1
64#define ENTRY_TXD_RTS_FRAME 2
65#define ENTRY_TXD_OFDM_RATE 3
66#define ENTRY_TXD_MORE_FRAG 4
67#define ENTRY_TXD_REQ_TIMESTAMP 5
68#define ENTRY_TXD_BURST 6
69
70/*
71 * Queue ID. ID's 0-4 are data TX rings
72 */
73 int queue;
74#define QUEUE_MGMT 13
75#define QUEUE_RX 14
76#define QUEUE_OTHER 15
77
78 /*
79 * PLCP values.
80 */
81 u16 length_high;
82 u16 length_low;
83 u16 signal;
84 u16 service;
85
86 /*
87 * Timing information
88 */
89 int aifs;
90 int ifs;
91 int cw_min;
92 int cw_max;
93};
94
95/*
96 * data_entry
97 * The data ring is a list of data entries.
98 * Each entry holds a reference to the descriptor
99 * and the data buffer. For TX rings the reference to the
100 * sk_buff of the packet being transmitted is also stored here.
101 */
102struct data_entry {
103 /*
104 * Status flags
105 */
106 unsigned long flags;
107#define ENTRY_OWNER_NIC 1
108
109 /*
110 * Ring we belong to.
111 */
112 struct data_ring *ring;
113
114 /*
115 * sk_buff for the packet which is being transmitted
116 * in this entry (Only used with TX related rings).
117 */
118 struct sk_buff *skb;
119
120 /*
121 * Store a ieee80211_tx_status structure in each
122 * ring entry, this will optimize the txdone
123 * handler.
124 */
125 struct ieee80211_tx_status tx_status;
126
127 /*
128 * private pointer specific to driver.
129 */
130 void *priv;
131
132 /*
133 * Data address for this entry.
134 */
135 void *data_addr;
136 dma_addr_t data_dma;
137};
138
139/*
140 * data_ring
141 * Data rings are used by the device to send and receive packets.
142 * The data_addr is the base address of the data memory.
143 * To determine at which point in the ring we are,
144 * have to use the rt2x00_ring_index_*() functions.
145 */
146struct data_ring {
147 /*
148 * Pointer to main rt2x00dev structure where this
149 * ring belongs to.
150 */
151 struct rt2x00_dev *rt2x00dev;
152
153 /*
154 * Base address for the device specific data entries.
155 */
156 struct data_entry *entry;
157
158 /*
159 * TX queue statistic info.
160 */
161 struct ieee80211_tx_queue_stats_data stats;
162
163 /*
164 * TX Queue parameters.
165 */
166 struct ieee80211_tx_queue_params tx_params;
167
168 /*
169 * Base address for data ring.
170 */
171 dma_addr_t data_dma;
172 void *data_addr;
173
174 /*
175 * Index variables.
176 */
177 u16 index;
178 u16 index_done;
179
180 /*
181 * Size of packet and descriptor in bytes.
182 */
183 u16 data_size;
184 u16 desc_size;
185};
186
187/*
188 * Handlers to determine the address of the current device specific
189 * data entry, where either index or index_done points to.
190 */
191static inline struct data_entry *rt2x00_get_data_entry(struct data_ring *ring)
192{
193 return &ring->entry[ring->index];
194}
195
196static inline struct data_entry *rt2x00_get_data_entry_done(struct data_ring
197 *ring)
198{
199 return &ring->entry[ring->index_done];
200}
201
202/*
203 * Total ring memory
204 */
205static inline int rt2x00_get_ring_size(struct data_ring *ring)
206{
207 return ring->stats.limit * (ring->desc_size + ring->data_size);
208}
209
210/*
211 * Ring index manipulation functions.
212 */
213static inline void rt2x00_ring_index_inc(struct data_ring *ring)
214{
215 ring->index++;
216 if (ring->index >= ring->stats.limit)
217 ring->index = 0;
218 ring->stats.len++;
219}
220
221static inline void rt2x00_ring_index_done_inc(struct data_ring *ring)
222{
223 ring->index_done++;
224 if (ring->index_done >= ring->stats.limit)
225 ring->index_done = 0;
226 ring->stats.len--;
227 ring->stats.count++;
228}
229
230static inline void rt2x00_ring_index_clear(struct data_ring *ring)
231{
232 ring->index = 0;
233 ring->index_done = 0;
234 ring->stats.len = 0;
235 ring->stats.count = 0;
236}
237
238static inline int rt2x00_ring_empty(struct data_ring *ring)
239{
240 return ring->stats.len == 0;
241}
242
243static inline int rt2x00_ring_full(struct data_ring *ring)
244{
245 return ring->stats.len == ring->stats.limit;
246}
247
248static inline int rt2x00_ring_free(struct data_ring *ring)
249{
250 return ring->stats.limit - ring->stats.len;
251}
252
253/*
254 * TX/RX Descriptor access functions.
255 */
256static inline void rt2x00_desc_read(struct data_desc *desc,
257 const u8 word, u32 *value)
258{
259 *value = le32_to_cpu(desc->word[word]);
260}
261
262static inline void rt2x00_desc_write(struct data_desc *desc,
263 const u8 word, const u32 value)
264{
265 desc->word[word] = cpu_to_le32(value);
266}
267
268#endif /* RT2X00RING_H */