]> err.no Git - linux-2.6/blob - drivers/net/wireless/rt2x00/rt2x00dev.c
rt2x00: Add skb descriptor
[linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00dev.c
1 /*
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: rt2x00lib
23         Abstract: rt2x00 generic device routines.
24  */
25
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28
29 #include "rt2x00.h"
30 #include "rt2x00lib.h"
31
32 /*
33  * Ring handler.
34  */
35 struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev,
36                                      const unsigned int queue)
37 {
38         int beacon = test_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
39
40         /*
41          * Check if we are requesting a reqular TX ring,
42          * or if we are requesting a Beacon or Atim ring.
43          * For Atim rings, we should check if it is supported.
44          */
45         if (queue < rt2x00dev->hw->queues && rt2x00dev->tx)
46                 return &rt2x00dev->tx[queue];
47
48         if (!rt2x00dev->bcn || !beacon)
49                 return NULL;
50
51         if (queue == IEEE80211_TX_QUEUE_BEACON)
52                 return &rt2x00dev->bcn[0];
53         else if (queue == IEEE80211_TX_QUEUE_AFTER_BEACON)
54                 return &rt2x00dev->bcn[1];
55
56         return NULL;
57 }
58 EXPORT_SYMBOL_GPL(rt2x00lib_get_ring);
59
60 /*
61  * Link tuning handlers
62  */
63 static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev)
64 {
65         rt2x00dev->link.count = 0;
66         rt2x00dev->link.vgc_level = 0;
67
68         memset(&rt2x00dev->link.qual, 0, sizeof(rt2x00dev->link.qual));
69
70         /*
71          * The RX and TX percentage should start at 50%
72          * this will assure we will get at least get some
73          * decent value when the link tuner starts.
74          * The value will be dropped and overwritten with
75          * the correct (measured )value anyway during the
76          * first run of the link tuner.
77          */
78         rt2x00dev->link.qual.rx_percentage = 50;
79         rt2x00dev->link.qual.tx_percentage = 50;
80
81         /*
82          * Reset the link tuner.
83          */
84         rt2x00dev->ops->lib->reset_tuner(rt2x00dev);
85
86         queue_delayed_work(rt2x00dev->hw->workqueue,
87                            &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
88 }
89
90 static void rt2x00lib_stop_link_tuner(struct rt2x00_dev *rt2x00dev)
91 {
92         cancel_delayed_work_sync(&rt2x00dev->link.work);
93 }
94
95 void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
96 {
97         if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
98                 return;
99
100         rt2x00lib_stop_link_tuner(rt2x00dev);
101         rt2x00lib_start_link_tuner(rt2x00dev);
102 }
103
104 /*
105  * Radio control handlers.
106  */
107 int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
108 {
109         int status;
110
111         /*
112          * Don't enable the radio twice.
113          * And check if the hardware button has been disabled.
114          */
115         if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
116             test_bit(DEVICE_DISABLED_RADIO_HW, &rt2x00dev->flags))
117                 return 0;
118
119         /*
120          * Enable radio.
121          */
122         status = rt2x00dev->ops->lib->set_device_state(rt2x00dev,
123                                                        STATE_RADIO_ON);
124         if (status)
125                 return status;
126
127         __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
128
129         /*
130          * Enable RX.
131          */
132         rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
133
134         /*
135          * Start the TX queues.
136          */
137         ieee80211_start_queues(rt2x00dev->hw);
138
139         return 0;
140 }
141
142 void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
143 {
144         if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
145                 return;
146
147         /*
148          * Stop all scheduled work.
149          */
150         if (work_pending(&rt2x00dev->beacon_work))
151                 cancel_work_sync(&rt2x00dev->beacon_work);
152         if (work_pending(&rt2x00dev->filter_work))
153                 cancel_work_sync(&rt2x00dev->filter_work);
154         if (work_pending(&rt2x00dev->config_work))
155                 cancel_work_sync(&rt2x00dev->config_work);
156
157         /*
158          * Stop the TX queues.
159          */
160         ieee80211_stop_queues(rt2x00dev->hw);
161
162         /*
163          * Disable RX.
164          */
165         rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
166
167         /*
168          * Disable radio.
169          */
170         rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
171 }
172
173 void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state)
174 {
175         /*
176          * When we are disabling the RX, we should also stop the link tuner.
177          */
178         if (state == STATE_RADIO_RX_OFF)
179                 rt2x00lib_stop_link_tuner(rt2x00dev);
180
181         rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
182
183         /*
184          * When we are enabling the RX, we should also start the link tuner.
185          */
186         if (state == STATE_RADIO_RX_ON &&
187             is_interface_present(&rt2x00dev->interface))
188                 rt2x00lib_start_link_tuner(rt2x00dev);
189 }
190
191 static void rt2x00lib_evaluate_antenna_sample(struct rt2x00_dev *rt2x00dev)
192 {
193         enum antenna rx = rt2x00dev->link.ant.active.rx;
194         enum antenna tx = rt2x00dev->link.ant.active.tx;
195         int sample_a =
196             rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_A);
197         int sample_b =
198             rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_B);
199
200         /*
201          * We are done sampling. Now we should evaluate the results.
202          */
203         rt2x00dev->link.ant.flags &= ~ANTENNA_MODE_SAMPLE;
204
205         /*
206          * During the last period we have sampled the RSSI
207          * from both antenna's. It now is time to determine
208          * which antenna demonstrated the best performance.
209          * When we are already on the antenna with the best
210          * performance, then there really is nothing for us
211          * left to do.
212          */
213         if (sample_a == sample_b)
214                 return;
215
216         if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) {
217                 if (sample_a > sample_b && rx == ANTENNA_B)
218                         rx = ANTENNA_A;
219                 else if (rx == ANTENNA_A)
220                         rx = ANTENNA_B;
221         }
222
223         if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY) {
224                 if (sample_a > sample_b && tx == ANTENNA_B)
225                         tx = ANTENNA_A;
226                 else if (tx == ANTENNA_A)
227                         tx = ANTENNA_B;
228         }
229
230         rt2x00lib_config_antenna(rt2x00dev, rx, tx);
231 }
232
233 static void rt2x00lib_evaluate_antenna_eval(struct rt2x00_dev *rt2x00dev)
234 {
235         enum antenna rx = rt2x00dev->link.ant.active.rx;
236         enum antenna tx = rt2x00dev->link.ant.active.tx;
237         int rssi_curr = rt2x00_get_link_ant_rssi(&rt2x00dev->link);
238         int rssi_old = rt2x00_update_ant_rssi(&rt2x00dev->link, rssi_curr);
239
240         /*
241          * Legacy driver indicates that we should swap antenna's
242          * when the difference in RSSI is greater that 5. This
243          * also should be done when the RSSI was actually better
244          * then the previous sample.
245          * When the difference exceeds the threshold we should
246          * sample the rssi from the other antenna to make a valid
247          * comparison between the 2 antennas.
248          */
249         if ((rssi_curr - rssi_old) > -5 || (rssi_curr - rssi_old) < 5)
250                 return;
251
252         rt2x00dev->link.ant.flags |= ANTENNA_MODE_SAMPLE;
253
254         if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY)
255                 rx = (rx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A;
256
257         if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)
258                 tx = (tx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A;
259
260         rt2x00lib_config_antenna(rt2x00dev, rx, tx);
261 }
262
263 static void rt2x00lib_evaluate_antenna(struct rt2x00_dev *rt2x00dev)
264 {
265         /*
266          * Determine if software diversity is enabled for
267          * either the TX or RX antenna (or both).
268          * Always perform this check since within the link
269          * tuner interval the configuration might have changed.
270          */
271         rt2x00dev->link.ant.flags &= ~ANTENNA_RX_DIVERSITY;
272         rt2x00dev->link.ant.flags &= ~ANTENNA_TX_DIVERSITY;
273
274         if (rt2x00dev->hw->conf.antenna_sel_rx == 0 &&
275             rt2x00dev->default_ant.rx != ANTENNA_SW_DIVERSITY)
276                 rt2x00dev->link.ant.flags |= ANTENNA_RX_DIVERSITY;
277         if (rt2x00dev->hw->conf.antenna_sel_tx == 0 &&
278             rt2x00dev->default_ant.tx != ANTENNA_SW_DIVERSITY)
279                 rt2x00dev->link.ant.flags |= ANTENNA_TX_DIVERSITY;
280
281         if (!(rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) &&
282             !(rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)) {
283                 rt2x00dev->link.ant.flags &= ~ANTENNA_MODE_SAMPLE;
284                 return;
285         }
286
287         /*
288          * If we have only sampled the data over the last period
289          * we should now harvest the data. Otherwise just evaluate
290          * the data. The latter should only be performed once
291          * every 2 seconds.
292          */
293         if (rt2x00dev->link.ant.flags & ANTENNA_MODE_SAMPLE)
294                 rt2x00lib_evaluate_antenna_sample(rt2x00dev);
295         else if (rt2x00dev->link.count & 1)
296                 rt2x00lib_evaluate_antenna_eval(rt2x00dev);
297 }
298
299 static void rt2x00lib_update_link_stats(struct link *link, int rssi)
300 {
301         int avg_rssi = rssi;
302
303         /*
304          * Update global RSSI
305          */
306         if (link->qual.avg_rssi)
307                 avg_rssi = MOVING_AVERAGE(link->qual.avg_rssi, rssi, 8);
308         link->qual.avg_rssi = avg_rssi;
309
310         /*
311          * Update antenna RSSI
312          */
313         if (link->ant.rssi_ant)
314                 rssi = MOVING_AVERAGE(link->ant.rssi_ant, rssi, 8);
315         link->ant.rssi_ant = rssi;
316 }
317
318 static void rt2x00lib_precalculate_link_signal(struct link_qual *qual)
319 {
320         if (qual->rx_failed || qual->rx_success)
321                 qual->rx_percentage =
322                     (qual->rx_success * 100) /
323                     (qual->rx_failed + qual->rx_success);
324         else
325                 qual->rx_percentage = 50;
326
327         if (qual->tx_failed || qual->tx_success)
328                 qual->tx_percentage =
329                     (qual->tx_success * 100) /
330                     (qual->tx_failed + qual->tx_success);
331         else
332                 qual->tx_percentage = 50;
333
334         qual->rx_success = 0;
335         qual->rx_failed = 0;
336         qual->tx_success = 0;
337         qual->tx_failed = 0;
338 }
339
340 static int rt2x00lib_calculate_link_signal(struct rt2x00_dev *rt2x00dev,
341                                            int rssi)
342 {
343         int rssi_percentage = 0;
344         int signal;
345
346         /*
347          * We need a positive value for the RSSI.
348          */
349         if (rssi < 0)
350                 rssi += rt2x00dev->rssi_offset;
351
352         /*
353          * Calculate the different percentages,
354          * which will be used for the signal.
355          */
356         if (rt2x00dev->rssi_offset)
357                 rssi_percentage = (rssi * 100) / rt2x00dev->rssi_offset;
358
359         /*
360          * Add the individual percentages and use the WEIGHT
361          * defines to calculate the current link signal.
362          */
363         signal = ((WEIGHT_RSSI * rssi_percentage) +
364                   (WEIGHT_TX * rt2x00dev->link.qual.tx_percentage) +
365                   (WEIGHT_RX * rt2x00dev->link.qual.rx_percentage)) / 100;
366
367         return (signal > 100) ? 100 : signal;
368 }
369
370 static void rt2x00lib_link_tuner(struct work_struct *work)
371 {
372         struct rt2x00_dev *rt2x00dev =
373             container_of(work, struct rt2x00_dev, link.work.work);
374
375         /*
376          * When the radio is shutting down we should
377          * immediately cease all link tuning.
378          */
379         if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
380                 return;
381
382         /*
383          * Update statistics.
384          */
385         rt2x00dev->ops->lib->link_stats(rt2x00dev, &rt2x00dev->link.qual);
386         rt2x00dev->low_level_stats.dot11FCSErrorCount +=
387             rt2x00dev->link.qual.rx_failed;
388
389         /*
390          * Only perform the link tuning when Link tuning
391          * has been enabled (This could have been disabled from the EEPROM).
392          */
393         if (!test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags))
394                 rt2x00dev->ops->lib->link_tuner(rt2x00dev);
395
396         /*
397          * Evaluate antenna setup.
398          */
399         rt2x00lib_evaluate_antenna(rt2x00dev);
400
401         /*
402          * Precalculate a portion of the link signal which is
403          * in based on the tx/rx success/failure counters.
404          */
405         rt2x00lib_precalculate_link_signal(&rt2x00dev->link.qual);
406
407         /*
408          * Increase tuner counter, and reschedule the next link tuner run.
409          */
410         rt2x00dev->link.count++;
411         queue_delayed_work(rt2x00dev->hw->workqueue, &rt2x00dev->link.work,
412                            LINK_TUNE_INTERVAL);
413 }
414
415 static void rt2x00lib_packetfilter_scheduled(struct work_struct *work)
416 {
417         struct rt2x00_dev *rt2x00dev =
418             container_of(work, struct rt2x00_dev, filter_work);
419         unsigned int filter = rt2x00dev->interface.filter;
420
421         /*
422          * Since we had stored the filter inside interface.filter,
423          * we should now clear that field. Otherwise the driver will
424          * assume nothing has changed (*total_flags will be compared
425          * to interface.filter to determine if any action is required).
426          */
427         rt2x00dev->interface.filter = 0;
428
429         rt2x00dev->ops->hw->configure_filter(rt2x00dev->hw,
430                                              filter, &filter, 0, NULL);
431 }
432
433 static void rt2x00lib_configuration_scheduled(struct work_struct *work)
434 {
435         struct rt2x00_dev *rt2x00dev =
436             container_of(work, struct rt2x00_dev, config_work);
437         int preamble = !test_bit(CONFIG_SHORT_PREAMBLE, &rt2x00dev->flags);
438
439         rt2x00mac_erp_ie_changed(rt2x00dev->hw,
440                                  IEEE80211_ERP_CHANGE_PREAMBLE, 0, preamble);
441 }
442
443 /*
444  * Interrupt context handlers.
445  */
446 static void rt2x00lib_beacondone_scheduled(struct work_struct *work)
447 {
448         struct rt2x00_dev *rt2x00dev =
449             container_of(work, struct rt2x00_dev, beacon_work);
450         struct data_ring *ring =
451             rt2x00lib_get_ring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
452         struct data_entry *entry = rt2x00_get_data_entry(ring);
453         struct sk_buff *skb;
454
455         skb = ieee80211_beacon_get(rt2x00dev->hw,
456                                    rt2x00dev->interface.id,
457                                    &entry->tx_status.control);
458         if (!skb)
459                 return;
460
461         rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, skb,
462                                           &entry->tx_status.control);
463
464         dev_kfree_skb(skb);
465 }
466
467 void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
468 {
469         if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
470                 return;
471
472         queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->beacon_work);
473 }
474 EXPORT_SYMBOL_GPL(rt2x00lib_beacondone);
475
476 void rt2x00lib_txdone(struct data_entry *entry,
477                       const int status, const int retry)
478 {
479         struct rt2x00_dev *rt2x00dev = entry->ring->rt2x00dev;
480         struct ieee80211_tx_status *tx_status = &entry->tx_status;
481         struct ieee80211_low_level_stats *stats = &rt2x00dev->low_level_stats;
482         int success = !!(status == TX_SUCCESS || status == TX_SUCCESS_RETRY);
483         int fail = !!(status == TX_FAIL_RETRY || status == TX_FAIL_INVALID ||
484                       status == TX_FAIL_OTHER);
485
486         /*
487          * Update TX statistics.
488          */
489         tx_status->flags = 0;
490         tx_status->ack_signal = 0;
491         tx_status->excessive_retries = (status == TX_FAIL_RETRY);
492         tx_status->retry_count = retry;
493         rt2x00dev->link.qual.tx_success += success;
494         rt2x00dev->link.qual.tx_failed += retry + fail;
495
496         if (!(tx_status->control.flags & IEEE80211_TXCTL_NO_ACK)) {
497                 if (success)
498                         tx_status->flags |= IEEE80211_TX_STATUS_ACK;
499                 else
500                         stats->dot11ACKFailureCount++;
501         }
502
503         tx_status->queue_length = entry->ring->stats.limit;
504         tx_status->queue_number = tx_status->control.queue;
505
506         if (tx_status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) {
507                 if (success)
508                         stats->dot11RTSSuccessCount++;
509                 else
510                         stats->dot11RTSFailureCount++;
511         }
512
513         /*
514          * Send the tx_status to mac80211,
515          * that method also cleans up the skb structure.
516          */
517         ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb, tx_status);
518         entry->skb = NULL;
519 }
520 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
521
522 void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb,
523                       struct rxdata_entry_desc *desc)
524 {
525         struct rt2x00_dev *rt2x00dev = entry->ring->rt2x00dev;
526         struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
527         struct ieee80211_hw_mode *mode;
528         struct ieee80211_rate *rate;
529         unsigned int i;
530         int val = 0;
531
532         /*
533          * Update RX statistics.
534          */
535         mode = &rt2x00dev->hwmodes[rt2x00dev->curr_hwmode];
536         for (i = 0; i < mode->num_rates; i++) {
537                 rate = &mode->rates[i];
538
539                 /*
540                  * When frame was received with an OFDM bitrate,
541                  * the signal is the PLCP value. If it was received with
542                  * a CCK bitrate the signal is the rate in 0.5kbit/s.
543                  */
544                 if (!desc->ofdm)
545                         val = DEVICE_GET_RATE_FIELD(rate->val, RATE);
546                 else
547                         val = DEVICE_GET_RATE_FIELD(rate->val, PLCP);
548
549                 if (val == desc->signal) {
550                         val = rate->val;
551                         break;
552                 }
553         }
554
555         rt2x00lib_update_link_stats(&rt2x00dev->link, desc->rssi);
556         rt2x00dev->link.qual.rx_success++;
557
558         rx_status->rate = val;
559         rx_status->signal =
560             rt2x00lib_calculate_link_signal(rt2x00dev, desc->rssi);
561         rx_status->ssi = desc->rssi;
562         rx_status->flag = desc->flags;
563         rx_status->antenna = rt2x00dev->link.ant.active.rx;
564
565         /*
566          * Send frame to mac80211
567          */
568         ieee80211_rx_irqsafe(rt2x00dev->hw, skb, rx_status);
569 }
570 EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
571
572 /*
573  * TX descriptor initializer
574  */
575 void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
576                              struct sk_buff *skb,
577                              struct ieee80211_tx_control *control)
578 {
579         struct txdata_entry_desc desc;
580         struct skb_desc *skbdesc = get_skb_desc(skb);
581         struct ieee80211_hdr *ieee80211hdr = skbdesc->data;
582         __le32 *txd = skbdesc->desc;
583         int tx_rate;
584         int bitrate;
585         int length;
586         int duration;
587         int residual;
588         u16 frame_control;
589         u16 seq_ctrl;
590
591         memset(&desc, 0, sizeof(desc));
592
593         desc.cw_min = skbdesc->ring->tx_params.cw_min;
594         desc.cw_max = skbdesc->ring->tx_params.cw_max;
595         desc.aifs = skbdesc->ring->tx_params.aifs;
596
597         /*
598          * Identify queue
599          */
600         if (control->queue < rt2x00dev->hw->queues)
601                 desc.queue = control->queue;
602         else if (control->queue == IEEE80211_TX_QUEUE_BEACON ||
603                  control->queue == IEEE80211_TX_QUEUE_AFTER_BEACON)
604                 desc.queue = QUEUE_MGMT;
605         else
606                 desc.queue = QUEUE_OTHER;
607
608         /*
609          * Read required fields from ieee80211 header.
610          */
611         frame_control = le16_to_cpu(ieee80211hdr->frame_control);
612         seq_ctrl = le16_to_cpu(ieee80211hdr->seq_ctrl);
613
614         tx_rate = control->tx_rate;
615
616         /*
617          * Check whether this frame is to be acked
618          */
619         if (!(control->flags & IEEE80211_TXCTL_NO_ACK))
620                 __set_bit(ENTRY_TXD_ACK, &desc.flags);
621
622         /*
623          * Check if this is a RTS/CTS frame
624          */
625         if (is_rts_frame(frame_control) || is_cts_frame(frame_control)) {
626                 __set_bit(ENTRY_TXD_BURST, &desc.flags);
627                 if (is_rts_frame(frame_control)) {
628                         __set_bit(ENTRY_TXD_RTS_FRAME, &desc.flags);
629                         __set_bit(ENTRY_TXD_ACK, &desc.flags);
630                 } else
631                         __clear_bit(ENTRY_TXD_ACK, &desc.flags);
632                 if (control->rts_cts_rate)
633                         tx_rate = control->rts_cts_rate;
634         }
635
636         /*
637          * Check for OFDM
638          */
639         if (DEVICE_GET_RATE_FIELD(tx_rate, RATEMASK) & DEV_OFDM_RATEMASK)
640                 __set_bit(ENTRY_TXD_OFDM_RATE, &desc.flags);
641
642         /*
643          * Check if more fragments are pending
644          */
645         if (ieee80211_get_morefrag(ieee80211hdr)) {
646                 __set_bit(ENTRY_TXD_BURST, &desc.flags);
647                 __set_bit(ENTRY_TXD_MORE_FRAG, &desc.flags);
648         }
649
650         /*
651          * Beacons and probe responses require the tsf timestamp
652          * to be inserted into the frame.
653          */
654         if (control->queue == IEEE80211_TX_QUEUE_BEACON ||
655             is_probe_resp(frame_control))
656                 __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc.flags);
657
658         /*
659          * Determine with what IFS priority this frame should be send.
660          * Set ifs to IFS_SIFS when the this is not the first fragment,
661          * or this fragment came after RTS/CTS.
662          */
663         if ((seq_ctrl & IEEE80211_SCTL_FRAG) > 0 ||
664             test_bit(ENTRY_TXD_RTS_FRAME, &desc.flags))
665                 desc.ifs = IFS_SIFS;
666         else
667                 desc.ifs = IFS_BACKOFF;
668
669         /*
670          * PLCP setup
671          * Length calculation depends on OFDM/CCK rate.
672          */
673         desc.signal = DEVICE_GET_RATE_FIELD(tx_rate, PLCP);
674         desc.service = 0x04;
675
676         length = skbdesc->data_len + FCS_LEN;
677         if (test_bit(ENTRY_TXD_OFDM_RATE, &desc.flags)) {
678                 desc.length_high = (length >> 6) & 0x3f;
679                 desc.length_low = length & 0x3f;
680         } else {
681                 bitrate = DEVICE_GET_RATE_FIELD(tx_rate, RATE);
682
683                 /*
684                  * Convert length to microseconds.
685                  */
686                 residual = get_duration_res(length, bitrate);
687                 duration = get_duration(length, bitrate);
688
689                 if (residual != 0) {
690                         duration++;
691
692                         /*
693                          * Check if we need to set the Length Extension
694                          */
695                         if (bitrate == 110 && residual <= 30)
696                                 desc.service |= 0x80;
697                 }
698
699                 desc.length_high = (duration >> 8) & 0xff;
700                 desc.length_low = duration & 0xff;
701
702                 /*
703                  * When preamble is enabled we should set the
704                  * preamble bit for the signal.
705                  */
706                 if (DEVICE_GET_RATE_FIELD(tx_rate, PREAMBLE))
707                         desc.signal |= 0x08;
708         }
709
710         rt2x00dev->ops->lib->write_tx_desc(rt2x00dev, txd, &desc, ieee80211hdr,
711                                            skbdesc->data_len, control);
712
713         /*
714          * Update ring entry.
715          */
716         skbdesc->entry->skb = skb;
717         memcpy(&skbdesc->entry->tx_status.control, control, sizeof(*control));
718 }
719 EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc);
720
721 /*
722  * Driver initialization handlers.
723  */
724 static void rt2x00lib_channel(struct ieee80211_channel *entry,
725                               const int channel, const int tx_power,
726                               const int value)
727 {
728         entry->chan = channel;
729         if (channel <= 14)
730                 entry->freq = 2407 + (5 * channel);
731         else
732                 entry->freq = 5000 + (5 * channel);
733         entry->val = value;
734         entry->flag =
735             IEEE80211_CHAN_W_IBSS |
736             IEEE80211_CHAN_W_ACTIVE_SCAN |
737             IEEE80211_CHAN_W_SCAN;
738         entry->power_level = tx_power;
739         entry->antenna_max = 0xff;
740 }
741
742 static void rt2x00lib_rate(struct ieee80211_rate *entry,
743                            const int rate, const int mask,
744                            const int plcp, const int flags)
745 {
746         entry->rate = rate;
747         entry->val =
748             DEVICE_SET_RATE_FIELD(rate, RATE) |
749             DEVICE_SET_RATE_FIELD(mask, RATEMASK) |
750             DEVICE_SET_RATE_FIELD(plcp, PLCP);
751         entry->flags = flags;
752         entry->val2 = entry->val;
753         if (entry->flags & IEEE80211_RATE_PREAMBLE2)
754                 entry->val2 |= DEVICE_SET_RATE_FIELD(1, PREAMBLE);
755         entry->min_rssi_ack = 0;
756         entry->min_rssi_ack_delta = 0;
757 }
758
759 static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
760                                     struct hw_mode_spec *spec)
761 {
762         struct ieee80211_hw *hw = rt2x00dev->hw;
763         struct ieee80211_hw_mode *hwmodes;
764         struct ieee80211_channel *channels;
765         struct ieee80211_rate *rates;
766         unsigned int i;
767         unsigned char tx_power;
768
769         hwmodes = kzalloc(sizeof(*hwmodes) * spec->num_modes, GFP_KERNEL);
770         if (!hwmodes)
771                 goto exit;
772
773         channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
774         if (!channels)
775                 goto exit_free_modes;
776
777         rates = kzalloc(sizeof(*rates) * spec->num_rates, GFP_KERNEL);
778         if (!rates)
779                 goto exit_free_channels;
780
781         /*
782          * Initialize Rate list.
783          */
784         rt2x00lib_rate(&rates[0], 10, DEV_RATEMASK_1MB,
785                        0x00, IEEE80211_RATE_CCK);
786         rt2x00lib_rate(&rates[1], 20, DEV_RATEMASK_2MB,
787                        0x01, IEEE80211_RATE_CCK_2);
788         rt2x00lib_rate(&rates[2], 55, DEV_RATEMASK_5_5MB,
789                        0x02, IEEE80211_RATE_CCK_2);
790         rt2x00lib_rate(&rates[3], 110, DEV_RATEMASK_11MB,
791                        0x03, IEEE80211_RATE_CCK_2);
792
793         if (spec->num_rates > 4) {
794                 rt2x00lib_rate(&rates[4], 60, DEV_RATEMASK_6MB,
795                                0x0b, IEEE80211_RATE_OFDM);
796                 rt2x00lib_rate(&rates[5], 90, DEV_RATEMASK_9MB,
797                                0x0f, IEEE80211_RATE_OFDM);
798                 rt2x00lib_rate(&rates[6], 120, DEV_RATEMASK_12MB,
799                                0x0a, IEEE80211_RATE_OFDM);
800                 rt2x00lib_rate(&rates[7], 180, DEV_RATEMASK_18MB,
801                                0x0e, IEEE80211_RATE_OFDM);
802                 rt2x00lib_rate(&rates[8], 240, DEV_RATEMASK_24MB,
803                                0x09, IEEE80211_RATE_OFDM);
804                 rt2x00lib_rate(&rates[9], 360, DEV_RATEMASK_36MB,
805                                0x0d, IEEE80211_RATE_OFDM);
806                 rt2x00lib_rate(&rates[10], 480, DEV_RATEMASK_48MB,
807                                0x08, IEEE80211_RATE_OFDM);
808                 rt2x00lib_rate(&rates[11], 540, DEV_RATEMASK_54MB,
809                                0x0c, IEEE80211_RATE_OFDM);
810         }
811
812         /*
813          * Initialize Channel list.
814          */
815         for (i = 0; i < spec->num_channels; i++) {
816                 if (spec->channels[i].channel <= 14)
817                         tx_power = spec->tx_power_bg[i];
818                 else if (spec->tx_power_a)
819                         tx_power = spec->tx_power_a[i];
820                 else
821                         tx_power = spec->tx_power_default;
822
823                 rt2x00lib_channel(&channels[i],
824                                   spec->channels[i].channel, tx_power, i);
825         }
826
827         /*
828          * Intitialize 802.11b
829          * Rates: CCK.
830          * Channels: OFDM.
831          */
832         if (spec->num_modes > HWMODE_B) {
833                 hwmodes[HWMODE_B].mode = MODE_IEEE80211B;
834                 hwmodes[HWMODE_B].num_channels = 14;
835                 hwmodes[HWMODE_B].num_rates = 4;
836                 hwmodes[HWMODE_B].channels = channels;
837                 hwmodes[HWMODE_B].rates = rates;
838         }
839
840         /*
841          * Intitialize 802.11g
842          * Rates: CCK, OFDM.
843          * Channels: OFDM.
844          */
845         if (spec->num_modes > HWMODE_G) {
846                 hwmodes[HWMODE_G].mode = MODE_IEEE80211G;
847                 hwmodes[HWMODE_G].num_channels = 14;
848                 hwmodes[HWMODE_G].num_rates = spec->num_rates;
849                 hwmodes[HWMODE_G].channels = channels;
850                 hwmodes[HWMODE_G].rates = rates;
851         }
852
853         /*
854          * Intitialize 802.11a
855          * Rates: OFDM.
856          * Channels: OFDM, UNII, HiperLAN2.
857          */
858         if (spec->num_modes > HWMODE_A) {
859                 hwmodes[HWMODE_A].mode = MODE_IEEE80211A;
860                 hwmodes[HWMODE_A].num_channels = spec->num_channels - 14;
861                 hwmodes[HWMODE_A].num_rates = spec->num_rates - 4;
862                 hwmodes[HWMODE_A].channels = &channels[14];
863                 hwmodes[HWMODE_A].rates = &rates[4];
864         }
865
866         if (spec->num_modes > HWMODE_G &&
867             ieee80211_register_hwmode(hw, &hwmodes[HWMODE_G]))
868                 goto exit_free_rates;
869
870         if (spec->num_modes > HWMODE_B &&
871             ieee80211_register_hwmode(hw, &hwmodes[HWMODE_B]))
872                 goto exit_free_rates;
873
874         if (spec->num_modes > HWMODE_A &&
875             ieee80211_register_hwmode(hw, &hwmodes[HWMODE_A]))
876                 goto exit_free_rates;
877
878         rt2x00dev->hwmodes = hwmodes;
879
880         return 0;
881
882 exit_free_rates:
883         kfree(rates);
884
885 exit_free_channels:
886         kfree(channels);
887
888 exit_free_modes:
889         kfree(hwmodes);
890
891 exit:
892         ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
893         return -ENOMEM;
894 }
895
896 static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
897 {
898         if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags))
899                 ieee80211_unregister_hw(rt2x00dev->hw);
900
901         if (likely(rt2x00dev->hwmodes)) {
902                 kfree(rt2x00dev->hwmodes->channels);
903                 kfree(rt2x00dev->hwmodes->rates);
904                 kfree(rt2x00dev->hwmodes);
905                 rt2x00dev->hwmodes = NULL;
906         }
907 }
908
909 static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
910 {
911         struct hw_mode_spec *spec = &rt2x00dev->spec;
912         int status;
913
914         /*
915          * Initialize HW modes.
916          */
917         status = rt2x00lib_probe_hw_modes(rt2x00dev, spec);
918         if (status)
919                 return status;
920
921         /*
922          * Register HW.
923          */
924         status = ieee80211_register_hw(rt2x00dev->hw);
925         if (status) {
926                 rt2x00lib_remove_hw(rt2x00dev);
927                 return status;
928         }
929
930         __set_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags);
931
932         return 0;
933 }
934
935 /*
936  * Initialization/uninitialization handlers.
937  */
938 static int rt2x00lib_alloc_entries(struct data_ring *ring,
939                                    const u16 max_entries, const u16 data_size,
940                                    const u16 desc_size)
941 {
942         struct data_entry *entry;
943         unsigned int i;
944
945         ring->stats.limit = max_entries;
946         ring->data_size = data_size;
947         ring->desc_size = desc_size;
948
949         /*
950          * Allocate all ring entries.
951          */
952         entry = kzalloc(ring->stats.limit * sizeof(*entry), GFP_KERNEL);
953         if (!entry)
954                 return -ENOMEM;
955
956         for (i = 0; i < ring->stats.limit; i++) {
957                 entry[i].flags = 0;
958                 entry[i].ring = ring;
959                 entry[i].skb = NULL;
960         }
961
962         ring->entry = entry;
963
964         return 0;
965 }
966
967 static int rt2x00lib_alloc_ring_entries(struct rt2x00_dev *rt2x00dev)
968 {
969         struct data_ring *ring;
970
971         /*
972          * Allocate the RX ring.
973          */
974         if (rt2x00lib_alloc_entries(rt2x00dev->rx, RX_ENTRIES, DATA_FRAME_SIZE,
975                                     rt2x00dev->ops->rxd_size))
976                 return -ENOMEM;
977
978         /*
979          * First allocate the TX rings.
980          */
981         txring_for_each(rt2x00dev, ring) {
982                 if (rt2x00lib_alloc_entries(ring, TX_ENTRIES, DATA_FRAME_SIZE,
983                                             rt2x00dev->ops->txd_size))
984                         return -ENOMEM;
985         }
986
987         if (!test_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags))
988                 return 0;
989
990         /*
991          * Allocate the BEACON ring.
992          */
993         if (rt2x00lib_alloc_entries(&rt2x00dev->bcn[0], BEACON_ENTRIES,
994                                     MGMT_FRAME_SIZE, rt2x00dev->ops->txd_size))
995                 return -ENOMEM;
996
997         /*
998          * Allocate the Atim ring.
999          */
1000         if (rt2x00lib_alloc_entries(&rt2x00dev->bcn[1], ATIM_ENTRIES,
1001                                     DATA_FRAME_SIZE, rt2x00dev->ops->txd_size))
1002                 return -ENOMEM;
1003
1004         return 0;
1005 }
1006
1007 static void rt2x00lib_free_ring_entries(struct rt2x00_dev *rt2x00dev)
1008 {
1009         struct data_ring *ring;
1010
1011         ring_for_each(rt2x00dev, ring) {
1012                 kfree(ring->entry);
1013                 ring->entry = NULL;
1014         }
1015 }
1016
1017 void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
1018 {
1019         if (!__test_and_clear_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
1020                 return;
1021
1022         /*
1023          * Unregister rfkill.
1024          */
1025         rt2x00rfkill_unregister(rt2x00dev);
1026
1027         /*
1028          * Allow the HW to uninitialize.
1029          */
1030         rt2x00dev->ops->lib->uninitialize(rt2x00dev);
1031
1032         /*
1033          * Free allocated ring entries.
1034          */
1035         rt2x00lib_free_ring_entries(rt2x00dev);
1036 }
1037
1038 int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
1039 {
1040         int status;
1041
1042         if (test_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
1043                 return 0;
1044
1045         /*
1046          * Allocate all ring entries.
1047          */
1048         status = rt2x00lib_alloc_ring_entries(rt2x00dev);
1049         if (status) {
1050                 ERROR(rt2x00dev, "Ring entries allocation failed.\n");
1051                 return status;
1052         }
1053
1054         /*
1055          * Initialize the device.
1056          */
1057         status = rt2x00dev->ops->lib->initialize(rt2x00dev);
1058         if (status)
1059                 goto exit;
1060
1061         __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
1062
1063         /*
1064          * Register the rfkill handler.
1065          */
1066         status = rt2x00rfkill_register(rt2x00dev);
1067         if (status)
1068                 goto exit_unitialize;
1069
1070         return 0;
1071
1072 exit_unitialize:
1073         rt2x00lib_uninitialize(rt2x00dev);
1074
1075 exit:
1076         rt2x00lib_free_ring_entries(rt2x00dev);
1077
1078         return status;
1079 }
1080
1081 /*
1082  * driver allocation handlers.
1083  */
1084 static int rt2x00lib_alloc_rings(struct rt2x00_dev *rt2x00dev)
1085 {
1086         struct data_ring *ring;
1087
1088         /*
1089          * We need the following rings:
1090          * RX: 1
1091          * TX: hw->queues
1092          * Beacon: 1 (if required)
1093          * Atim: 1 (if required)
1094          */
1095         rt2x00dev->data_rings = 1 + rt2x00dev->hw->queues +
1096             (2 * test_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags));
1097
1098         ring = kzalloc(rt2x00dev->data_rings * sizeof(*ring), GFP_KERNEL);
1099         if (!ring) {
1100                 ERROR(rt2x00dev, "Ring allocation failed.\n");
1101                 return -ENOMEM;
1102         }
1103
1104         /*
1105          * Initialize pointers
1106          */
1107         rt2x00dev->rx = ring;
1108         rt2x00dev->tx = &rt2x00dev->rx[1];
1109         if (test_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags))
1110                 rt2x00dev->bcn = &rt2x00dev->tx[rt2x00dev->hw->queues];
1111
1112         /*
1113          * Initialize ring parameters.
1114          * cw_min: 2^5 = 32.
1115          * cw_max: 2^10 = 1024.
1116          */
1117         ring_for_each(rt2x00dev, ring) {
1118                 ring->rt2x00dev = rt2x00dev;
1119                 ring->tx_params.aifs = 2;
1120                 ring->tx_params.cw_min = 5;
1121                 ring->tx_params.cw_max = 10;
1122         }
1123
1124         return 0;
1125 }
1126
1127 static void rt2x00lib_free_rings(struct rt2x00_dev *rt2x00dev)
1128 {
1129         kfree(rt2x00dev->rx);
1130         rt2x00dev->rx = NULL;
1131         rt2x00dev->tx = NULL;
1132         rt2x00dev->bcn = NULL;
1133 }
1134
1135 int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1136 {
1137         int retval = -ENOMEM;
1138
1139         /*
1140          * Let the driver probe the device to detect the capabilities.
1141          */
1142         retval = rt2x00dev->ops->lib->probe_hw(rt2x00dev);
1143         if (retval) {
1144                 ERROR(rt2x00dev, "Failed to allocate device.\n");
1145                 goto exit;
1146         }
1147
1148         /*
1149          * Initialize configuration work.
1150          */
1151         INIT_WORK(&rt2x00dev->beacon_work, rt2x00lib_beacondone_scheduled);
1152         INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled);
1153         INIT_WORK(&rt2x00dev->config_work, rt2x00lib_configuration_scheduled);
1154         INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
1155
1156         /*
1157          * Reset current working type.
1158          */
1159         rt2x00dev->interface.type = INVALID_INTERFACE;
1160
1161         /*
1162          * Allocate ring array.
1163          */
1164         retval = rt2x00lib_alloc_rings(rt2x00dev);
1165         if (retval)
1166                 goto exit;
1167
1168         /*
1169          * Initialize ieee80211 structure.
1170          */
1171         retval = rt2x00lib_probe_hw(rt2x00dev);
1172         if (retval) {
1173                 ERROR(rt2x00dev, "Failed to initialize hw.\n");
1174                 goto exit;
1175         }
1176
1177         /*
1178          * Allocatie rfkill.
1179          */
1180         retval = rt2x00rfkill_allocate(rt2x00dev);
1181         if (retval)
1182                 goto exit;
1183
1184         /*
1185          * Open the debugfs entry.
1186          */
1187         rt2x00debug_register(rt2x00dev);
1188
1189         __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
1190
1191         return 0;
1192
1193 exit:
1194         rt2x00lib_remove_dev(rt2x00dev);
1195
1196         return retval;
1197 }
1198 EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
1199
1200 void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
1201 {
1202         __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
1203
1204         /*
1205          * Disable radio.
1206          */
1207         rt2x00lib_disable_radio(rt2x00dev);
1208
1209         /*
1210          * Uninitialize device.
1211          */
1212         rt2x00lib_uninitialize(rt2x00dev);
1213
1214         /*
1215          * Close debugfs entry.
1216          */
1217         rt2x00debug_deregister(rt2x00dev);
1218
1219         /*
1220          * Free rfkill
1221          */
1222         rt2x00rfkill_free(rt2x00dev);
1223
1224         /*
1225          * Free ieee80211_hw memory.
1226          */
1227         rt2x00lib_remove_hw(rt2x00dev);
1228
1229         /*
1230          * Free firmware image.
1231          */
1232         rt2x00lib_free_firmware(rt2x00dev);
1233
1234         /*
1235          * Free ring structures.
1236          */
1237         rt2x00lib_free_rings(rt2x00dev);
1238 }
1239 EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
1240
1241 /*
1242  * Device state handlers
1243  */
1244 #ifdef CONFIG_PM
1245 int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
1246 {
1247         int retval;
1248
1249         NOTICE(rt2x00dev, "Going to sleep.\n");
1250         __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
1251
1252         /*
1253          * Only continue if mac80211 has open interfaces.
1254          */
1255         if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
1256                 goto exit;
1257         __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags);
1258
1259         /*
1260          * Disable radio and unitialize all items
1261          * that must be recreated on resume.
1262          */
1263         rt2x00mac_stop(rt2x00dev->hw);
1264         rt2x00lib_uninitialize(rt2x00dev);
1265         rt2x00debug_deregister(rt2x00dev);
1266
1267 exit:
1268         /*
1269          * Set device mode to sleep for power management.
1270          */
1271         retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP);
1272         if (retval)
1273                 return retval;
1274
1275         return 0;
1276 }
1277 EXPORT_SYMBOL_GPL(rt2x00lib_suspend);
1278
1279 int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
1280 {
1281         struct interface *intf = &rt2x00dev->interface;
1282         int retval;
1283
1284         NOTICE(rt2x00dev, "Waking up.\n");
1285         __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
1286
1287         /*
1288          * Open the debugfs entry.
1289          */
1290         rt2x00debug_register(rt2x00dev);
1291
1292         /*
1293          * Only continue if mac80211 had open interfaces.
1294          */
1295         if (!__test_and_clear_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags))
1296                 return 0;
1297
1298         /*
1299          * Reinitialize device and all active interfaces.
1300          */
1301         retval = rt2x00mac_start(rt2x00dev->hw);
1302         if (retval)
1303                 goto exit;
1304
1305         /*
1306          * Reconfigure device.
1307          */
1308         rt2x00lib_config(rt2x00dev, &rt2x00dev->hw->conf, 1);
1309         if (!rt2x00dev->hw->conf.radio_enabled)
1310                 rt2x00lib_disable_radio(rt2x00dev);
1311
1312         rt2x00lib_config_mac_addr(rt2x00dev, intf->mac);
1313         rt2x00lib_config_bssid(rt2x00dev, intf->bssid);
1314         rt2x00lib_config_type(rt2x00dev, intf->type);
1315
1316         /*
1317          * It is possible that during that mac80211 has attempted
1318          * to send frames while we were suspending or resuming.
1319          * In that case we have disabled the TX queue and should
1320          * now enable it again
1321          */
1322         ieee80211_start_queues(rt2x00dev->hw);
1323
1324         /*
1325          * When in Master or Ad-hoc mode,
1326          * restart Beacon transmitting by faking a beacondone event.
1327          */
1328         if (intf->type == IEEE80211_IF_TYPE_AP ||
1329             intf->type == IEEE80211_IF_TYPE_IBSS)
1330                 rt2x00lib_beacondone(rt2x00dev);
1331
1332         return 0;
1333
1334 exit:
1335         rt2x00lib_disable_radio(rt2x00dev);
1336         rt2x00lib_uninitialize(rt2x00dev);
1337         rt2x00debug_deregister(rt2x00dev);
1338
1339         return retval;
1340 }
1341 EXPORT_SYMBOL_GPL(rt2x00lib_resume);
1342 #endif /* CONFIG_PM */
1343
1344 /*
1345  * rt2x00lib module information.
1346  */
1347 MODULE_AUTHOR(DRV_PROJECT);
1348 MODULE_VERSION(DRV_VERSION);
1349 MODULE_DESCRIPTION("rt2x00 library");
1350 MODULE_LICENSE("GPL");