]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wireless/rt2x00/rt2x00ring.h
rt2x00: Store queue idx and entry idx in data_ring and data_entry
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / rt2x00 / rt2x00ring.h
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  * skb_desc
31  * Descriptor information for the skb buffer
32  */
33 struct skb_desc {
34         unsigned int frame_type;
35
36         unsigned int desc_len;
37         unsigned int data_len;
38
39         void *desc;
40         void *data;
41
42         struct data_ring *ring;
43         struct data_entry *entry;
44 };
45
46 static inline struct skb_desc* get_skb_desc(struct sk_buff *skb)
47 {
48         return (struct skb_desc*)&skb->cb[0];
49 }
50
51 /*
52  * rxdata_entry_desc
53  * Summary of information that has been read from the
54  * RX frame descriptor.
55  */
56 struct rxdata_entry_desc {
57         int signal;
58         int rssi;
59         int ofdm;
60         int size;
61         int flags;
62 };
63
64 /*
65  * txdata_entry_desc
66  * Summary of information that should be written into the
67  * descriptor for sending a TX frame.
68  */
69 struct txdata_entry_desc {
70         unsigned long flags;
71 #define ENTRY_TXDONE            1
72 #define ENTRY_TXD_RTS_FRAME     2
73 #define ENTRY_TXD_OFDM_RATE     3
74 #define ENTRY_TXD_MORE_FRAG     4
75 #define ENTRY_TXD_REQ_TIMESTAMP 5
76 #define ENTRY_TXD_BURST         6
77 #define ENTRY_TXD_ACK           7
78
79 /*
80  * Queue ID. ID's 0-4 are data TX rings
81  */
82         int queue;
83 #define QUEUE_MGMT              13
84 #define QUEUE_RX                14
85 #define QUEUE_OTHER             15
86
87         /*
88          * PLCP values.
89          */
90         u16 length_high;
91         u16 length_low;
92         u16 signal;
93         u16 service;
94
95         /*
96          * Timing information
97          */
98         int aifs;
99         int ifs;
100         int cw_min;
101         int cw_max;
102 };
103
104 /*
105  * data_entry
106  * The data ring is a list of data entries.
107  * Each entry holds a reference to the descriptor
108  * and the data buffer. For TX rings the reference to the
109  * sk_buff of the packet being transmitted is also stored here.
110  */
111 struct data_entry {
112         /*
113          * Status flags
114          */
115         unsigned long flags;
116 #define ENTRY_OWNER_NIC         1
117
118         /*
119          * Ring we belong to.
120          */
121         struct data_ring *ring;
122
123         /*
124          * sk_buff for the packet which is being transmitted
125          * in this entry (Only used with TX related rings).
126          */
127         struct sk_buff *skb;
128
129         /*
130          * Store a ieee80211_tx_status structure in each
131          * ring entry, this will optimize the txdone
132          * handler.
133          */
134         struct ieee80211_tx_status tx_status;
135
136         /*
137          * private pointer specific to driver.
138          */
139         void *priv;
140
141         /*
142          * Data address for this entry.
143          */
144         void *data_addr;
145         dma_addr_t data_dma;
146
147         /*
148          * Entry identification number (index).
149          */
150         unsigned int entry_idx;
151 };
152
153 /*
154  * data_ring
155  * Data rings are used by the device to send and receive packets.
156  * The data_addr is the base address of the data memory.
157  * To determine at which point in the ring we are,
158  * have to use the rt2x00_ring_index_*() functions.
159  */
160 struct data_ring {
161         /*
162          * Pointer to main rt2x00dev structure where this
163          * ring belongs to.
164          */
165         struct rt2x00_dev *rt2x00dev;
166
167         /*
168          * Base address for the device specific data entries.
169          */
170         struct data_entry *entry;
171
172         /*
173          * TX queue statistic info.
174          */
175         struct ieee80211_tx_queue_stats_data stats;
176
177         /*
178          * TX Queue parameters.
179          */
180         struct ieee80211_tx_queue_params tx_params;
181
182         /*
183          * Base address for data ring.
184          */
185         dma_addr_t data_dma;
186         void *data_addr;
187
188         /*
189          * Queue identification number:
190          * RX: 0
191          * TX: IEEE80211_TX_*
192          */
193         unsigned int queue_idx;
194
195         /*
196          * Index variables.
197          */
198         u16 index;
199         u16 index_done;
200
201         /*
202          * Size of packet and descriptor in bytes.
203          */
204         u16 data_size;
205         u16 desc_size;
206 };
207
208 /*
209  * Handlers to determine the address of the current device specific
210  * data entry, where either index or index_done points to.
211  */
212 static inline struct data_entry *rt2x00_get_data_entry(struct data_ring *ring)
213 {
214         return &ring->entry[ring->index];
215 }
216
217 static inline struct data_entry *rt2x00_get_data_entry_done(struct data_ring
218                                                             *ring)
219 {
220         return &ring->entry[ring->index_done];
221 }
222
223 /*
224  * Total ring memory
225  */
226 static inline int rt2x00_get_ring_size(struct data_ring *ring)
227 {
228         return ring->stats.limit * (ring->desc_size + ring->data_size);
229 }
230
231 /*
232  * Ring index manipulation functions.
233  */
234 static inline void rt2x00_ring_index_inc(struct data_ring *ring)
235 {
236         ring->index++;
237         if (ring->index >= ring->stats.limit)
238                 ring->index = 0;
239         ring->stats.len++;
240 }
241
242 static inline void rt2x00_ring_index_done_inc(struct data_ring *ring)
243 {
244         ring->index_done++;
245         if (ring->index_done >= ring->stats.limit)
246                 ring->index_done = 0;
247         ring->stats.len--;
248         ring->stats.count++;
249 }
250
251 static inline void rt2x00_ring_index_clear(struct data_ring *ring)
252 {
253         ring->index = 0;
254         ring->index_done = 0;
255         ring->stats.len = 0;
256         ring->stats.count = 0;
257 }
258
259 static inline int rt2x00_ring_empty(struct data_ring *ring)
260 {
261         return ring->stats.len == 0;
262 }
263
264 static inline int rt2x00_ring_full(struct data_ring *ring)
265 {
266         return ring->stats.len == ring->stats.limit;
267 }
268
269 static inline int rt2x00_ring_free(struct data_ring *ring)
270 {
271         return ring->stats.limit - ring->stats.len;
272 }
273
274 /*
275  * TX/RX Descriptor access functions.
276  */
277 static inline void rt2x00_desc_read(__le32 *desc,
278                                     const u8 word, u32 *value)
279 {
280         *value = le32_to_cpu(desc[word]);
281 }
282
283 static inline void rt2x00_desc_write(__le32 *desc,
284                                      const u8 word, const u32 value)
285 {
286         desc[word] = cpu_to_le32(value);
287 }
288
289 #endif /* RT2X00RING_H */