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