blob: 278f1a1ac92661a42f7d2cd22f9f0a49f60bbab8 [file] [log] [blame]
Ivo van Doorn181d6902008-02-05 16:42:23 -05001/*
2 Copyright (C) 2004 - 2008 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: rt2x00lib
23 Abstract: rt2x00 queue specific routines.
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28
29#include "rt2x00.h"
30#include "rt2x00lib.h"
31
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +020032struct sk_buff *rt2x00queue_alloc_skb(struct data_queue *queue)
Gertjan van Wingerde239c2492008-06-06 22:54:12 +020033{
34 struct sk_buff *skb;
35 unsigned int frame_size;
36 unsigned int reserved_size;
37
38 /*
39 * The frame size includes descriptor size, because the
40 * hardware directly receive the frame into the skbuffer.
41 */
42 frame_size = queue->data_size + queue->desc_size;
43
44 /*
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +020045 * Reserve a few bytes extra headroom to allow drivers some moving
46 * space (e.g. for alignment), while keeping the skb aligned.
Gertjan van Wingerde239c2492008-06-06 22:54:12 +020047 */
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +020048 reserved_size = 8;
Gertjan van Wingerde239c2492008-06-06 22:54:12 +020049
50 /*
51 * Allocate skbuffer.
52 */
53 skb = dev_alloc_skb(frame_size + reserved_size);
54 if (!skb)
55 return NULL;
56
57 skb_reserve(skb, reserved_size);
58 skb_put(skb, frame_size);
59
60 return skb;
61}
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +020062EXPORT_SYMBOL_GPL(rt2x00queue_alloc_skb);
63
64void rt2x00queue_free_skb(struct sk_buff *skb)
65{
66 dev_kfree_skb_any(skb);
67}
68EXPORT_SYMBOL_GPL(rt2x00queue_free_skb);
Gertjan van Wingerde239c2492008-06-06 22:54:12 +020069
Ivo van Doorn7050ec82008-05-10 13:46:13 +020070void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
Johannes Berge039fa42008-05-15 12:55:29 +020071 struct txentry_desc *txdesc)
Ivo van Doorn7050ec82008-05-10 13:46:13 +020072{
Johannes Berg2e92e6f2008-05-15 12:55:27 +020073 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
Johannes Berge039fa42008-05-15 12:55:29 +020074 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
Ivo van Doorn7050ec82008-05-10 13:46:13 +020075 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data;
Johannes Berg2e92e6f2008-05-15 12:55:27 +020076 struct ieee80211_rate *rate =
Johannes Berge039fa42008-05-15 12:55:29 +020077 ieee80211_get_tx_rate(rt2x00dev->hw, tx_info);
Ivo van Doorn7050ec82008-05-10 13:46:13 +020078 const struct rt2x00_rate *hwrate;
79 unsigned int data_length;
80 unsigned int duration;
81 unsigned int residual;
Ivo van Doorn7050ec82008-05-10 13:46:13 +020082
83 memset(txdesc, 0, sizeof(*txdesc));
84
85 /*
86 * Initialize information from queue
87 */
88 txdesc->queue = entry->queue->qid;
89 txdesc->cw_min = entry->queue->cw_min;
90 txdesc->cw_max = entry->queue->cw_max;
91 txdesc->aifs = entry->queue->aifs;
92
93 /* Data length should be extended with 4 bytes for CRC */
94 data_length = entry->skb->len + 4;
95
96 /*
Ivo van Doorn7050ec82008-05-10 13:46:13 +020097 * Check whether this frame is to be acked.
98 */
Johannes Berge039fa42008-05-15 12:55:29 +020099 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK))
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200100 __set_bit(ENTRY_TXD_ACK, &txdesc->flags);
101
102 /*
103 * Check if this is a RTS/CTS frame
104 */
Ivo van Doornac104462008-06-16 19:54:57 +0200105 if (ieee80211_is_rts(hdr->frame_control) ||
106 ieee80211_is_cts(hdr->frame_control)) {
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200107 __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
Ivo van Doornac104462008-06-16 19:54:57 +0200108 if (ieee80211_is_rts(hdr->frame_control))
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200109 __set_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags);
Johannes Berge039fa42008-05-15 12:55:29 +0200110 else
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200111 __set_bit(ENTRY_TXD_CTS_FRAME, &txdesc->flags);
Johannes Berge039fa42008-05-15 12:55:29 +0200112 if (tx_info->control.rts_cts_rate_idx >= 0)
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200113 rate =
Johannes Berge039fa42008-05-15 12:55:29 +0200114 ieee80211_get_rts_cts_rate(rt2x00dev->hw, tx_info);
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200115 }
116
117 /*
118 * Determine retry information.
119 */
Johannes Berge039fa42008-05-15 12:55:29 +0200120 txdesc->retry_limit = tx_info->control.retry_limit;
121 if (tx_info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT)
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200122 __set_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags);
123
124 /*
125 * Check if more fragments are pending
126 */
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700127 if (ieee80211_has_morefrags(hdr->frame_control)) {
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200128 __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
129 __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags);
130 }
131
132 /*
133 * Beacons and probe responses require the tsf timestamp
134 * to be inserted into the frame.
135 */
Ivo van Doornac104462008-06-16 19:54:57 +0200136 if (ieee80211_is_beacon(hdr->frame_control) ||
137 ieee80211_is_probe_resp(hdr->frame_control))
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200138 __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags);
139
140 /*
141 * Determine with what IFS priority this frame should be send.
142 * Set ifs to IFS_SIFS when the this is not the first fragment,
143 * or this fragment came after RTS/CTS.
144 */
145 if (test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags)) {
146 txdesc->ifs = IFS_SIFS;
Johannes Berge039fa42008-05-15 12:55:29 +0200147 } else if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200148 __set_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags);
149 txdesc->ifs = IFS_BACKOFF;
150 } else {
151 txdesc->ifs = IFS_SIFS;
152 }
153
154 /*
155 * PLCP setup
156 * Length calculation depends on OFDM/CCK rate.
157 */
158 hwrate = rt2x00_get_rate(rate->hw_value);
159 txdesc->signal = hwrate->plcp;
160 txdesc->service = 0x04;
161
162 if (hwrate->flags & DEV_RATE_OFDM) {
163 __set_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags);
164
165 txdesc->length_high = (data_length >> 6) & 0x3f;
166 txdesc->length_low = data_length & 0x3f;
167 } else {
168 /*
169 * Convert length to microseconds.
170 */
171 residual = get_duration_res(data_length, hwrate->bitrate);
172 duration = get_duration(data_length, hwrate->bitrate);
173
174 if (residual != 0) {
175 duration++;
176
177 /*
178 * Check if we need to set the Length Extension
179 */
180 if (hwrate->bitrate == 110 && residual <= 30)
181 txdesc->service |= 0x80;
182 }
183
184 txdesc->length_high = (duration >> 8) & 0xff;
185 txdesc->length_low = duration & 0xff;
186
187 /*
188 * When preamble is enabled we should set the
189 * preamble bit for the signal.
190 */
191 if (rt2x00_get_rate_preamble(rate->hw_value))
192 txdesc->signal |= 0x08;
193 }
194}
195EXPORT_SYMBOL_GPL(rt2x00queue_create_tx_descriptor);
196
197void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
198 struct txentry_desc *txdesc)
199{
Ivo van Doornb8697672008-06-06 22:53:14 +0200200 struct data_queue *queue = entry->queue;
201 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200202
203 rt2x00dev->ops->lib->write_tx_desc(rt2x00dev, entry->skb, txdesc);
204
205 /*
206 * All processing on the frame has been completed, this means
207 * it is now ready to be dumped to userspace through debugfs.
208 */
209 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TX, entry->skb);
210
211 /*
Ivo van Doornb8697672008-06-06 22:53:14 +0200212 * Check if we need to kick the queue, there are however a few rules
213 * 1) Don't kick beacon queue
214 * 2) Don't kick unless this is the last in frame in a burst.
215 * When the burst flag is set, this frame is always followed
216 * by another frame which in some way are related to eachother.
217 * This is true for fragments, RTS or CTS-to-self frames.
218 * 3) Rule 2 can be broken when the available entries
219 * in the queue are less then a certain threshold.
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200220 */
Ivo van Doornb8697672008-06-06 22:53:14 +0200221 if (entry->queue->qid == QID_BEACON)
222 return;
223
224 if (rt2x00queue_threshold(queue) ||
225 !test_bit(ENTRY_TXD_BURST, &txdesc->flags))
226 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, queue->qid);
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200227}
228EXPORT_SYMBOL_GPL(rt2x00queue_write_tx_descriptor);
229
Ivo van Doorn6db37862008-06-06 22:50:28 +0200230int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
231{
232 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
233 struct txentry_desc txdesc;
234
235 if (unlikely(rt2x00queue_full(queue)))
236 return -EINVAL;
237
238 if (__test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) {
239 ERROR(queue->rt2x00dev,
240 "Arrived at non-free entry in the non-full queue %d.\n"
241 "Please file bug report to %s.\n",
242 queue->qid, DRV_PROJECT);
243 return -EINVAL;
244 }
245
246 /*
247 * Copy all TX descriptor information into txdesc,
248 * after that we are free to use the skb->cb array
249 * for our information.
250 */
251 entry->skb = skb;
252 rt2x00queue_create_tx_descriptor(entry, &txdesc);
253
254 if (unlikely(queue->rt2x00dev->ops->lib->write_tx_data(entry))) {
255 __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
256 return -EIO;
257 }
258
259 __set_bit(ENTRY_DATA_PENDING, &entry->flags);
260
261 rt2x00queue_index_inc(queue, Q_INDEX);
262 rt2x00queue_write_tx_descriptor(entry, &txdesc);
263
264 return 0;
265}
266
Ivo van Doorn181d6902008-02-05 16:42:23 -0500267struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
Ivo van Doorne58c6ac2008-04-21 19:00:47 +0200268 const enum data_queue_qid queue)
Ivo van Doorn181d6902008-02-05 16:42:23 -0500269{
270 int atim = test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
271
Gertjan van Wingerde61448f82008-05-10 13:43:33 +0200272 if (queue < rt2x00dev->ops->tx_queues && rt2x00dev->tx)
Ivo van Doorn181d6902008-02-05 16:42:23 -0500273 return &rt2x00dev->tx[queue];
274
275 if (!rt2x00dev->bcn)
276 return NULL;
277
Ivo van Doorne58c6ac2008-04-21 19:00:47 +0200278 if (queue == QID_BEACON)
Ivo van Doorn181d6902008-02-05 16:42:23 -0500279 return &rt2x00dev->bcn[0];
Ivo van Doorne58c6ac2008-04-21 19:00:47 +0200280 else if (queue == QID_ATIM && atim)
Ivo van Doorn181d6902008-02-05 16:42:23 -0500281 return &rt2x00dev->bcn[1];
282
283 return NULL;
284}
285EXPORT_SYMBOL_GPL(rt2x00queue_get_queue);
286
287struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
288 enum queue_index index)
289{
290 struct queue_entry *entry;
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100291 unsigned long irqflags;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500292
293 if (unlikely(index >= Q_INDEX_MAX)) {
294 ERROR(queue->rt2x00dev,
295 "Entry requested from invalid index type (%d)\n", index);
296 return NULL;
297 }
298
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100299 spin_lock_irqsave(&queue->lock, irqflags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500300
301 entry = &queue->entries[queue->index[index]];
302
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100303 spin_unlock_irqrestore(&queue->lock, irqflags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500304
305 return entry;
306}
307EXPORT_SYMBOL_GPL(rt2x00queue_get_entry);
308
309void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index)
310{
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100311 unsigned long irqflags;
312
Ivo van Doorn181d6902008-02-05 16:42:23 -0500313 if (unlikely(index >= Q_INDEX_MAX)) {
314 ERROR(queue->rt2x00dev,
315 "Index change on invalid index type (%d)\n", index);
316 return;
317 }
318
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100319 spin_lock_irqsave(&queue->lock, irqflags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500320
321 queue->index[index]++;
322 if (queue->index[index] >= queue->limit)
323 queue->index[index] = 0;
324
Ivo van Doorn10b6b802008-02-03 15:55:21 +0100325 if (index == Q_INDEX) {
326 queue->length++;
327 } else if (index == Q_INDEX_DONE) {
328 queue->length--;
329 queue->count ++;
330 }
Ivo van Doorn181d6902008-02-05 16:42:23 -0500331
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100332 spin_unlock_irqrestore(&queue->lock, irqflags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500333}
334EXPORT_SYMBOL_GPL(rt2x00queue_index_inc);
335
336static void rt2x00queue_reset(struct data_queue *queue)
337{
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100338 unsigned long irqflags;
339
340 spin_lock_irqsave(&queue->lock, irqflags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500341
342 queue->count = 0;
343 queue->length = 0;
344 memset(queue->index, 0, sizeof(queue->index));
345
Ivo van Doorn5f46c4d2008-03-09 22:44:30 +0100346 spin_unlock_irqrestore(&queue->lock, irqflags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500347}
348
349void rt2x00queue_init_rx(struct rt2x00_dev *rt2x00dev)
350{
351 struct data_queue *queue = rt2x00dev->rx;
352 unsigned int i;
353
354 rt2x00queue_reset(queue);
355
356 if (!rt2x00dev->ops->lib->init_rxentry)
357 return;
358
359 for (i = 0; i < queue->limit; i++)
360 rt2x00dev->ops->lib->init_rxentry(rt2x00dev,
361 &queue->entries[i]);
362}
363
364void rt2x00queue_init_tx(struct rt2x00_dev *rt2x00dev)
365{
366 struct data_queue *queue;
367 unsigned int i;
368
369 txall_queue_for_each(rt2x00dev, queue) {
370 rt2x00queue_reset(queue);
371
372 if (!rt2x00dev->ops->lib->init_txentry)
373 continue;
374
375 for (i = 0; i < queue->limit; i++)
376 rt2x00dev->ops->lib->init_txentry(rt2x00dev,
377 &queue->entries[i]);
378 }
379}
380
381static int rt2x00queue_alloc_entries(struct data_queue *queue,
382 const struct data_queue_desc *qdesc)
383{
384 struct queue_entry *entries;
385 unsigned int entry_size;
386 unsigned int i;
387
388 rt2x00queue_reset(queue);
389
390 queue->limit = qdesc->entry_num;
Ivo van Doornb8697672008-06-06 22:53:14 +0200391 queue->threshold = DIV_ROUND_UP(qdesc->entry_num, 10);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500392 queue->data_size = qdesc->data_size;
393 queue->desc_size = qdesc->desc_size;
394
395 /*
396 * Allocate all queue entries.
397 */
398 entry_size = sizeof(*entries) + qdesc->priv_size;
399 entries = kzalloc(queue->limit * entry_size, GFP_KERNEL);
400 if (!entries)
401 return -ENOMEM;
402
403#define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \
Adam Baker231be4e2008-02-10 22:48:19 +0100404 ( ((char *)(__base)) + ((__limit) * (__esize)) + \
405 ((__index) * (__psize)) )
Ivo van Doorn181d6902008-02-05 16:42:23 -0500406
407 for (i = 0; i < queue->limit; i++) {
408 entries[i].flags = 0;
409 entries[i].queue = queue;
410 entries[i].skb = NULL;
411 entries[i].entry_idx = i;
412 entries[i].priv_data =
413 QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit,
414 sizeof(*entries), qdesc->priv_size);
415 }
416
417#undef QUEUE_ENTRY_PRIV_OFFSET
418
419 queue->entries = entries;
420
421 return 0;
422}
423
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +0200424static void rt2x00queue_free_skbs(struct data_queue *queue)
425{
426 unsigned int i;
427
428 if (!queue->entries)
429 return;
430
431 for (i = 0; i < queue->limit; i++) {
432 if (queue->entries[i].skb)
433 rt2x00queue_free_skb(queue->entries[i].skb);
434 }
435}
436
437static int rt2x00queue_alloc_skbs(struct data_queue *queue)
438{
439 unsigned int i;
440 struct sk_buff *skb;
441
442 for (i = 0; i < queue->limit; i++) {
443 skb = rt2x00queue_alloc_skb(queue);
444 if (!skb)
445 goto exit;
446
447 queue->entries[i].skb = skb;
448 }
449
450 return 0;
451
452exit:
453 rt2x00queue_free_skbs(queue);
454
455 return -ENOMEM;
456}
457
Ivo van Doorn181d6902008-02-05 16:42:23 -0500458int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
459{
460 struct data_queue *queue;
461 int status;
462
Ivo van Doorn181d6902008-02-05 16:42:23 -0500463 status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx);
464 if (status)
465 goto exit;
466
467 tx_queue_for_each(rt2x00dev, queue) {
468 status = rt2x00queue_alloc_entries(queue, rt2x00dev->ops->tx);
469 if (status)
470 goto exit;
471 }
472
473 status = rt2x00queue_alloc_entries(rt2x00dev->bcn, rt2x00dev->ops->bcn);
474 if (status)
475 goto exit;
476
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +0200477 if (test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags)) {
478 status = rt2x00queue_alloc_entries(&rt2x00dev->bcn[1],
479 rt2x00dev->ops->atim);
480 if (status)
481 goto exit;
482 }
Ivo van Doorn181d6902008-02-05 16:42:23 -0500483
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +0200484 status = rt2x00queue_alloc_skbs(rt2x00dev->rx);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500485 if (status)
486 goto exit;
487
488 return 0;
489
490exit:
491 ERROR(rt2x00dev, "Queue entries allocation failed.\n");
492
493 rt2x00queue_uninitialize(rt2x00dev);
494
495 return status;
496}
497
498void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev)
499{
500 struct data_queue *queue;
501
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +0200502 rt2x00queue_free_skbs(rt2x00dev->rx);
503
Ivo van Doorn181d6902008-02-05 16:42:23 -0500504 queue_for_each(rt2x00dev, queue) {
505 kfree(queue->entries);
506 queue->entries = NULL;
507 }
508}
509
Ivo van Doorn8f539272008-02-10 22:51:41 +0100510static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev,
511 struct data_queue *queue, enum data_queue_qid qid)
512{
513 spin_lock_init(&queue->lock);
514
515 queue->rt2x00dev = rt2x00dev;
516 queue->qid = qid;
517 queue->aifs = 2;
518 queue->cw_min = 5;
519 queue->cw_max = 10;
520}
521
Ivo van Doorn181d6902008-02-05 16:42:23 -0500522int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev)
523{
524 struct data_queue *queue;
525 enum data_queue_qid qid;
526 unsigned int req_atim =
527 !!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
528
529 /*
530 * We need the following queues:
531 * RX: 1
Gertjan van Wingerde61448f82008-05-10 13:43:33 +0200532 * TX: ops->tx_queues
Ivo van Doorn181d6902008-02-05 16:42:23 -0500533 * Beacon: 1
534 * Atim: 1 (if required)
535 */
Gertjan van Wingerde61448f82008-05-10 13:43:33 +0200536 rt2x00dev->data_queues = 2 + rt2x00dev->ops->tx_queues + req_atim;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500537
538 queue = kzalloc(rt2x00dev->data_queues * sizeof(*queue), GFP_KERNEL);
539 if (!queue) {
540 ERROR(rt2x00dev, "Queue allocation failed.\n");
541 return -ENOMEM;
542 }
543
544 /*
545 * Initialize pointers
546 */
547 rt2x00dev->rx = queue;
548 rt2x00dev->tx = &queue[1];
Gertjan van Wingerde61448f82008-05-10 13:43:33 +0200549 rt2x00dev->bcn = &queue[1 + rt2x00dev->ops->tx_queues];
Ivo van Doorn181d6902008-02-05 16:42:23 -0500550
551 /*
552 * Initialize queue parameters.
553 * RX: qid = QID_RX
554 * TX: qid = QID_AC_BE + index
555 * TX: cw_min: 2^5 = 32.
556 * TX: cw_max: 2^10 = 1024.
Ivo van Doorn565a0192008-06-03 20:29:05 +0200557 * BCN: qid = QID_BEACON
558 * ATIM: qid = QID_ATIM
Ivo van Doorn181d6902008-02-05 16:42:23 -0500559 */
Ivo van Doorn8f539272008-02-10 22:51:41 +0100560 rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX);
561
Ivo van Doorn181d6902008-02-05 16:42:23 -0500562 qid = QID_AC_BE;
Ivo van Doorn8f539272008-02-10 22:51:41 +0100563 tx_queue_for_each(rt2x00dev, queue)
564 rt2x00queue_init(rt2x00dev, queue, qid++);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500565
Ivo van Doorn565a0192008-06-03 20:29:05 +0200566 rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[0], QID_BEACON);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500567 if (req_atim)
Ivo van Doorn565a0192008-06-03 20:29:05 +0200568 rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[1], QID_ATIM);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500569
570 return 0;
571}
572
573void rt2x00queue_free(struct rt2x00_dev *rt2x00dev)
574{
575 kfree(rt2x00dev->rx);
576 rt2x00dev->rx = NULL;
577 rt2x00dev->tx = NULL;
578 rt2x00dev->bcn = NULL;
579}