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 enum data_queue_qid 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 == QID_BEACON)
44 return &rt2x00dev->bcn[0];
45 else if (queue == QID_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;
56 unsigned long irqflags;
58 if (unlikely(index >= Q_INDEX_MAX)) {
59 ERROR(queue->rt2x00dev,
60 "Entry requested from invalid index type (%d)\n", index);
64 spin_lock_irqsave(&queue->lock, irqflags);
66 entry = &queue->entries[queue->index[index]];
68 spin_unlock_irqrestore(&queue->lock, irqflags);
72 EXPORT_SYMBOL_GPL(rt2x00queue_get_entry);
74 void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index)
76 unsigned long irqflags;
78 if (unlikely(index >= Q_INDEX_MAX)) {
79 ERROR(queue->rt2x00dev,
80 "Index change on invalid index type (%d)\n", index);
84 spin_lock_irqsave(&queue->lock, irqflags);
86 queue->index[index]++;
87 if (queue->index[index] >= queue->limit)
88 queue->index[index] = 0;
90 if (index == Q_INDEX) {
92 } else if (index == Q_INDEX_DONE) {
97 spin_unlock_irqrestore(&queue->lock, irqflags);
99 EXPORT_SYMBOL_GPL(rt2x00queue_index_inc);
101 static void rt2x00queue_reset(struct data_queue *queue)
103 unsigned long irqflags;
105 spin_lock_irqsave(&queue->lock, irqflags);
109 memset(queue->index, 0, sizeof(queue->index));
111 spin_unlock_irqrestore(&queue->lock, irqflags);
114 void rt2x00queue_init_rx(struct rt2x00_dev *rt2x00dev)
116 struct data_queue *queue = rt2x00dev->rx;
119 rt2x00queue_reset(queue);
121 if (!rt2x00dev->ops->lib->init_rxentry)
124 for (i = 0; i < queue->limit; i++)
125 rt2x00dev->ops->lib->init_rxentry(rt2x00dev,
129 void rt2x00queue_init_tx(struct rt2x00_dev *rt2x00dev)
131 struct data_queue *queue;
134 txall_queue_for_each(rt2x00dev, queue) {
135 rt2x00queue_reset(queue);
137 if (!rt2x00dev->ops->lib->init_txentry)
140 for (i = 0; i < queue->limit; i++)
141 rt2x00dev->ops->lib->init_txentry(rt2x00dev,
146 static int rt2x00queue_alloc_entries(struct data_queue *queue,
147 const struct data_queue_desc *qdesc)
149 struct queue_entry *entries;
150 unsigned int entry_size;
153 rt2x00queue_reset(queue);
155 queue->limit = qdesc->entry_num;
156 queue->data_size = qdesc->data_size;
157 queue->desc_size = qdesc->desc_size;
160 * Allocate all queue entries.
162 entry_size = sizeof(*entries) + qdesc->priv_size;
163 entries = kzalloc(queue->limit * entry_size, GFP_KERNEL);
167 #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \
168 ( ((char *)(__base)) + ((__limit) * (__esize)) + \
169 ((__index) * (__psize)) )
171 for (i = 0; i < queue->limit; i++) {
172 entries[i].flags = 0;
173 entries[i].queue = queue;
174 entries[i].skb = NULL;
175 entries[i].entry_idx = i;
176 entries[i].priv_data =
177 QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit,
178 sizeof(*entries), qdesc->priv_size);
181 #undef QUEUE_ENTRY_PRIV_OFFSET
183 queue->entries = entries;
188 int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
190 struct data_queue *queue;
194 status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx);
198 tx_queue_for_each(rt2x00dev, queue) {
199 status = rt2x00queue_alloc_entries(queue, rt2x00dev->ops->tx);
204 status = rt2x00queue_alloc_entries(rt2x00dev->bcn, rt2x00dev->ops->bcn);
208 if (!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags))
211 status = rt2x00queue_alloc_entries(&rt2x00dev->bcn[1],
212 rt2x00dev->ops->atim);
219 ERROR(rt2x00dev, "Queue entries allocation failed.\n");
221 rt2x00queue_uninitialize(rt2x00dev);
226 void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev)
228 struct data_queue *queue;
230 queue_for_each(rt2x00dev, queue) {
231 kfree(queue->entries);
232 queue->entries = NULL;
236 static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev,
237 struct data_queue *queue, enum data_queue_qid qid)
239 spin_lock_init(&queue->lock);
241 queue->rt2x00dev = rt2x00dev;
248 int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev)
250 struct data_queue *queue;
251 enum data_queue_qid qid;
252 unsigned int req_atim =
253 !!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
256 * We need the following queues:
260 * Atim: 1 (if required)
262 rt2x00dev->data_queues = 2 + rt2x00dev->hw->queues + req_atim;
264 queue = kzalloc(rt2x00dev->data_queues * sizeof(*queue), GFP_KERNEL);
266 ERROR(rt2x00dev, "Queue allocation failed.\n");
271 * Initialize pointers
273 rt2x00dev->rx = queue;
274 rt2x00dev->tx = &queue[1];
275 rt2x00dev->bcn = &queue[1 + rt2x00dev->hw->queues];
278 * Initialize queue parameters.
280 * TX: qid = QID_AC_BE + index
281 * TX: cw_min: 2^5 = 32.
282 * TX: cw_max: 2^10 = 1024.
283 * BCN & Atim: qid = QID_MGMT
285 rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX);
288 tx_queue_for_each(rt2x00dev, queue)
289 rt2x00queue_init(rt2x00dev, queue, qid++);
291 rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[0], QID_MGMT);
293 rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[1], QID_MGMT);
298 void rt2x00queue_free(struct rt2x00_dev *rt2x00dev)
300 kfree(rt2x00dev->rx);
301 rt2x00dev->rx = NULL;
302 rt2x00dev->tx = NULL;
303 rt2x00dev->bcn = NULL;