2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
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.
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.
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.
23 Abstract: rt2x00 queue specific routines.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include "rt2x00lib.h"
32 struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
33 const unsigned int queue)
35 int atim = test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
37 if (queue < rt2x00dev->hw->queues && rt2x00dev->tx)
38 return &rt2x00dev->tx[queue];
43 if (queue == RT2X00_BCN_QUEUE_BEACON)
44 return &rt2x00dev->bcn[0];
45 else if (queue == RT2X00_BCN_QUEUE_ATIM && atim)
46 return &rt2x00dev->bcn[1];
50 EXPORT_SYMBOL_GPL(rt2x00queue_get_queue);
52 struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
53 enum queue_index index)
55 struct queue_entry *entry;
57 if (unlikely(index >= Q_INDEX_MAX)) {
58 ERROR(queue->rt2x00dev,
59 "Entry requested from invalid index type (%d)\n", index);
63 spin_lock(&queue->lock);
65 entry = &queue->entries[queue->index[index]];
67 spin_unlock(&queue->lock);
71 EXPORT_SYMBOL_GPL(rt2x00queue_get_entry);
73 void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index)
75 if (unlikely(index >= Q_INDEX_MAX)) {
76 ERROR(queue->rt2x00dev,
77 "Index change on invalid index type (%d)\n", index);
81 spin_lock(&queue->lock);
83 queue->index[index]++;
84 if (queue->index[index] >= queue->limit)
85 queue->index[index] = 0;
87 if (index == Q_INDEX) {
89 } else if (index == Q_INDEX_DONE) {
94 spin_unlock(&queue->lock);
96 EXPORT_SYMBOL_GPL(rt2x00queue_index_inc);
98 static void rt2x00queue_reset(struct data_queue *queue)
100 spin_lock(&queue->lock);
104 memset(queue->index, 0, sizeof(queue->index));
106 spin_unlock(&queue->lock);
109 void rt2x00queue_init_rx(struct rt2x00_dev *rt2x00dev)
111 struct data_queue *queue = rt2x00dev->rx;
114 rt2x00queue_reset(queue);
116 if (!rt2x00dev->ops->lib->init_rxentry)
119 for (i = 0; i < queue->limit; i++)
120 rt2x00dev->ops->lib->init_rxentry(rt2x00dev,
124 void rt2x00queue_init_tx(struct rt2x00_dev *rt2x00dev)
126 struct data_queue *queue;
129 txall_queue_for_each(rt2x00dev, queue) {
130 rt2x00queue_reset(queue);
132 if (!rt2x00dev->ops->lib->init_txentry)
135 for (i = 0; i < queue->limit; i++)
136 rt2x00dev->ops->lib->init_txentry(rt2x00dev,
141 static int rt2x00queue_alloc_entries(struct data_queue *queue,
142 const struct data_queue_desc *qdesc)
144 struct queue_entry *entries;
145 unsigned int entry_size;
148 rt2x00queue_reset(queue);
150 queue->limit = qdesc->entry_num;
151 queue->data_size = qdesc->data_size;
152 queue->desc_size = qdesc->desc_size;
155 * Allocate all queue entries.
157 entry_size = sizeof(*entries) + qdesc->priv_size;
158 entries = kzalloc(queue->limit * entry_size, GFP_KERNEL);
162 #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \
163 ( ((char *)(__base)) + ((__limit) * (__esize)) + \
164 ((__index) * (__psize)) )
166 for (i = 0; i < queue->limit; i++) {
167 entries[i].flags = 0;
168 entries[i].queue = queue;
169 entries[i].skb = NULL;
170 entries[i].entry_idx = i;
171 entries[i].priv_data =
172 QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit,
173 sizeof(*entries), qdesc->priv_size);
176 #undef QUEUE_ENTRY_PRIV_OFFSET
178 queue->entries = entries;
183 int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
185 struct data_queue *queue;
189 status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx);
193 tx_queue_for_each(rt2x00dev, queue) {
194 status = rt2x00queue_alloc_entries(queue, rt2x00dev->ops->tx);
199 status = rt2x00queue_alloc_entries(rt2x00dev->bcn, rt2x00dev->ops->bcn);
203 if (!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags))
206 status = rt2x00queue_alloc_entries(&rt2x00dev->bcn[1],
207 rt2x00dev->ops->atim);
214 ERROR(rt2x00dev, "Queue entries allocation failed.\n");
216 rt2x00queue_uninitialize(rt2x00dev);
221 void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev)
223 struct data_queue *queue;
225 queue_for_each(rt2x00dev, queue) {
226 kfree(queue->entries);
227 queue->entries = NULL;
231 static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev,
232 struct data_queue *queue, enum data_queue_qid qid)
234 spin_lock_init(&queue->lock);
236 queue->rt2x00dev = rt2x00dev;
243 int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev)
245 struct data_queue *queue;
246 enum data_queue_qid qid;
247 unsigned int req_atim =
248 !!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
251 * We need the following queues:
255 * Atim: 1 (if required)
257 rt2x00dev->data_queues = 2 + rt2x00dev->hw->queues + req_atim;
259 queue = kzalloc(rt2x00dev->data_queues * sizeof(*queue), GFP_KERNEL);
261 ERROR(rt2x00dev, "Queue allocation failed.\n");
266 * Initialize pointers
268 rt2x00dev->rx = queue;
269 rt2x00dev->tx = &queue[1];
270 rt2x00dev->bcn = &queue[1 + rt2x00dev->hw->queues];
273 * Initialize queue parameters.
275 * TX: qid = QID_AC_BE + index
276 * TX: cw_min: 2^5 = 32.
277 * TX: cw_max: 2^10 = 1024.
278 * BCN & Atim: qid = QID_MGMT
280 rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX);
283 tx_queue_for_each(rt2x00dev, queue)
284 rt2x00queue_init(rt2x00dev, queue, qid++);
286 rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[0], QID_MGMT);
288 rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[1], QID_MGMT);
293 void rt2x00queue_free(struct rt2x00_dev *rt2x00dev)
295 kfree(rt2x00dev->rx);
296 rt2x00dev->rx = NULL;
297 rt2x00dev->tx = NULL;
298 rt2x00dev->bcn = NULL;