GNU Linux-libre 4.9.318-gnu1
[releases.git] / drivers / net / wireless / ralink / rt2x00 / rt2x00queue.c
1 /*
2         Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
3         Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
4         Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
5         <http://rt2x00.serialmonkey.com>
6
7         This program is free software; you can redistribute it and/or modify
8         it under the terms of the GNU General Public License as published by
9         the Free Software Foundation; either version 2 of the License, or
10         (at your option) any later version.
11
12         This program is distributed in the hope that it will be useful,
13         but WITHOUT ANY WARRANTY; without even the implied warranty of
14         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15         GNU General Public License for more details.
16
17         You should have received a copy of the GNU General Public License
18         along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 /*
22         Module: rt2x00lib
23         Abstract: rt2x00 queue specific routines.
24  */
25
26 #include <linux/slab.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/dma-mapping.h>
30
31 #include "rt2x00.h"
32 #include "rt2x00lib.h"
33
34 struct sk_buff *rt2x00queue_alloc_rxskb(struct queue_entry *entry, gfp_t gfp)
35 {
36         struct data_queue *queue = entry->queue;
37         struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
38         struct sk_buff *skb;
39         struct skb_frame_desc *skbdesc;
40         unsigned int frame_size;
41         unsigned int head_size = 0;
42         unsigned int tail_size = 0;
43
44         /*
45          * The frame size includes descriptor size, because the
46          * hardware directly receive the frame into the skbuffer.
47          */
48         frame_size = queue->data_size + queue->desc_size + queue->winfo_size;
49
50         /*
51          * The payload should be aligned to a 4-byte boundary,
52          * this means we need at least 3 bytes for moving the frame
53          * into the correct offset.
54          */
55         head_size = 4;
56
57         /*
58          * For IV/EIV/ICV assembly we must make sure there is
59          * at least 8 bytes bytes available in headroom for IV/EIV
60          * and 8 bytes for ICV data as tailroon.
61          */
62         if (rt2x00_has_cap_hw_crypto(rt2x00dev)) {
63                 head_size += 8;
64                 tail_size += 8;
65         }
66
67         /*
68          * Allocate skbuffer.
69          */
70         skb = __dev_alloc_skb(frame_size + head_size + tail_size, gfp);
71         if (!skb)
72                 return NULL;
73
74         /*
75          * Make sure we not have a frame with the requested bytes
76          * available in the head and tail.
77          */
78         skb_reserve(skb, head_size);
79         skb_put(skb, frame_size);
80
81         /*
82          * Populate skbdesc.
83          */
84         skbdesc = get_skb_frame_desc(skb);
85         memset(skbdesc, 0, sizeof(*skbdesc));
86         skbdesc->entry = entry;
87
88         if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_DMA)) {
89                 dma_addr_t skb_dma;
90
91                 skb_dma = dma_map_single(rt2x00dev->dev, skb->data, skb->len,
92                                          DMA_FROM_DEVICE);
93                 if (unlikely(dma_mapping_error(rt2x00dev->dev, skb_dma))) {
94                         dev_kfree_skb_any(skb);
95                         return NULL;
96                 }
97
98                 skbdesc->skb_dma = skb_dma;
99                 skbdesc->flags |= SKBDESC_DMA_MAPPED_RX;
100         }
101
102         return skb;
103 }
104
105 int rt2x00queue_map_txskb(struct queue_entry *entry)
106 {
107         struct device *dev = entry->queue->rt2x00dev->dev;
108         struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
109
110         skbdesc->skb_dma =
111             dma_map_single(dev, entry->skb->data, entry->skb->len, DMA_TO_DEVICE);
112
113         if (unlikely(dma_mapping_error(dev, skbdesc->skb_dma)))
114                 return -ENOMEM;
115
116         skbdesc->flags |= SKBDESC_DMA_MAPPED_TX;
117         return 0;
118 }
119 EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb);
120
121 void rt2x00queue_unmap_skb(struct queue_entry *entry)
122 {
123         struct device *dev = entry->queue->rt2x00dev->dev;
124         struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
125
126         if (skbdesc->flags & SKBDESC_DMA_MAPPED_RX) {
127                 dma_unmap_single(dev, skbdesc->skb_dma, entry->skb->len,
128                                  DMA_FROM_DEVICE);
129                 skbdesc->flags &= ~SKBDESC_DMA_MAPPED_RX;
130         } else if (skbdesc->flags & SKBDESC_DMA_MAPPED_TX) {
131                 dma_unmap_single(dev, skbdesc->skb_dma, entry->skb->len,
132                                  DMA_TO_DEVICE);
133                 skbdesc->flags &= ~SKBDESC_DMA_MAPPED_TX;
134         }
135 }
136 EXPORT_SYMBOL_GPL(rt2x00queue_unmap_skb);
137
138 void rt2x00queue_free_skb(struct queue_entry *entry)
139 {
140         if (!entry->skb)
141                 return;
142
143         rt2x00queue_unmap_skb(entry);
144         dev_kfree_skb_any(entry->skb);
145         entry->skb = NULL;
146 }
147
148 void rt2x00queue_align_frame(struct sk_buff *skb)
149 {
150         unsigned int frame_length = skb->len;
151         unsigned int align = ALIGN_SIZE(skb, 0);
152
153         if (!align)
154                 return;
155
156         skb_push(skb, align);
157         memmove(skb->data, skb->data + align, frame_length);
158         skb_trim(skb, frame_length);
159 }
160
161 /*
162  * H/W needs L2 padding between the header and the paylod if header size
163  * is not 4 bytes aligned.
164  */
165 void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int hdr_len)
166 {
167         unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
168
169         if (!l2pad)
170                 return;
171
172         skb_push(skb, l2pad);
173         memmove(skb->data, skb->data + l2pad, hdr_len);
174 }
175
176 void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int hdr_len)
177 {
178         unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
179
180         if (!l2pad)
181                 return;
182
183         memmove(skb->data + l2pad, skb->data, hdr_len);
184         skb_pull(skb, l2pad);
185 }
186
187 static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
188                                                  struct sk_buff *skb,
189                                                  struct txentry_desc *txdesc)
190 {
191         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
192         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
193         struct rt2x00_intf *intf = vif_to_intf(tx_info->control.vif);
194         u16 seqno;
195
196         if (!(tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ))
197                 return;
198
199         __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags);
200
201         if (!rt2x00_has_cap_flag(rt2x00dev, REQUIRE_SW_SEQNO)) {
202                 /*
203                  * rt2800 has a H/W (or F/W) bug, device incorrectly increase
204                  * seqno on retransmitted data (non-QOS) and management frames.
205                  * To workaround the problem let's generate seqno in software.
206                  * Except for beacons which are transmitted periodically by H/W
207                  * hence hardware has to assign seqno for them.
208                  */
209                 if (ieee80211_is_beacon(hdr->frame_control)) {
210                         __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags);
211                         /* H/W will generate sequence number */
212                         return;
213                 }
214
215                 __clear_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags);
216         }
217
218         /*
219          * The hardware is not able to insert a sequence number. Assign a
220          * software generated one here.
221          *
222          * This is wrong because beacons are not getting sequence
223          * numbers assigned properly.
224          *
225          * A secondary problem exists for drivers that cannot toggle
226          * sequence counting per-frame, since those will override the
227          * sequence counter given by mac80211.
228          */
229         if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
230                 seqno = atomic_add_return(0x10, &intf->seqno);
231         else
232                 seqno = atomic_read(&intf->seqno);
233
234         hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
235         hdr->seq_ctrl |= cpu_to_le16(seqno);
236 }
237
238 static void rt2x00queue_create_tx_descriptor_plcp(struct rt2x00_dev *rt2x00dev,
239                                                   struct sk_buff *skb,
240                                                   struct txentry_desc *txdesc,
241                                                   const struct rt2x00_rate *hwrate)
242 {
243         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
244         struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
245         unsigned int data_length;
246         unsigned int duration;
247         unsigned int residual;
248
249         /*
250          * Determine with what IFS priority this frame should be send.
251          * Set ifs to IFS_SIFS when the this is not the first fragment,
252          * or this fragment came after RTS/CTS.
253          */
254         if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
255                 txdesc->u.plcp.ifs = IFS_BACKOFF;
256         else
257                 txdesc->u.plcp.ifs = IFS_SIFS;
258
259         /* Data length + CRC + Crypto overhead (IV/EIV/ICV/MIC) */
260         data_length = skb->len + 4;
261         data_length += rt2x00crypto_tx_overhead(rt2x00dev, skb);
262
263         /*
264          * PLCP setup
265          * Length calculation depends on OFDM/CCK rate.
266          */
267         txdesc->u.plcp.signal = hwrate->plcp;
268         txdesc->u.plcp.service = 0x04;
269
270         if (hwrate->flags & DEV_RATE_OFDM) {
271                 txdesc->u.plcp.length_high = (data_length >> 6) & 0x3f;
272                 txdesc->u.plcp.length_low = data_length & 0x3f;
273         } else {
274                 /*
275                  * Convert length to microseconds.
276                  */
277                 residual = GET_DURATION_RES(data_length, hwrate->bitrate);
278                 duration = GET_DURATION(data_length, hwrate->bitrate);
279
280                 if (residual != 0) {
281                         duration++;
282
283                         /*
284                          * Check if we need to set the Length Extension
285                          */
286                         if (hwrate->bitrate == 110 && residual <= 30)
287                                 txdesc->u.plcp.service |= 0x80;
288                 }
289
290                 txdesc->u.plcp.length_high = (duration >> 8) & 0xff;
291                 txdesc->u.plcp.length_low = duration & 0xff;
292
293                 /*
294                  * When preamble is enabled we should set the
295                  * preamble bit for the signal.
296                  */
297                 if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
298                         txdesc->u.plcp.signal |= 0x08;
299         }
300 }
301
302 static void rt2x00queue_create_tx_descriptor_ht(struct rt2x00_dev *rt2x00dev,
303                                                 struct sk_buff *skb,
304                                                 struct txentry_desc *txdesc,
305                                                 struct ieee80211_sta *sta,
306                                                 const struct rt2x00_rate *hwrate)
307 {
308         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
309         struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
310         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
311         struct rt2x00_sta *sta_priv = NULL;
312
313         if (sta) {
314                 txdesc->u.ht.mpdu_density =
315                     sta->ht_cap.ampdu_density;
316
317                 sta_priv = sta_to_rt2x00_sta(sta);
318                 txdesc->u.ht.wcid = sta_priv->wcid;
319         }
320
321         /*
322          * If IEEE80211_TX_RC_MCS is set txrate->idx just contains the
323          * mcs rate to be used
324          */
325         if (txrate->flags & IEEE80211_TX_RC_MCS) {
326                 txdesc->u.ht.mcs = txrate->idx;
327
328                 /*
329                  * MIMO PS should be set to 1 for STA's using dynamic SM PS
330                  * when using more then one tx stream (>MCS7).
331                  */
332                 if (sta && txdesc->u.ht.mcs > 7 &&
333                     sta->smps_mode == IEEE80211_SMPS_DYNAMIC)
334                         __set_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags);
335         } else {
336                 txdesc->u.ht.mcs = rt2x00_get_rate_mcs(hwrate->mcs);
337                 if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
338                         txdesc->u.ht.mcs |= 0x08;
339         }
340
341         if (test_bit(CONFIG_HT_DISABLED, &rt2x00dev->flags)) {
342                 if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT))
343                         txdesc->u.ht.txop = TXOP_SIFS;
344                 else
345                         txdesc->u.ht.txop = TXOP_BACKOFF;
346
347                 /* Left zero on all other settings. */
348                 return;
349         }
350
351         txdesc->u.ht.ba_size = 7;       /* FIXME: What value is needed? */
352
353         /*
354          * Only one STBC stream is supported for now.
355          */
356         if (tx_info->flags & IEEE80211_TX_CTL_STBC)
357                 txdesc->u.ht.stbc = 1;
358
359         /*
360          * This frame is eligible for an AMPDU, however, don't aggregate
361          * frames that are intended to probe a specific tx rate.
362          */
363         if (tx_info->flags & IEEE80211_TX_CTL_AMPDU &&
364             !(tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE))
365                 __set_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags);
366
367         /*
368          * Set 40Mhz mode if necessary (for legacy rates this will
369          * duplicate the frame to both channels).
370          */
371         if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH ||
372             txrate->flags & IEEE80211_TX_RC_DUP_DATA)
373                 __set_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags);
374         if (txrate->flags & IEEE80211_TX_RC_SHORT_GI)
375                 __set_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags);
376
377         /*
378          * Determine IFS values
379          * - Use TXOP_BACKOFF for management frames except beacons
380          * - Use TXOP_SIFS for fragment bursts
381          * - Use TXOP_HTTXOP for everything else
382          *
383          * Note: rt2800 devices won't use CTS protection (if used)
384          * for frames not transmitted with TXOP_HTTXOP
385          */
386         if (ieee80211_is_mgmt(hdr->frame_control) &&
387             !ieee80211_is_beacon(hdr->frame_control))
388                 txdesc->u.ht.txop = TXOP_BACKOFF;
389         else if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT))
390                 txdesc->u.ht.txop = TXOP_SIFS;
391         else
392                 txdesc->u.ht.txop = TXOP_HTTXOP;
393 }
394
395 static void rt2x00queue_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
396                                              struct sk_buff *skb,
397                                              struct txentry_desc *txdesc,
398                                              struct ieee80211_sta *sta)
399 {
400         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
401         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
402         struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
403         struct ieee80211_rate *rate;
404         const struct rt2x00_rate *hwrate = NULL;
405
406         memset(txdesc, 0, sizeof(*txdesc));
407
408         /*
409          * Header and frame information.
410          */
411         txdesc->length = skb->len;
412         txdesc->header_length = ieee80211_get_hdrlen_from_skb(skb);
413
414         /*
415          * Check whether this frame is to be acked.
416          */
417         if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK))
418                 __set_bit(ENTRY_TXD_ACK, &txdesc->flags);
419
420         /*
421          * Check if this is a RTS/CTS frame
422          */
423         if (ieee80211_is_rts(hdr->frame_control) ||
424             ieee80211_is_cts(hdr->frame_control)) {
425                 __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
426                 if (ieee80211_is_rts(hdr->frame_control))
427                         __set_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags);
428                 else
429                         __set_bit(ENTRY_TXD_CTS_FRAME, &txdesc->flags);
430                 if (tx_info->control.rts_cts_rate_idx >= 0)
431                         rate =
432                             ieee80211_get_rts_cts_rate(rt2x00dev->hw, tx_info);
433         }
434
435         /*
436          * Determine retry information.
437          */
438         txdesc->retry_limit = tx_info->control.rates[0].count - 1;
439         if (txdesc->retry_limit >= rt2x00dev->long_retry)
440                 __set_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags);
441
442         /*
443          * Check if more fragments are pending
444          */
445         if (ieee80211_has_morefrags(hdr->frame_control)) {
446                 __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
447                 __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags);
448         }
449
450         /*
451          * Check if more frames (!= fragments) are pending
452          */
453         if (tx_info->flags & IEEE80211_TX_CTL_MORE_FRAMES)
454                 __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
455
456         /*
457          * Beacons and probe responses require the tsf timestamp
458          * to be inserted into the frame.
459          */
460         if (ieee80211_is_beacon(hdr->frame_control) ||
461             ieee80211_is_probe_resp(hdr->frame_control))
462                 __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags);
463
464         if ((tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) &&
465             !test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags))
466                 __set_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags);
467
468         /*
469          * Determine rate modulation.
470          */
471         if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
472                 txdesc->rate_mode = RATE_MODE_HT_GREENFIELD;
473         else if (txrate->flags & IEEE80211_TX_RC_MCS)
474                 txdesc->rate_mode = RATE_MODE_HT_MIX;
475         else {
476                 rate = ieee80211_get_tx_rate(rt2x00dev->hw, tx_info);
477                 hwrate = rt2x00_get_rate(rate->hw_value);
478                 if (hwrate->flags & DEV_RATE_OFDM)
479                         txdesc->rate_mode = RATE_MODE_OFDM;
480                 else
481                         txdesc->rate_mode = RATE_MODE_CCK;
482         }
483
484         /*
485          * Apply TX descriptor handling by components
486          */
487         rt2x00crypto_create_tx_descriptor(rt2x00dev, skb, txdesc);
488         rt2x00queue_create_tx_descriptor_seq(rt2x00dev, skb, txdesc);
489
490         if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_HT_TX_DESC))
491                 rt2x00queue_create_tx_descriptor_ht(rt2x00dev, skb, txdesc,
492                                                    sta, hwrate);
493         else
494                 rt2x00queue_create_tx_descriptor_plcp(rt2x00dev, skb, txdesc,
495                                                       hwrate);
496 }
497
498 static int rt2x00queue_write_tx_data(struct queue_entry *entry,
499                                      struct txentry_desc *txdesc)
500 {
501         struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
502
503         /*
504          * This should not happen, we already checked the entry
505          * was ours. When the hardware disagrees there has been
506          * a queue corruption!
507          */
508         if (unlikely(rt2x00dev->ops->lib->get_entry_state &&
509                      rt2x00dev->ops->lib->get_entry_state(entry))) {
510                 rt2x00_err(rt2x00dev,
511                            "Corrupt queue %d, accessing entry which is not ours\n"
512                            "Please file bug report to %s\n",
513                            entry->queue->qid, DRV_PROJECT);
514                 return -EINVAL;
515         }
516
517         /*
518          * Add the requested extra tx headroom in front of the skb.
519          */
520         skb_push(entry->skb, rt2x00dev->extra_tx_headroom);
521         memset(entry->skb->data, 0, rt2x00dev->extra_tx_headroom);
522
523         /*
524          * Call the driver's write_tx_data function, if it exists.
525          */
526         if (rt2x00dev->ops->lib->write_tx_data)
527                 rt2x00dev->ops->lib->write_tx_data(entry, txdesc);
528
529         /*
530          * Map the skb to DMA.
531          */
532         if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_DMA) &&
533             rt2x00queue_map_txskb(entry))
534                 return -ENOMEM;
535
536         return 0;
537 }
538
539 static void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
540                                             struct txentry_desc *txdesc)
541 {
542         struct data_queue *queue = entry->queue;
543
544         queue->rt2x00dev->ops->lib->write_tx_desc(entry, txdesc);
545
546         /*
547          * All processing on the frame has been completed, this means
548          * it is now ready to be dumped to userspace through debugfs.
549          */
550         rt2x00debug_dump_frame(queue->rt2x00dev, DUMP_FRAME_TX, entry->skb);
551 }
552
553 static void rt2x00queue_kick_tx_queue(struct data_queue *queue,
554                                       struct txentry_desc *txdesc)
555 {
556         /*
557          * Check if we need to kick the queue, there are however a few rules
558          *      1) Don't kick unless this is the last in frame in a burst.
559          *         When the burst flag is set, this frame is always followed
560          *         by another frame which in some way are related to eachother.
561          *         This is true for fragments, RTS or CTS-to-self frames.
562          *      2) Rule 1 can be broken when the available entries
563          *         in the queue are less then a certain threshold.
564          */
565         if (rt2x00queue_threshold(queue) ||
566             !test_bit(ENTRY_TXD_BURST, &txdesc->flags))
567                 queue->rt2x00dev->ops->lib->kick_queue(queue);
568 }
569
570 static void rt2x00queue_bar_check(struct queue_entry *entry)
571 {
572         struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
573         struct ieee80211_bar *bar = (void *) (entry->skb->data +
574                                     rt2x00dev->extra_tx_headroom);
575         struct rt2x00_bar_list_entry *bar_entry;
576
577         if (likely(!ieee80211_is_back_req(bar->frame_control)))
578                 return;
579
580         bar_entry = kmalloc(sizeof(*bar_entry), GFP_ATOMIC);
581
582         /*
583          * If the alloc fails we still send the BAR out but just don't track
584          * it in our bar list. And as a result we will report it to mac80211
585          * back as failed.
586          */
587         if (!bar_entry)
588                 return;
589
590         bar_entry->entry = entry;
591         bar_entry->block_acked = 0;
592
593         /*
594          * Copy the relevant parts of the 802.11 BAR into out check list
595          * such that we can use RCU for less-overhead in the RX path since
596          * sending BARs and processing the according BlockAck should be
597          * the exception.
598          */
599         memcpy(bar_entry->ra, bar->ra, sizeof(bar->ra));
600         memcpy(bar_entry->ta, bar->ta, sizeof(bar->ta));
601         bar_entry->control = bar->control;
602         bar_entry->start_seq_num = bar->start_seq_num;
603
604         /*
605          * Insert BAR into our BAR check list.
606          */
607         spin_lock_bh(&rt2x00dev->bar_list_lock);
608         list_add_tail_rcu(&bar_entry->list, &rt2x00dev->bar_list);
609         spin_unlock_bh(&rt2x00dev->bar_list_lock);
610 }
611
612 int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
613                                struct ieee80211_sta *sta, bool local)
614 {
615         struct ieee80211_tx_info *tx_info;
616         struct queue_entry *entry;
617         struct txentry_desc txdesc;
618         struct skb_frame_desc *skbdesc;
619         u8 rate_idx, rate_flags;
620         int ret = 0;
621
622         /*
623          * Copy all TX descriptor information into txdesc,
624          * after that we are free to use the skb->cb array
625          * for our information.
626          */
627         rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, sta);
628
629         /*
630          * All information is retrieved from the skb->cb array,
631          * now we should claim ownership of the driver part of that
632          * array, preserving the bitrate index and flags.
633          */
634         tx_info = IEEE80211_SKB_CB(skb);
635         rate_idx = tx_info->control.rates[0].idx;
636         rate_flags = tx_info->control.rates[0].flags;
637         skbdesc = get_skb_frame_desc(skb);
638         memset(skbdesc, 0, sizeof(*skbdesc));
639         skbdesc->tx_rate_idx = rate_idx;
640         skbdesc->tx_rate_flags = rate_flags;
641
642         if (local)
643                 skbdesc->flags |= SKBDESC_NOT_MAC80211;
644
645         /*
646          * When hardware encryption is supported, and this frame
647          * is to be encrypted, we should strip the IV/EIV data from
648          * the frame so we can provide it to the driver separately.
649          */
650         if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) &&
651             !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) {
652                 if (rt2x00_has_cap_flag(queue->rt2x00dev, REQUIRE_COPY_IV))
653                         rt2x00crypto_tx_copy_iv(skb, &txdesc);
654                 else
655                         rt2x00crypto_tx_remove_iv(skb, &txdesc);
656         }
657
658         /*
659          * When DMA allocation is required we should guarantee to the
660          * driver that the DMA is aligned to a 4-byte boundary.
661          * However some drivers require L2 padding to pad the payload
662          * rather then the header. This could be a requirement for
663          * PCI and USB devices, while header alignment only is valid
664          * for PCI devices.
665          */
666         if (rt2x00_has_cap_flag(queue->rt2x00dev, REQUIRE_L2PAD))
667                 rt2x00queue_insert_l2pad(skb, txdesc.header_length);
668         else if (rt2x00_has_cap_flag(queue->rt2x00dev, REQUIRE_DMA))
669                 rt2x00queue_align_frame(skb);
670
671         /*
672          * That function must be called with bh disabled.
673          */
674         spin_lock(&queue->tx_lock);
675
676         if (unlikely(rt2x00queue_full(queue))) {
677                 rt2x00_err(queue->rt2x00dev, "Dropping frame due to full tx queue %d\n",
678                            queue->qid);
679                 ret = -ENOBUFS;
680                 goto out;
681         }
682
683         entry = rt2x00queue_get_entry(queue, Q_INDEX);
684
685         if (unlikely(test_and_set_bit(ENTRY_OWNER_DEVICE_DATA,
686                                       &entry->flags))) {
687                 rt2x00_err(queue->rt2x00dev,
688                            "Arrived at non-free entry in the non-full queue %d\n"
689                            "Please file bug report to %s\n",
690                            queue->qid, DRV_PROJECT);
691                 ret = -EINVAL;
692                 goto out;
693         }
694
695         skbdesc->entry = entry;
696         entry->skb = skb;
697
698         /*
699          * It could be possible that the queue was corrupted and this
700          * call failed. Since we always return NETDEV_TX_OK to mac80211,
701          * this frame will simply be dropped.
702          */
703         if (unlikely(rt2x00queue_write_tx_data(entry, &txdesc))) {
704                 clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
705                 entry->skb = NULL;
706                 ret = -EIO;
707                 goto out;
708         }
709
710         /*
711          * Put BlockAckReqs into our check list for driver BA processing.
712          */
713         rt2x00queue_bar_check(entry);
714
715         set_bit(ENTRY_DATA_PENDING, &entry->flags);
716
717         rt2x00queue_index_inc(entry, Q_INDEX);
718         rt2x00queue_write_tx_descriptor(entry, &txdesc);
719         rt2x00queue_kick_tx_queue(queue, &txdesc);
720
721 out:
722         spin_unlock(&queue->tx_lock);
723         return ret;
724 }
725
726 int rt2x00queue_clear_beacon(struct rt2x00_dev *rt2x00dev,
727                              struct ieee80211_vif *vif)
728 {
729         struct rt2x00_intf *intf = vif_to_intf(vif);
730
731         if (unlikely(!intf->beacon))
732                 return -ENOBUFS;
733
734         /*
735          * Clean up the beacon skb.
736          */
737         rt2x00queue_free_skb(intf->beacon);
738
739         /*
740          * Clear beacon (single bssid devices don't need to clear the beacon
741          * since the beacon queue will get stopped anyway).
742          */
743         if (rt2x00dev->ops->lib->clear_beacon)
744                 rt2x00dev->ops->lib->clear_beacon(intf->beacon);
745
746         return 0;
747 }
748
749 int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
750                               struct ieee80211_vif *vif)
751 {
752         struct rt2x00_intf *intf = vif_to_intf(vif);
753         struct skb_frame_desc *skbdesc;
754         struct txentry_desc txdesc;
755
756         if (unlikely(!intf->beacon))
757                 return -ENOBUFS;
758
759         /*
760          * Clean up the beacon skb.
761          */
762         rt2x00queue_free_skb(intf->beacon);
763
764         intf->beacon->skb = ieee80211_beacon_get(rt2x00dev->hw, vif);
765         if (!intf->beacon->skb)
766                 return -ENOMEM;
767
768         /*
769          * Copy all TX descriptor information into txdesc,
770          * after that we are free to use the skb->cb array
771          * for our information.
772          */
773         rt2x00queue_create_tx_descriptor(rt2x00dev, intf->beacon->skb, &txdesc, NULL);
774
775         /*
776          * Fill in skb descriptor
777          */
778         skbdesc = get_skb_frame_desc(intf->beacon->skb);
779         memset(skbdesc, 0, sizeof(*skbdesc));
780         skbdesc->entry = intf->beacon;
781
782         /*
783          * Send beacon to hardware.
784          */
785         rt2x00dev->ops->lib->write_beacon(intf->beacon, &txdesc);
786
787         return 0;
788
789 }
790
791 bool rt2x00queue_for_each_entry(struct data_queue *queue,
792                                 enum queue_index start,
793                                 enum queue_index end,
794                                 void *data,
795                                 bool (*fn)(struct queue_entry *entry,
796                                            void *data))
797 {
798         unsigned long irqflags;
799         unsigned int index_start;
800         unsigned int index_end;
801         unsigned int i;
802
803         if (unlikely(start >= Q_INDEX_MAX || end >= Q_INDEX_MAX)) {
804                 rt2x00_err(queue->rt2x00dev,
805                            "Entry requested from invalid index range (%d - %d)\n",
806                            start, end);
807                 return true;
808         }
809
810         /*
811          * Only protect the range we are going to loop over,
812          * if during our loop a extra entry is set to pending
813          * it should not be kicked during this run, since it
814          * is part of another TX operation.
815          */
816         spin_lock_irqsave(&queue->index_lock, irqflags);
817         index_start = queue->index[start];
818         index_end = queue->index[end];
819         spin_unlock_irqrestore(&queue->index_lock, irqflags);
820
821         /*
822          * Start from the TX done pointer, this guarantees that we will
823          * send out all frames in the correct order.
824          */
825         if (index_start < index_end) {
826                 for (i = index_start; i < index_end; i++) {
827                         if (fn(&queue->entries[i], data))
828                                 return true;
829                 }
830         } else {
831                 for (i = index_start; i < queue->limit; i++) {
832                         if (fn(&queue->entries[i], data))
833                                 return true;
834                 }
835
836                 for (i = 0; i < index_end; i++) {
837                         if (fn(&queue->entries[i], data))
838                                 return true;
839                 }
840         }
841
842         return false;
843 }
844 EXPORT_SYMBOL_GPL(rt2x00queue_for_each_entry);
845
846 struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
847                                           enum queue_index index)
848 {
849         struct queue_entry *entry;
850         unsigned long irqflags;
851
852         if (unlikely(index >= Q_INDEX_MAX)) {
853                 rt2x00_err(queue->rt2x00dev, "Entry requested from invalid index type (%d)\n",
854                            index);
855                 return NULL;
856         }
857
858         spin_lock_irqsave(&queue->index_lock, irqflags);
859
860         entry = &queue->entries[queue->index[index]];
861
862         spin_unlock_irqrestore(&queue->index_lock, irqflags);
863
864         return entry;
865 }
866 EXPORT_SYMBOL_GPL(rt2x00queue_get_entry);
867
868 void rt2x00queue_index_inc(struct queue_entry *entry, enum queue_index index)
869 {
870         struct data_queue *queue = entry->queue;
871         unsigned long irqflags;
872
873         if (unlikely(index >= Q_INDEX_MAX)) {
874                 rt2x00_err(queue->rt2x00dev,
875                            "Index change on invalid index type (%d)\n", index);
876                 return;
877         }
878
879         spin_lock_irqsave(&queue->index_lock, irqflags);
880
881         queue->index[index]++;
882         if (queue->index[index] >= queue->limit)
883                 queue->index[index] = 0;
884
885         entry->last_action = jiffies;
886
887         if (index == Q_INDEX) {
888                 queue->length++;
889         } else if (index == Q_INDEX_DONE) {
890                 queue->length--;
891                 queue->count++;
892         }
893
894         spin_unlock_irqrestore(&queue->index_lock, irqflags);
895 }
896
897 static void rt2x00queue_pause_queue_nocheck(struct data_queue *queue)
898 {
899         switch (queue->qid) {
900         case QID_AC_VO:
901         case QID_AC_VI:
902         case QID_AC_BE:
903         case QID_AC_BK:
904                 /*
905                  * For TX queues, we have to disable the queue
906                  * inside mac80211.
907                  */
908                 ieee80211_stop_queue(queue->rt2x00dev->hw, queue->qid);
909                 break;
910         default:
911                 break;
912         }
913 }
914 void rt2x00queue_pause_queue(struct data_queue *queue)
915 {
916         if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
917             !test_bit(QUEUE_STARTED, &queue->flags) ||
918             test_and_set_bit(QUEUE_PAUSED, &queue->flags))
919                 return;
920
921         rt2x00queue_pause_queue_nocheck(queue);
922 }
923 EXPORT_SYMBOL_GPL(rt2x00queue_pause_queue);
924
925 void rt2x00queue_unpause_queue(struct data_queue *queue)
926 {
927         if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
928             !test_bit(QUEUE_STARTED, &queue->flags) ||
929             !test_and_clear_bit(QUEUE_PAUSED, &queue->flags))
930                 return;
931
932         switch (queue->qid) {
933         case QID_AC_VO:
934         case QID_AC_VI:
935         case QID_AC_BE:
936         case QID_AC_BK:
937                 /*
938                  * For TX queues, we have to enable the queue
939                  * inside mac80211.
940                  */
941                 ieee80211_wake_queue(queue->rt2x00dev->hw, queue->qid);
942                 break;
943         case QID_RX:
944                 /*
945                  * For RX we need to kick the queue now in order to
946                  * receive frames.
947                  */
948                 queue->rt2x00dev->ops->lib->kick_queue(queue);
949         default:
950                 break;
951         }
952 }
953 EXPORT_SYMBOL_GPL(rt2x00queue_unpause_queue);
954
955 void rt2x00queue_start_queue(struct data_queue *queue)
956 {
957         mutex_lock(&queue->status_lock);
958
959         if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
960             test_and_set_bit(QUEUE_STARTED, &queue->flags)) {
961                 mutex_unlock(&queue->status_lock);
962                 return;
963         }
964
965         set_bit(QUEUE_PAUSED, &queue->flags);
966
967         queue->rt2x00dev->ops->lib->start_queue(queue);
968
969         rt2x00queue_unpause_queue(queue);
970
971         mutex_unlock(&queue->status_lock);
972 }
973 EXPORT_SYMBOL_GPL(rt2x00queue_start_queue);
974
975 void rt2x00queue_stop_queue(struct data_queue *queue)
976 {
977         mutex_lock(&queue->status_lock);
978
979         if (!test_and_clear_bit(QUEUE_STARTED, &queue->flags)) {
980                 mutex_unlock(&queue->status_lock);
981                 return;
982         }
983
984         rt2x00queue_pause_queue_nocheck(queue);
985
986         queue->rt2x00dev->ops->lib->stop_queue(queue);
987
988         mutex_unlock(&queue->status_lock);
989 }
990 EXPORT_SYMBOL_GPL(rt2x00queue_stop_queue);
991
992 void rt2x00queue_flush_queue(struct data_queue *queue, bool drop)
993 {
994         bool tx_queue =
995                 (queue->qid == QID_AC_VO) ||
996                 (queue->qid == QID_AC_VI) ||
997                 (queue->qid == QID_AC_BE) ||
998                 (queue->qid == QID_AC_BK);
999
1000
1001         /*
1002          * If we are not supposed to drop any pending
1003          * frames, this means we must force a start (=kick)
1004          * to the queue to make sure the hardware will
1005          * start transmitting.
1006          */
1007         if (!drop && tx_queue)
1008                 queue->rt2x00dev->ops->lib->kick_queue(queue);
1009
1010         /*
1011          * Check if driver supports flushing, if that is the case we can
1012          * defer the flushing to the driver. Otherwise we must use the
1013          * alternative which just waits for the queue to become empty.
1014          */
1015         if (likely(queue->rt2x00dev->ops->lib->flush_queue))
1016                 queue->rt2x00dev->ops->lib->flush_queue(queue, drop);
1017
1018         /*
1019          * The queue flush has failed...
1020          */
1021         if (unlikely(!rt2x00queue_empty(queue)))
1022                 rt2x00_warn(queue->rt2x00dev, "Queue %d failed to flush\n",
1023                             queue->qid);
1024 }
1025 EXPORT_SYMBOL_GPL(rt2x00queue_flush_queue);
1026
1027 void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev)
1028 {
1029         struct data_queue *queue;
1030
1031         /*
1032          * rt2x00queue_start_queue will call ieee80211_wake_queue
1033          * for each queue after is has been properly initialized.
1034          */
1035         tx_queue_for_each(rt2x00dev, queue)
1036                 rt2x00queue_start_queue(queue);
1037
1038         rt2x00queue_start_queue(rt2x00dev->rx);
1039 }
1040 EXPORT_SYMBOL_GPL(rt2x00queue_start_queues);
1041
1042 void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev)
1043 {
1044         struct data_queue *queue;
1045
1046         /*
1047          * rt2x00queue_stop_queue will call ieee80211_stop_queue
1048          * as well, but we are completely shutting doing everything
1049          * now, so it is much safer to stop all TX queues at once,
1050          * and use rt2x00queue_stop_queue for cleaning up.
1051          */
1052         ieee80211_stop_queues(rt2x00dev->hw);
1053
1054         tx_queue_for_each(rt2x00dev, queue)
1055                 rt2x00queue_stop_queue(queue);
1056
1057         rt2x00queue_stop_queue(rt2x00dev->rx);
1058 }
1059 EXPORT_SYMBOL_GPL(rt2x00queue_stop_queues);
1060
1061 void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop)
1062 {
1063         struct data_queue *queue;
1064
1065         tx_queue_for_each(rt2x00dev, queue)
1066                 rt2x00queue_flush_queue(queue, drop);
1067
1068         rt2x00queue_flush_queue(rt2x00dev->rx, drop);
1069 }
1070 EXPORT_SYMBOL_GPL(rt2x00queue_flush_queues);
1071
1072 static void rt2x00queue_reset(struct data_queue *queue)
1073 {
1074         unsigned long irqflags;
1075         unsigned int i;
1076
1077         spin_lock_irqsave(&queue->index_lock, irqflags);
1078
1079         queue->count = 0;
1080         queue->length = 0;
1081
1082         for (i = 0; i < Q_INDEX_MAX; i++)
1083                 queue->index[i] = 0;
1084
1085         spin_unlock_irqrestore(&queue->index_lock, irqflags);
1086 }
1087
1088 void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev)
1089 {
1090         struct data_queue *queue;
1091         unsigned int i;
1092
1093         queue_for_each(rt2x00dev, queue) {
1094                 rt2x00queue_reset(queue);
1095
1096                 for (i = 0; i < queue->limit; i++)
1097                         rt2x00dev->ops->lib->clear_entry(&queue->entries[i]);
1098         }
1099 }
1100
1101 static int rt2x00queue_alloc_entries(struct data_queue *queue)
1102 {
1103         struct queue_entry *entries;
1104         unsigned int entry_size;
1105         unsigned int i;
1106
1107         rt2x00queue_reset(queue);
1108
1109         /*
1110          * Allocate all queue entries.
1111          */
1112         entry_size = sizeof(*entries) + queue->priv_size;
1113         entries = kcalloc(queue->limit, entry_size, GFP_KERNEL);
1114         if (!entries)
1115                 return -ENOMEM;
1116
1117 #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \
1118         (((char *)(__base)) + ((__limit) * (__esize)) + \
1119             ((__index) * (__psize)))
1120
1121         for (i = 0; i < queue->limit; i++) {
1122                 entries[i].flags = 0;
1123                 entries[i].queue = queue;
1124                 entries[i].skb = NULL;
1125                 entries[i].entry_idx = i;
1126                 entries[i].priv_data =
1127                     QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit,
1128                                             sizeof(*entries), queue->priv_size);
1129         }
1130
1131 #undef QUEUE_ENTRY_PRIV_OFFSET
1132
1133         queue->entries = entries;
1134
1135         return 0;
1136 }
1137
1138 static void rt2x00queue_free_skbs(struct data_queue *queue)
1139 {
1140         unsigned int i;
1141
1142         if (!queue->entries)
1143                 return;
1144
1145         for (i = 0; i < queue->limit; i++) {
1146                 rt2x00queue_free_skb(&queue->entries[i]);
1147         }
1148 }
1149
1150 static int rt2x00queue_alloc_rxskbs(struct data_queue *queue)
1151 {
1152         unsigned int i;
1153         struct sk_buff *skb;
1154
1155         for (i = 0; i < queue->limit; i++) {
1156                 skb = rt2x00queue_alloc_rxskb(&queue->entries[i], GFP_KERNEL);
1157                 if (!skb)
1158                         return -ENOMEM;
1159                 queue->entries[i].skb = skb;
1160         }
1161
1162         return 0;
1163 }
1164
1165 int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
1166 {
1167         struct data_queue *queue;
1168         int status;
1169
1170         status = rt2x00queue_alloc_entries(rt2x00dev->rx);
1171         if (status)
1172                 goto exit;
1173
1174         tx_queue_for_each(rt2x00dev, queue) {
1175                 status = rt2x00queue_alloc_entries(queue);
1176                 if (status)
1177                         goto exit;
1178         }
1179
1180         status = rt2x00queue_alloc_entries(rt2x00dev->bcn);
1181         if (status)
1182                 goto exit;
1183
1184         if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_ATIM_QUEUE)) {
1185                 status = rt2x00queue_alloc_entries(rt2x00dev->atim);
1186                 if (status)
1187                         goto exit;
1188         }
1189
1190         status = rt2x00queue_alloc_rxskbs(rt2x00dev->rx);
1191         if (status)
1192                 goto exit;
1193
1194         return 0;
1195
1196 exit:
1197         rt2x00_err(rt2x00dev, "Queue entries allocation failed\n");
1198
1199         rt2x00queue_uninitialize(rt2x00dev);
1200
1201         return status;
1202 }
1203
1204 void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev)
1205 {
1206         struct data_queue *queue;
1207
1208         rt2x00queue_free_skbs(rt2x00dev->rx);
1209
1210         queue_for_each(rt2x00dev, queue) {
1211                 kfree(queue->entries);
1212                 queue->entries = NULL;
1213         }
1214 }
1215
1216 static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev,
1217                              struct data_queue *queue, enum data_queue_qid qid)
1218 {
1219         mutex_init(&queue->status_lock);
1220         spin_lock_init(&queue->tx_lock);
1221         spin_lock_init(&queue->index_lock);
1222
1223         queue->rt2x00dev = rt2x00dev;
1224         queue->qid = qid;
1225         queue->txop = 0;
1226         queue->aifs = 2;
1227         queue->cw_min = 5;
1228         queue->cw_max = 10;
1229
1230         rt2x00dev->ops->queue_init(queue);
1231
1232         queue->threshold = DIV_ROUND_UP(queue->limit, 10);
1233 }
1234
1235 int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev)
1236 {
1237         struct data_queue *queue;
1238         enum data_queue_qid qid;
1239         unsigned int req_atim =
1240             rt2x00_has_cap_flag(rt2x00dev, REQUIRE_ATIM_QUEUE);
1241
1242         /*
1243          * We need the following queues:
1244          * RX: 1
1245          * TX: ops->tx_queues
1246          * Beacon: 1
1247          * Atim: 1 (if required)
1248          */
1249         rt2x00dev->data_queues = 2 + rt2x00dev->ops->tx_queues + req_atim;
1250
1251         queue = kcalloc(rt2x00dev->data_queues, sizeof(*queue), GFP_KERNEL);
1252         if (!queue) {
1253                 rt2x00_err(rt2x00dev, "Queue allocation failed\n");
1254                 return -ENOMEM;
1255         }
1256
1257         /*
1258          * Initialize pointers
1259          */
1260         rt2x00dev->rx = queue;
1261         rt2x00dev->tx = &queue[1];
1262         rt2x00dev->bcn = &queue[1 + rt2x00dev->ops->tx_queues];
1263         rt2x00dev->atim = req_atim ? &queue[2 + rt2x00dev->ops->tx_queues] : NULL;
1264
1265         /*
1266          * Initialize queue parameters.
1267          * RX: qid = QID_RX
1268          * TX: qid = QID_AC_VO + index
1269          * TX: cw_min: 2^5 = 32.
1270          * TX: cw_max: 2^10 = 1024.
1271          * BCN: qid = QID_BEACON
1272          * ATIM: qid = QID_ATIM
1273          */
1274         rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX);
1275
1276         qid = QID_AC_VO;
1277         tx_queue_for_each(rt2x00dev, queue)
1278                 rt2x00queue_init(rt2x00dev, queue, qid++);
1279
1280         rt2x00queue_init(rt2x00dev, rt2x00dev->bcn, QID_BEACON);
1281         if (req_atim)
1282                 rt2x00queue_init(rt2x00dev, rt2x00dev->atim, QID_ATIM);
1283
1284         return 0;
1285 }
1286
1287 void rt2x00queue_free(struct rt2x00_dev *rt2x00dev)
1288 {
1289         kfree(rt2x00dev->rx);
1290         rt2x00dev->rx = NULL;
1291         rt2x00dev->tx = NULL;
1292         rt2x00dev->bcn = NULL;
1293 }