blob: e9a564863127f4d76ab0791273708bedf0fa91d8 [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
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/*
Ivo van Doorn08992f72008-01-24 01:56:25 -080030 * skb_desc
31 * Descriptor information for the skb buffer
32 */
33struct 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
46static inline struct skb_desc* get_skb_desc(struct sk_buff *skb)
47{
48 return (struct skb_desc*)&skb->cb[0];
49}
50
51/*
Johannes Berg4150c572007-09-17 01:29:23 -040052 * rxdata_entry_desc
53 * Summary of information that has been read from the
54 * RX frame descriptor.
55 */
56struct 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
Ivo van Doorn95ea3622007-09-25 17:57:13 -070066 * Summary of information that should be written into the
67 * descriptor for sending a TX frame.
68 */
Johannes Berg4150c572007-09-17 01:29:23 -040069struct txdata_entry_desc {
Ivo van Doorn95ea3622007-09-25 17:57:13 -070070 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
Mattias Nissler2700f8b2007-10-27 13:43:49 +020077#define ENTRY_TXD_ACK 7
Ivo van Doorn95ea3622007-09-25 17:57:13 -070078
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 */
111struct 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;
Ivo van Doorn04267102008-01-06 23:39:25 +0100146
147 /*
148 * Entry identification number (index).
149 */
150 unsigned int entry_idx;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700151};
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 */
160struct 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 /*
Ivo van Doorn04267102008-01-06 23:39:25 +0100189 * Queue identification number:
190 * RX: 0
191 * TX: IEEE80211_TX_*
192 */
193 unsigned int queue_idx;
194
195 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700196 * 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 */
212static inline struct data_entry *rt2x00_get_data_entry(struct data_ring *ring)
213{
214 return &ring->entry[ring->index];
215}
216
217static 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 */
226static 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 */
234static 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
242static 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
251static 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
259static inline int rt2x00_ring_empty(struct data_ring *ring)
260{
261 return ring->stats.len == 0;
262}
263
264static inline int rt2x00_ring_full(struct data_ring *ring)
265{
266 return ring->stats.len == ring->stats.limit;
267}
268
269static 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 */
Ivo van Doorn4bd7c452008-01-24 00:48:03 -0800277static inline void rt2x00_desc_read(__le32 *desc,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700278 const u8 word, u32 *value)
279{
Ivo van Doorn4bd7c452008-01-24 00:48:03 -0800280 *value = le32_to_cpu(desc[word]);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700281}
282
Ivo van Doorn4bd7c452008-01-24 00:48:03 -0800283static inline void rt2x00_desc_write(__le32 *desc,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700284 const u8 word, const u32 value)
285{
Ivo van Doorn4bd7c452008-01-24 00:48:03 -0800286 desc[word] = cpu_to_le32(value);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700287}
288
289#endif /* RT2X00RING_H */