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