2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 generic device routines.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include "rt2x00lib.h"
31 #include "rt2x00dump.h"
36 struct data_ring
*rt2x00lib_get_ring(struct rt2x00_dev
*rt2x00dev
,
37 const unsigned int queue
)
39 int beacon
= test_bit(DRIVER_REQUIRE_BEACON_RING
, &rt2x00dev
->flags
);
42 * Check if we are requesting a reqular TX ring,
43 * or if we are requesting a Beacon or Atim ring.
44 * For Atim rings, we should check if it is supported.
46 if (queue
< rt2x00dev
->hw
->queues
&& rt2x00dev
->tx
)
47 return &rt2x00dev
->tx
[queue
];
49 if (!rt2x00dev
->bcn
|| !beacon
)
52 if (queue
== IEEE80211_TX_QUEUE_BEACON
)
53 return &rt2x00dev
->bcn
[0];
54 else if (queue
== IEEE80211_TX_QUEUE_AFTER_BEACON
)
55 return &rt2x00dev
->bcn
[1];
59 EXPORT_SYMBOL_GPL(rt2x00lib_get_ring
);
62 * Link tuning handlers
64 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
65 static void rt2x00lib_start_link_tuner(struct rt2x00_dev
*rt2x00dev
)
67 void rt2x00lib_reset_link_tuner(struct rt2x00_dev
*rt2x00dev
)
68 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
70 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
72 if (!test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
76 * Reset link information.
77 * Both the currently active vgc level as well as
78 * the link tuner counter should be reset. Resetting
79 * the counter is important for devices where the
80 * device should only perform link tuning during the
81 * first minute after being enabled.
83 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
84 rt2x00dev
->link
.count
= 0;
85 rt2x00dev
->link
.vgc_level
= 0;
87 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
90 * Reset the link tuner.
92 rt2x00dev
->ops
->lib
->reset_tuner(rt2x00dev
);
95 static void rt2x00lib_start_link_tuner(struct rt2x00_dev
*rt2x00dev
)
98 * Clear all (possibly) pre-existing quality statistics.
100 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
101 memset(&rt2x00dev
->link
.qual
, 0, sizeof(rt2x00dev
->link
.qual
));
104 * The RX and TX percentage should start at 50%
105 * this will assure we will get at least get some
106 * decent value when the link tuner starts.
107 * The value will be dropped and overwritten with
108 * the correct (measured )value anyway during the
109 * first run of the link tuner.
111 rt2x00dev
->link
.qual
.rx_percentage
= 50;
112 rt2x00dev
->link
.qual
.tx_percentage
= 50;
114 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
116 * Reset the link tuner.
118 rt2x00dev
->ops
->lib
->reset_tuner(rt2x00dev
);
120 rt2x00lib_reset_link_tuner(rt2x00dev
);
121 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
123 queue_delayed_work(rt2x00dev
->hw
->workqueue
,
124 &rt2x00dev
->link
.work
, LINK_TUNE_INTERVAL
);
127 static void rt2x00lib_stop_link_tuner(struct rt2x00_dev
*rt2x00dev
)
129 cancel_delayed_work_sync(&rt2x00dev
->link
.work
);
132 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
133 void rt2x00lib_reset_link_tuner(struct rt2x00_dev
*rt2x00dev
)
135 if (!test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
138 rt2x00lib_stop_link_tuner(rt2x00dev
);
139 rt2x00lib_start_link_tuner(rt2x00dev
);
143 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
145 * Ring initialization
147 static void rt2x00lib_init_rxrings(struct rt2x00_dev
*rt2x00dev
)
149 struct data_ring
*ring
= rt2x00dev
->rx
;
152 if (!rt2x00dev
->ops
->lib
->init_rxentry
)
156 memset(ring
->data_addr
, 0, rt2x00_get_ring_size(ring
));
158 for (i
= 0; i
< ring
->stats
.limit
; i
++)
159 rt2x00dev
->ops
->lib
->init_rxentry(rt2x00dev
, &ring
->entry
[i
]);
161 rt2x00_ring_index_clear(ring
);
164 static void rt2x00lib_init_txrings(struct rt2x00_dev
*rt2x00dev
)
166 struct data_ring
*ring
;
169 if (!rt2x00dev
->ops
->lib
->init_txentry
)
172 txringall_for_each(rt2x00dev
, ring
) {
174 memset(ring
->data_addr
, 0, rt2x00_get_ring_size(ring
));
176 for (i
= 0; i
< ring
->stats
.limit
; i
++)
177 rt2x00dev
->ops
->lib
->init_txentry(rt2x00dev
,
180 rt2x00_ring_index_clear(ring
);
185 * Radio control handlers.
187 int rt2x00lib_enable_radio(struct rt2x00_dev
*rt2x00dev
)
192 * Don't enable the radio twice.
193 * And check if the hardware button has been disabled.
195 if (test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
) ||
196 test_bit(DEVICE_DISABLED_RADIO_HW
, &rt2x00dev
->flags
))
200 * Initialize all data rings.
202 rt2x00lib_init_rxrings(rt2x00dev
);
203 rt2x00lib_init_txrings(rt2x00dev
);
208 status
= rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
,
213 __set_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
);
218 rt2x00lib_toggle_rx(rt2x00dev
, STATE_RADIO_RX_ON
);
221 * Start the TX queues.
223 ieee80211_start_queues(rt2x00dev
->hw
);
228 void rt2x00lib_disable_radio(struct rt2x00_dev
*rt2x00dev
)
230 if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
234 * Stop all scheduled work.
236 if (work_pending(&rt2x00dev
->beacon_work
))
237 cancel_work_sync(&rt2x00dev
->beacon_work
);
238 if (work_pending(&rt2x00dev
->filter_work
))
239 cancel_work_sync(&rt2x00dev
->filter_work
);
240 if (work_pending(&rt2x00dev
->config_work
))
241 cancel_work_sync(&rt2x00dev
->config_work
);
244 * Stop the TX queues.
246 ieee80211_stop_queues(rt2x00dev
->hw
);
251 rt2x00lib_toggle_rx(rt2x00dev
, STATE_RADIO_RX_OFF
);
256 rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_RADIO_OFF
);
259 void rt2x00lib_toggle_rx(struct rt2x00_dev
*rt2x00dev
, enum dev_state state
)
262 * When we are disabling the RX, we should also stop the link tuner.
264 if (state
== STATE_RADIO_RX_OFF
)
265 rt2x00lib_stop_link_tuner(rt2x00dev
);
267 rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, state
);
270 * When we are enabling the RX, we should also start the link tuner.
272 if (state
== STATE_RADIO_RX_ON
&&
273 is_interface_present(&rt2x00dev
->interface
))
274 rt2x00lib_start_link_tuner(rt2x00dev
);
277 static void rt2x00lib_evaluate_antenna_sample(struct rt2x00_dev
*rt2x00dev
)
279 enum antenna rx
= rt2x00dev
->link
.ant
.active
.rx
;
280 enum antenna tx
= rt2x00dev
->link
.ant
.active
.tx
;
282 rt2x00_get_link_ant_rssi_history(&rt2x00dev
->link
, ANTENNA_A
);
284 rt2x00_get_link_ant_rssi_history(&rt2x00dev
->link
, ANTENNA_B
);
287 * We are done sampling. Now we should evaluate the results.
289 rt2x00dev
->link
.ant
.flags
&= ~ANTENNA_MODE_SAMPLE
;
292 * During the last period we have sampled the RSSI
293 * from both antenna's. It now is time to determine
294 * which antenna demonstrated the best performance.
295 * When we are already on the antenna with the best
296 * performance, then there really is nothing for us
299 if (sample_a
== sample_b
)
302 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
303 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_RX_DIVERSITY
) {
304 if (sample_a
> sample_b
&& rx
== ANTENNA_B
)
306 else if (rx
== ANTENNA_A
)
310 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_RX_DIVERSITY
)
311 rx
= (sample_a
> sample_b
) ? ANTENNA_A
: ANTENNA_B
;
312 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
314 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
315 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_TX_DIVERSITY
) {
316 if (sample_a
> sample_b
&& tx
== ANTENNA_B
)
318 else if (tx
== ANTENNA_A
)
322 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_TX_DIVERSITY
)
323 tx
= (sample_a
> sample_b
) ? ANTENNA_A
: ANTENNA_B
;
324 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
326 rt2x00lib_config_antenna(rt2x00dev
, rx
, tx
);
329 static void rt2x00lib_evaluate_antenna_eval(struct rt2x00_dev
*rt2x00dev
)
331 enum antenna rx
= rt2x00dev
->link
.ant
.active
.rx
;
332 enum antenna tx
= rt2x00dev
->link
.ant
.active
.tx
;
333 int rssi_curr
= rt2x00_get_link_ant_rssi(&rt2x00dev
->link
);
334 int rssi_old
= rt2x00_update_ant_rssi(&rt2x00dev
->link
, rssi_curr
);
337 * Legacy driver indicates that we should swap antenna's
338 * when the difference in RSSI is greater that 5. This
339 * also should be done when the RSSI was actually better
340 * then the previous sample.
341 * When the difference exceeds the threshold we should
342 * sample the rssi from the other antenna to make a valid
343 * comparison between the 2 antennas.
345 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
346 if ((rssi_curr
- rssi_old
) > -5 || (rssi_curr
- rssi_old
) < 5)
348 if (abs(rssi_curr
- rssi_old
) < 5)
349 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
352 rt2x00dev
->link
.ant
.flags
|= ANTENNA_MODE_SAMPLE
;
354 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_RX_DIVERSITY
)
355 rx
= (rx
== ANTENNA_A
) ? ANTENNA_B
: ANTENNA_A
;
357 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_TX_DIVERSITY
)
358 tx
= (tx
== ANTENNA_A
) ? ANTENNA_B
: ANTENNA_A
;
360 rt2x00lib_config_antenna(rt2x00dev
, rx
, tx
);
363 static void rt2x00lib_evaluate_antenna(struct rt2x00_dev
*rt2x00dev
)
366 * Determine if software diversity is enabled for
367 * either the TX or RX antenna (or both).
368 * Always perform this check since within the link
369 * tuner interval the configuration might have changed.
371 rt2x00dev
->link
.ant
.flags
&= ~ANTENNA_RX_DIVERSITY
;
372 rt2x00dev
->link
.ant
.flags
&= ~ANTENNA_TX_DIVERSITY
;
374 if (rt2x00dev
->hw
->conf
.antenna_sel_rx
== 0 &&
375 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
376 rt2x00dev
->default_ant
.rx
!= ANTENNA_SW_DIVERSITY
)
378 rt2x00dev
->default_ant
.rx
== ANTENNA_SW_DIVERSITY
)
379 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
380 rt2x00dev
->link
.ant
.flags
|= ANTENNA_RX_DIVERSITY
;
381 if (rt2x00dev
->hw
->conf
.antenna_sel_tx
== 0 &&
382 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
383 rt2x00dev
->default_ant
.tx
!= ANTENNA_SW_DIVERSITY
)
385 rt2x00dev
->default_ant
.tx
== ANTENNA_SW_DIVERSITY
)
386 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
387 rt2x00dev
->link
.ant
.flags
|= ANTENNA_TX_DIVERSITY
;
389 if (!(rt2x00dev
->link
.ant
.flags
& ANTENNA_RX_DIVERSITY
) &&
390 !(rt2x00dev
->link
.ant
.flags
& ANTENNA_TX_DIVERSITY
)) {
391 <<<<<<< HEAD
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
392 rt2x00dev
->link
.ant
.flags
&= ~ANTENNA_MODE_SAMPLE
;
394 rt2x00dev
->link
.ant
.flags
= 0;
395 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rt2x00
/rt2x00dev
.c
400 * If we have only sampled the data over the last period
401 * we should now harvest the data. Otherwise just evaluate
402 * the data. The latter should only be performed once
405 if (rt2x00dev
->link
.ant
.flags
& ANTENNA_MODE_SAMPLE
)
406 rt2x00lib_evaluate_antenna_sample(rt2x00dev
);
407 else if (rt2x00dev
->link
.count
& 1)
408 rt2x00lib_evaluate_antenna_eval(rt2x00dev
);
411 static void rt2x00lib_update_link_stats(struct link
*link
, int rssi
)
418 if (link
->qual
.avg_rssi
)
419 avg_rssi
= MOVING_AVERAGE(link
->qual
.avg_rssi
, rssi
, 8);
420 link
->qual
.avg_rssi
= avg_rssi
;
423 * Update antenna RSSI
425 if (link
->ant
.rssi_ant
)
426 rssi
= MOVING_AVERAGE(link
->ant
.rssi_ant
, rssi
, 8);
427 link
->ant
.rssi_ant
= rssi
;
430 static void rt2x00lib_precalculate_link_signal(struct link_qual
*qual
)
432 if (qual
->rx_failed
|| qual
->rx_success
)
433 qual
->rx_percentage
=
434 (qual
->rx_success
* 100) /
435 (qual
->rx_failed
+ qual
->rx_success
);
437 qual
->rx_percentage
= 50;
439 if (qual
->tx_failed
|| qual
->tx_success
)
440 qual
->tx_percentage
=
441 (qual
->tx_success
* 100) /
442 (qual
->tx_failed
+ qual
->tx_success
);
444 qual
->tx_percentage
= 50;
446 qual
->rx_success
= 0;
448 qual
->tx_success
= 0;
452 static int rt2x00lib_calculate_link_signal(struct rt2x00_dev
*rt2x00dev
,
455 int rssi_percentage
= 0;
459 * We need a positive value for the RSSI.
462 rssi
+= rt2x00dev
->rssi_offset
;
465 * Calculate the different percentages,
466 * which will be used for the signal.
468 if (rt2x00dev
->rssi_offset
)
469 rssi_percentage
= (rssi
* 100) / rt2x00dev
->rssi_offset
;
472 * Add the individual percentages and use the WEIGHT
473 * defines to calculate the current link signal.
475 signal
= ((WEIGHT_RSSI
* rssi_percentage
) +
476 (WEIGHT_TX
* rt2x00dev
->link
.qual
.tx_percentage
) +
477 (WEIGHT_RX
* rt2x00dev
->link
.qual
.rx_percentage
)) / 100;
479 return (signal
> 100) ? 100 : signal
;
482 static void rt2x00lib_link_tuner(struct work_struct
*work
)
484 struct rt2x00_dev
*rt2x00dev
=
485 container_of(work
, struct rt2x00_dev
, link
.work
.work
);
488 * When the radio is shutting down we should
489 * immediately cease all link tuning.
491 if (!test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
497 rt2x00dev
->ops
->lib
->link_stats(rt2x00dev
, &rt2x00dev
->link
.qual
);
498 rt2x00dev
->low_level_stats
.dot11FCSErrorCount
+=
499 rt2x00dev
->link
.qual
.rx_failed
;
502 * Only perform the link tuning when Link tuning
503 * has been enabled (This could have been disabled from the EEPROM).
505 if (!test_bit(CONFIG_DISABLE_LINK_TUNING
, &rt2x00dev
->flags
))
506 rt2x00dev
->ops
->lib
->link_tuner(rt2x00dev
);
509 <<<<<<< HEAD:drivers/net/wireless/rt2x00/rt2x00dev.c
510 * Evaluate antenna setup.
512 rt2x00lib_evaluate_antenna(rt2x00dev
);
516 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/wireless/rt2x00/rt2x00dev.c
517 * Precalculate a portion of the link signal which is
518 * in based on the tx/rx success/failure counters.
520 rt2x00lib_precalculate_link_signal(&rt2x00dev
->link
.qual
);
523 <<<<<<< HEAD:drivers/net/wireless/rt2x00/rt2x00dev.c
525 * Evaluate antenna setup, make this the last step since this could
526 * possibly reset some statistics.
528 rt2x00lib_evaluate_antenna(rt2x00dev
);
531 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/wireless/rt2x00/rt2x00dev.c
532 * Increase tuner counter, and reschedule the next link tuner run.
534 rt2x00dev
->link
.count
++;
535 queue_delayed_work(rt2x00dev
->hw
->workqueue
, &rt2x00dev
->link
.work
,
539 static void rt2x00lib_packetfilter_scheduled(struct work_struct
*work
)
541 struct rt2x00_dev
*rt2x00dev
=
542 container_of(work
, struct rt2x00_dev
, filter_work
);
543 unsigned int filter
= rt2x00dev
->packet_filter
;
546 * Since we had stored the filter inside interface.filter,
547 * we should now clear that field. Otherwise the driver will
548 * assume nothing has changed (*total_flags will be compared
549 * to interface.filter to determine if any action is required).
551 rt2x00dev
->packet_filter
= 0;
553 rt2x00dev
->ops
->hw
->configure_filter(rt2x00dev
->hw
,
554 filter
, &filter
, 0, NULL
);
557 static void rt2x00lib_configuration_scheduled(struct work_struct
*work
)
559 struct rt2x00_dev
*rt2x00dev
=
560 container_of(work
, struct rt2x00_dev
, config_work
);
561 struct ieee80211_bss_conf bss_conf
;
563 bss_conf
.use_short_preamble
=
564 test_bit(CONFIG_SHORT_PREAMBLE
, &rt2x00dev
->flags
);
567 * FIXME: shouldn't invoke it this way because all other contents
568 * of bss_conf is invalid.
570 rt2x00mac_bss_info_changed(rt2x00dev
->hw
, rt2x00dev
->interface
.id
,
571 &bss_conf
, BSS_CHANGED_ERP_PREAMBLE
);
575 * Interrupt context handlers.
577 static void rt2x00lib_beacondone_scheduled(struct work_struct
*work
)
579 struct rt2x00_dev
*rt2x00dev
=
580 container_of(work
, struct rt2x00_dev
, beacon_work
);
581 struct data_ring
*ring
=
582 rt2x00lib_get_ring(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
583 struct data_entry
*entry
= rt2x00_get_data_entry(ring
);
586 skb
= ieee80211_beacon_get(rt2x00dev
->hw
,
587 rt2x00dev
->interface
.id
,
588 &entry
->tx_status
.control
);
592 rt2x00dev
->ops
->hw
->beacon_update(rt2x00dev
->hw
, skb
,
593 &entry
->tx_status
.control
);
598 void rt2x00lib_beacondone(struct rt2x00_dev
*rt2x00dev
)
600 if (!test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
603 queue_work(rt2x00dev
->hw
->workqueue
, &rt2x00dev
->beacon_work
);
605 EXPORT_SYMBOL_GPL(rt2x00lib_beacondone
);
607 void rt2x00lib_txdone(struct data_entry
*entry
,
608 const int status
, const int retry
)
610 struct rt2x00_dev
*rt2x00dev
= entry
->ring
->rt2x00dev
;
611 struct ieee80211_tx_status
*tx_status
= &entry
->tx_status
;
612 struct ieee80211_low_level_stats
*stats
= &rt2x00dev
->low_level_stats
;
613 int success
= !!(status
== TX_SUCCESS
|| status
== TX_SUCCESS_RETRY
);
614 int fail
= !!(status
== TX_FAIL_RETRY
|| status
== TX_FAIL_INVALID
||
615 status
== TX_FAIL_OTHER
);
618 * Update TX statistics.
620 tx_status
->flags
= 0;
621 tx_status
->ack_signal
= 0;
622 tx_status
->excessive_retries
= (status
== TX_FAIL_RETRY
);
623 tx_status
->retry_count
= retry
;
624 rt2x00dev
->link
.qual
.tx_success
+= success
;
625 rt2x00dev
->link
.qual
.tx_failed
+= retry
+ fail
;
627 if (!(tx_status
->control
.flags
& IEEE80211_TXCTL_NO_ACK
)) {
629 tx_status
->flags
|= IEEE80211_TX_STATUS_ACK
;
631 stats
->dot11ACKFailureCount
++;
634 tx_status
->queue_length
= entry
->ring
->stats
.limit
;
635 tx_status
->queue_number
= tx_status
->control
.queue
;
637 if (tx_status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
639 stats
->dot11RTSSuccessCount
++;
641 stats
->dot11RTSFailureCount
++;
645 * Send the tx_status to mac80211 & debugfs.
646 * mac80211 will clean up the skb structure.
648 get_skb_desc(entry
->skb
)->frame_type
= DUMP_FRAME_TXDONE
;
649 rt2x00debug_dump_frame(rt2x00dev
, entry
->skb
);
650 ieee80211_tx_status_irqsafe(rt2x00dev
->hw
, entry
->skb
, tx_status
);
653 EXPORT_SYMBOL_GPL(rt2x00lib_txdone
);
655 void rt2x00lib_rxdone(struct data_entry
*entry
, struct sk_buff
*skb
,
656 struct rxdata_entry_desc
*desc
)
658 struct rt2x00_dev
*rt2x00dev
= entry
->ring
->rt2x00dev
;
659 struct ieee80211_rx_status
*rx_status
= &rt2x00dev
->rx_status
;
660 struct ieee80211_hw_mode
*mode
;
661 struct ieee80211_rate
*rate
;
662 struct ieee80211_hdr
*hdr
;
668 * Update RX statistics.
670 mode
= &rt2x00dev
->hwmodes
[rt2x00dev
->curr_hwmode
];
671 for (i
= 0; i
< mode
->num_rates
; i
++) {
672 rate
= &mode
->rates
[i
];
675 * When frame was received with an OFDM bitrate,
676 * the signal is the PLCP value. If it was received with
677 * a CCK bitrate the signal is the rate in 0.5kbit/s.
680 val
= DEVICE_GET_RATE_FIELD(rate
->val
, RATE
);
682 val
= DEVICE_GET_RATE_FIELD(rate
->val
, PLCP
);
684 if (val
== desc
->signal
) {
691 * Only update link status if this is a beacon frame carrying our bssid.
693 hdr
= (struct ieee80211_hdr
*)skb
->data
;
694 fc
= le16_to_cpu(hdr
->frame_control
);
695 if (is_beacon(fc
) && desc
->my_bss
)
696 rt2x00lib_update_link_stats(&rt2x00dev
->link
, desc
->rssi
);
698 rt2x00dev
->link
.qual
.rx_success
++;
700 rx_status
->rate
= val
;
702 rt2x00lib_calculate_link_signal(rt2x00dev
, desc
->rssi
);
703 rx_status
->ssi
= desc
->rssi
;
704 rx_status
->flag
= desc
->flags
;
705 rx_status
->antenna
= rt2x00dev
->link
.ant
.active
.rx
;
708 * Send frame to mac80211 & debugfs
710 get_skb_desc(skb
)->frame_type
= DUMP_FRAME_RXDONE
;
711 rt2x00debug_dump_frame(rt2x00dev
, skb
);
712 ieee80211_rx_irqsafe(rt2x00dev
->hw
, skb
, rx_status
);
714 EXPORT_SYMBOL_GPL(rt2x00lib_rxdone
);
717 * TX descriptor initializer
719 void rt2x00lib_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
721 struct ieee80211_tx_control
*control
)
723 struct txdata_entry_desc desc
;
724 struct skb_desc
*skbdesc
= get_skb_desc(skb
);
725 struct ieee80211_hdr
*ieee80211hdr
= skbdesc
->data
;
734 memset(&desc
, 0, sizeof(desc
));
736 desc
.cw_min
= skbdesc
->ring
->tx_params
.cw_min
;
737 desc
.cw_max
= skbdesc
->ring
->tx_params
.cw_max
;
738 desc
.aifs
= skbdesc
->ring
->tx_params
.aifs
;
743 if (control
->queue
< rt2x00dev
->hw
->queues
)
744 desc
.queue
= control
->queue
;
745 else if (control
->queue
== IEEE80211_TX_QUEUE_BEACON
||
746 control
->queue
== IEEE80211_TX_QUEUE_AFTER_BEACON
)
747 desc
.queue
= QUEUE_MGMT
;
749 desc
.queue
= QUEUE_OTHER
;
752 * Read required fields from ieee80211 header.
754 frame_control
= le16_to_cpu(ieee80211hdr
->frame_control
);
755 seq_ctrl
= le16_to_cpu(ieee80211hdr
->seq_ctrl
);
757 tx_rate
= control
->tx_rate
;
760 * Check whether this frame is to be acked
762 if (!(control
->flags
& IEEE80211_TXCTL_NO_ACK
))
763 __set_bit(ENTRY_TXD_ACK
, &desc
.flags
);
766 * Check if this is a RTS/CTS frame
768 if (is_rts_frame(frame_control
) || is_cts_frame(frame_control
)) {
769 __set_bit(ENTRY_TXD_BURST
, &desc
.flags
);
770 if (is_rts_frame(frame_control
)) {
771 __set_bit(ENTRY_TXD_RTS_FRAME
, &desc
.flags
);
772 __set_bit(ENTRY_TXD_ACK
, &desc
.flags
);
774 __clear_bit(ENTRY_TXD_ACK
, &desc
.flags
);
775 if (control
->rts_cts_rate
)
776 tx_rate
= control
->rts_cts_rate
;
782 if (DEVICE_GET_RATE_FIELD(tx_rate
, RATEMASK
) & DEV_OFDM_RATEMASK
)
783 __set_bit(ENTRY_TXD_OFDM_RATE
, &desc
.flags
);
786 * Check if more fragments are pending
788 if (ieee80211_get_morefrag(ieee80211hdr
)) {
789 __set_bit(ENTRY_TXD_BURST
, &desc
.flags
);
790 __set_bit(ENTRY_TXD_MORE_FRAG
, &desc
.flags
);
794 * Beacons and probe responses require the tsf timestamp
795 * to be inserted into the frame.
797 if (control
->queue
== IEEE80211_TX_QUEUE_BEACON
||
798 is_probe_resp(frame_control
))
799 __set_bit(ENTRY_TXD_REQ_TIMESTAMP
, &desc
.flags
);
802 * Determine with what IFS priority this frame should be send.
803 * Set ifs to IFS_SIFS when the this is not the first fragment,
804 * or this fragment came after RTS/CTS.
806 if ((seq_ctrl
& IEEE80211_SCTL_FRAG
) > 0 ||
807 test_bit(ENTRY_TXD_RTS_FRAME
, &desc
.flags
))
810 desc
.ifs
= IFS_BACKOFF
;
814 * Length calculation depends on OFDM/CCK rate.
816 desc
.signal
= DEVICE_GET_RATE_FIELD(tx_rate
, PLCP
);
819 length
= skbdesc
->data_len
+ FCS_LEN
;
820 if (test_bit(ENTRY_TXD_OFDM_RATE
, &desc
.flags
)) {
821 desc
.length_high
= (length
>> 6) & 0x3f;
822 desc
.length_low
= length
& 0x3f;
824 bitrate
= DEVICE_GET_RATE_FIELD(tx_rate
, RATE
);
827 * Convert length to microseconds.
829 residual
= get_duration_res(length
, bitrate
);
830 duration
= get_duration(length
, bitrate
);
836 * Check if we need to set the Length Extension
838 if (bitrate
== 110 && residual
<= 30)
839 desc
.service
|= 0x80;
842 desc
.length_high
= (duration
>> 8) & 0xff;
843 desc
.length_low
= duration
& 0xff;
846 * When preamble is enabled we should set the
847 * preamble bit for the signal.
849 if (DEVICE_GET_RATE_FIELD(tx_rate
, PREAMBLE
))
853 rt2x00dev
->ops
->lib
->write_tx_desc(rt2x00dev
, skb
, &desc
, control
);
858 skbdesc
->entry
->skb
= skb
;
859 memcpy(&skbdesc
->entry
->tx_status
.control
, control
, sizeof(*control
));
862 * The frame has been completely initialized and ready
863 * for sending to the device. The caller will push the
864 * frame to the device, but we are going to push the
865 * frame to debugfs here.
867 skbdesc
->frame_type
= DUMP_FRAME_TX
;
868 rt2x00debug_dump_frame(rt2x00dev
, skb
);
870 EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc
);
873 * Driver initialization handlers.
875 static void rt2x00lib_channel(struct ieee80211_channel
*entry
,
876 const int channel
, const int tx_power
,
879 entry
->chan
= channel
;
881 entry
->freq
= 2407 + (5 * channel
);
883 entry
->freq
= 5000 + (5 * channel
);
886 IEEE80211_CHAN_W_IBSS
|
887 IEEE80211_CHAN_W_ACTIVE_SCAN
|
888 IEEE80211_CHAN_W_SCAN
;
889 entry
->power_level
= tx_power
;
890 entry
->antenna_max
= 0xff;
893 static void rt2x00lib_rate(struct ieee80211_rate
*entry
,
894 const int rate
, const int mask
,
895 const int plcp
, const int flags
)
899 DEVICE_SET_RATE_FIELD(rate
, RATE
) |
900 DEVICE_SET_RATE_FIELD(mask
, RATEMASK
) |
901 DEVICE_SET_RATE_FIELD(plcp
, PLCP
);
902 entry
->flags
= flags
;
903 entry
->val2
= entry
->val
;
904 if (entry
->flags
& IEEE80211_RATE_PREAMBLE2
)
905 entry
->val2
|= DEVICE_SET_RATE_FIELD(1, PREAMBLE
);
906 entry
->min_rssi_ack
= 0;
907 entry
->min_rssi_ack_delta
= 0;
910 static int rt2x00lib_probe_hw_modes(struct rt2x00_dev
*rt2x00dev
,
911 struct hw_mode_spec
*spec
)
913 struct ieee80211_hw
*hw
= rt2x00dev
->hw
;
914 struct ieee80211_hw_mode
*hwmodes
;
915 struct ieee80211_channel
*channels
;
916 struct ieee80211_rate
*rates
;
918 unsigned char tx_power
;
920 hwmodes
= kzalloc(sizeof(*hwmodes
) * spec
->num_modes
, GFP_KERNEL
);
924 channels
= kzalloc(sizeof(*channels
) * spec
->num_channels
, GFP_KERNEL
);
926 goto exit_free_modes
;
928 rates
= kzalloc(sizeof(*rates
) * spec
->num_rates
, GFP_KERNEL
);
930 goto exit_free_channels
;
933 * Initialize Rate list.
935 rt2x00lib_rate(&rates
[0], 10, DEV_RATEMASK_1MB
,
936 0x00, IEEE80211_RATE_CCK
);
937 rt2x00lib_rate(&rates
[1], 20, DEV_RATEMASK_2MB
,
938 0x01, IEEE80211_RATE_CCK_2
);
939 rt2x00lib_rate(&rates
[2], 55, DEV_RATEMASK_5_5MB
,
940 0x02, IEEE80211_RATE_CCK_2
);
941 rt2x00lib_rate(&rates
[3], 110, DEV_RATEMASK_11MB
,
942 0x03, IEEE80211_RATE_CCK_2
);
944 if (spec
->num_rates
> 4) {
945 rt2x00lib_rate(&rates
[4], 60, DEV_RATEMASK_6MB
,
946 0x0b, IEEE80211_RATE_OFDM
);
947 rt2x00lib_rate(&rates
[5], 90, DEV_RATEMASK_9MB
,
948 0x0f, IEEE80211_RATE_OFDM
);
949 rt2x00lib_rate(&rates
[6], 120, DEV_RATEMASK_12MB
,
950 0x0a, IEEE80211_RATE_OFDM
);
951 rt2x00lib_rate(&rates
[7], 180, DEV_RATEMASK_18MB
,
952 0x0e, IEEE80211_RATE_OFDM
);
953 rt2x00lib_rate(&rates
[8], 240, DEV_RATEMASK_24MB
,
954 0x09, IEEE80211_RATE_OFDM
);
955 rt2x00lib_rate(&rates
[9], 360, DEV_RATEMASK_36MB
,
956 0x0d, IEEE80211_RATE_OFDM
);
957 rt2x00lib_rate(&rates
[10], 480, DEV_RATEMASK_48MB
,
958 0x08, IEEE80211_RATE_OFDM
);
959 rt2x00lib_rate(&rates
[11], 540, DEV_RATEMASK_54MB
,
960 0x0c, IEEE80211_RATE_OFDM
);
964 * Initialize Channel list.
966 for (i
= 0; i
< spec
->num_channels
; i
++) {
967 if (spec
->channels
[i
].channel
<= 14)
968 tx_power
= spec
->tx_power_bg
[i
];
969 else if (spec
->tx_power_a
)
970 tx_power
= spec
->tx_power_a
[i
];
972 tx_power
= spec
->tx_power_default
;
974 rt2x00lib_channel(&channels
[i
],
975 spec
->channels
[i
].channel
, tx_power
, i
);
979 * Intitialize 802.11b
983 if (spec
->num_modes
> HWMODE_B
) {
984 hwmodes
[HWMODE_B
].mode
= MODE_IEEE80211B
;
985 hwmodes
[HWMODE_B
].num_channels
= 14;
986 hwmodes
[HWMODE_B
].num_rates
= 4;
987 hwmodes
[HWMODE_B
].channels
= channels
;
988 hwmodes
[HWMODE_B
].rates
= rates
;
992 * Intitialize 802.11g
996 if (spec
->num_modes
> HWMODE_G
) {
997 hwmodes
[HWMODE_G
].mode
= MODE_IEEE80211G
;
998 hwmodes
[HWMODE_G
].num_channels
= 14;
999 hwmodes
[HWMODE_G
].num_rates
= spec
->num_rates
;
1000 hwmodes
[HWMODE_G
].channels
= channels
;
1001 hwmodes
[HWMODE_G
].rates
= rates
;
1005 * Intitialize 802.11a
1007 * Channels: OFDM, UNII, HiperLAN2.
1009 if (spec
->num_modes
> HWMODE_A
) {
1010 hwmodes
[HWMODE_A
].mode
= MODE_IEEE80211A
;
1011 hwmodes
[HWMODE_A
].num_channels
= spec
->num_channels
- 14;
1012 hwmodes
[HWMODE_A
].num_rates
= spec
->num_rates
- 4;
1013 hwmodes
[HWMODE_A
].channels
= &channels
[14];
1014 hwmodes
[HWMODE_A
].rates
= &rates
[4];
1017 if (spec
->num_modes
> HWMODE_G
&&
1018 ieee80211_register_hwmode(hw
, &hwmodes
[HWMODE_G
]))
1019 goto exit_free_rates
;
1021 if (spec
->num_modes
> HWMODE_B
&&
1022 ieee80211_register_hwmode(hw
, &hwmodes
[HWMODE_B
]))
1023 goto exit_free_rates
;
1025 if (spec
->num_modes
> HWMODE_A
&&
1026 ieee80211_register_hwmode(hw
, &hwmodes
[HWMODE_A
]))
1027 goto exit_free_rates
;
1029 rt2x00dev
->hwmodes
= hwmodes
;
1043 ERROR(rt2x00dev
, "Allocation ieee80211 modes failed.\n");
1047 static void rt2x00lib_remove_hw(struct rt2x00_dev
*rt2x00dev
)
1049 if (test_bit(DEVICE_REGISTERED_HW
, &rt2x00dev
->flags
))
1050 ieee80211_unregister_hw(rt2x00dev
->hw
);
1052 if (likely(rt2x00dev
->hwmodes
)) {
1053 kfree(rt2x00dev
->hwmodes
->channels
);
1054 kfree(rt2x00dev
->hwmodes
->rates
);
1055 kfree(rt2x00dev
->hwmodes
);
1056 rt2x00dev
->hwmodes
= NULL
;
1060 static int rt2x00lib_probe_hw(struct rt2x00_dev
*rt2x00dev
)
1062 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
1066 * Initialize HW modes.
1068 status
= rt2x00lib_probe_hw_modes(rt2x00dev
, spec
);
1075 status
= ieee80211_register_hw(rt2x00dev
->hw
);
1077 rt2x00lib_remove_hw(rt2x00dev
);
1081 __set_bit(DEVICE_REGISTERED_HW
, &rt2x00dev
->flags
);
1087 * Initialization/uninitialization handlers.
1089 static int rt2x00lib_alloc_entries(struct data_ring
*ring
,
1090 const u16 max_entries
, const u16 data_size
,
1091 const u16 desc_size
)
1093 struct data_entry
*entry
;
1096 ring
->stats
.limit
= max_entries
;
1097 ring
->data_size
= data_size
;
1098 ring
->desc_size
= desc_size
;
1101 * Allocate all ring entries.
1103 entry
= kzalloc(ring
->stats
.limit
* sizeof(*entry
), GFP_KERNEL
);
1107 for (i
= 0; i
< ring
->stats
.limit
; i
++) {
1109 entry
[i
].ring
= ring
;
1110 entry
[i
].skb
= NULL
;
1111 entry
[i
].entry_idx
= i
;
1114 ring
->entry
= entry
;
1119 static int rt2x00lib_alloc_ring_entries(struct rt2x00_dev
*rt2x00dev
)
1121 struct data_ring
*ring
;
1124 * Allocate the RX ring.
1126 if (rt2x00lib_alloc_entries(rt2x00dev
->rx
, RX_ENTRIES
, DATA_FRAME_SIZE
,
1127 rt2x00dev
->ops
->rxd_size
))
1131 * First allocate the TX rings.
1133 txring_for_each(rt2x00dev
, ring
) {
1134 if (rt2x00lib_alloc_entries(ring
, TX_ENTRIES
, DATA_FRAME_SIZE
,
1135 rt2x00dev
->ops
->txd_size
))
1139 if (!test_bit(DRIVER_REQUIRE_BEACON_RING
, &rt2x00dev
->flags
))
1143 * Allocate the BEACON ring.
1145 if (rt2x00lib_alloc_entries(&rt2x00dev
->bcn
[0], BEACON_ENTRIES
,
1146 MGMT_FRAME_SIZE
, rt2x00dev
->ops
->txd_size
))
1150 * Allocate the Atim ring.
1152 if (rt2x00lib_alloc_entries(&rt2x00dev
->bcn
[1], ATIM_ENTRIES
,
1153 DATA_FRAME_SIZE
, rt2x00dev
->ops
->txd_size
))
1159 static void rt2x00lib_free_ring_entries(struct rt2x00_dev
*rt2x00dev
)
1161 struct data_ring
*ring
;
1163 ring_for_each(rt2x00dev
, ring
) {
1169 static void rt2x00lib_uninitialize(struct rt2x00_dev
*rt2x00dev
)
1171 if (!__test_and_clear_bit(DEVICE_INITIALIZED
, &rt2x00dev
->flags
))
1175 * Unregister rfkill.
1177 rt2x00rfkill_unregister(rt2x00dev
);
1180 * Allow the HW to uninitialize.
1182 rt2x00dev
->ops
->lib
->uninitialize(rt2x00dev
);
1185 * Free allocated ring entries.
1187 rt2x00lib_free_ring_entries(rt2x00dev
);
1190 static int rt2x00lib_initialize(struct rt2x00_dev
*rt2x00dev
)
1194 if (test_bit(DEVICE_INITIALIZED
, &rt2x00dev
->flags
))
1198 * Allocate all ring entries.
1200 status
= rt2x00lib_alloc_ring_entries(rt2x00dev
);
1202 ERROR(rt2x00dev
, "Ring entries allocation failed.\n");
1207 * Initialize the device.
1209 status
= rt2x00dev
->ops
->lib
->initialize(rt2x00dev
);
1213 __set_bit(DEVICE_INITIALIZED
, &rt2x00dev
->flags
);
1216 * Register the rfkill handler.
1218 status
= rt2x00rfkill_register(rt2x00dev
);
1220 goto exit_unitialize
;
1225 rt2x00lib_uninitialize(rt2x00dev
);
1228 rt2x00lib_free_ring_entries(rt2x00dev
);
1233 int rt2x00lib_start(struct rt2x00_dev
*rt2x00dev
)
1237 if (test_bit(DEVICE_STARTED
, &rt2x00dev
->flags
))
1241 * If this is the first interface which is added,
1242 * we should load the firmware now.
1244 if (test_bit(DRIVER_REQUIRE_FIRMWARE
, &rt2x00dev
->flags
)) {
1245 retval
= rt2x00lib_load_firmware(rt2x00dev
);
1251 * Initialize the device.
1253 retval
= rt2x00lib_initialize(rt2x00dev
);
1260 retval
= rt2x00lib_enable_radio(rt2x00dev
);
1262 rt2x00lib_uninitialize(rt2x00dev
);
1266 __set_bit(DEVICE_STARTED
, &rt2x00dev
->flags
);
1271 void rt2x00lib_stop(struct rt2x00_dev
*rt2x00dev
)
1273 if (!test_bit(DEVICE_STARTED
, &rt2x00dev
->flags
))
1277 * Perhaps we can add something smarter here,
1278 * but for now just disabling the radio should do.
1280 rt2x00lib_disable_radio(rt2x00dev
);
1282 __clear_bit(DEVICE_STARTED
, &rt2x00dev
->flags
);
1286 * driver allocation handlers.
1288 static int rt2x00lib_alloc_rings(struct rt2x00_dev
*rt2x00dev
)
1290 struct data_ring
*ring
;
1294 * We need the following rings:
1297 * Beacon: 1 (if required)
1298 * Atim: 1 (if required)
1300 rt2x00dev
->data_rings
= 1 + rt2x00dev
->hw
->queues
+
1301 (2 * test_bit(DRIVER_REQUIRE_BEACON_RING
, &rt2x00dev
->flags
));
1303 ring
= kzalloc(rt2x00dev
->data_rings
* sizeof(*ring
), GFP_KERNEL
);
1305 ERROR(rt2x00dev
, "Ring allocation failed.\n");
1310 * Initialize pointers
1312 rt2x00dev
->rx
= ring
;
1313 rt2x00dev
->tx
= &rt2x00dev
->rx
[1];
1314 if (test_bit(DRIVER_REQUIRE_BEACON_RING
, &rt2x00dev
->flags
))
1315 rt2x00dev
->bcn
= &rt2x00dev
->tx
[rt2x00dev
->hw
->queues
];
1318 * Initialize ring parameters.
1320 * TX: queue_idx = IEEE80211_TX_QUEUE_DATA0 + index
1321 * TX: cw_min: 2^5 = 32.
1322 * TX: cw_max: 2^10 = 1024.
1324 rt2x00dev
->rx
->rt2x00dev
= rt2x00dev
;
1325 rt2x00dev
->rx
->queue_idx
= 0;
1327 index
= IEEE80211_TX_QUEUE_DATA0
;
1328 txring_for_each(rt2x00dev
, ring
) {
1329 ring
->rt2x00dev
= rt2x00dev
;
1330 ring
->queue_idx
= index
++;
1331 ring
->tx_params
.aifs
= 2;
1332 ring
->tx_params
.cw_min
= 5;
1333 ring
->tx_params
.cw_max
= 10;
1339 static void rt2x00lib_free_rings(struct rt2x00_dev
*rt2x00dev
)
1341 kfree(rt2x00dev
->rx
);
1342 rt2x00dev
->rx
= NULL
;
1343 rt2x00dev
->tx
= NULL
;
1344 rt2x00dev
->bcn
= NULL
;
1347 int rt2x00lib_probe_dev(struct rt2x00_dev
*rt2x00dev
)
1349 int retval
= -ENOMEM
;
1352 * Let the driver probe the device to detect the capabilities.
1354 retval
= rt2x00dev
->ops
->lib
->probe_hw(rt2x00dev
);
1356 ERROR(rt2x00dev
, "Failed to allocate device.\n");
1361 * Initialize configuration work.
1363 INIT_WORK(&rt2x00dev
->beacon_work
, rt2x00lib_beacondone_scheduled
);
1364 INIT_WORK(&rt2x00dev
->filter_work
, rt2x00lib_packetfilter_scheduled
);
1365 INIT_WORK(&rt2x00dev
->config_work
, rt2x00lib_configuration_scheduled
);
1366 INIT_DELAYED_WORK(&rt2x00dev
->link
.work
, rt2x00lib_link_tuner
);
1369 * Reset current working type.
1371 rt2x00dev
->interface
.type
= IEEE80211_IF_TYPE_INVALID
;
1374 * Allocate ring array.
1376 retval
= rt2x00lib_alloc_rings(rt2x00dev
);
1381 * Initialize ieee80211 structure.
1383 retval
= rt2x00lib_probe_hw(rt2x00dev
);
1385 ERROR(rt2x00dev
, "Failed to initialize hw.\n");
1392 retval
= rt2x00rfkill_allocate(rt2x00dev
);
1397 * Open the debugfs entry.
1399 rt2x00debug_register(rt2x00dev
);
1401 __set_bit(DEVICE_PRESENT
, &rt2x00dev
->flags
);
1406 rt2x00lib_remove_dev(rt2x00dev
);
1410 EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev
);
1412 void rt2x00lib_remove_dev(struct rt2x00_dev
*rt2x00dev
)
1414 __clear_bit(DEVICE_PRESENT
, &rt2x00dev
->flags
);
1419 rt2x00lib_disable_radio(rt2x00dev
);
1422 * Uninitialize device.
1424 rt2x00lib_uninitialize(rt2x00dev
);
1427 * Close debugfs entry.
1429 rt2x00debug_deregister(rt2x00dev
);
1434 rt2x00rfkill_free(rt2x00dev
);
1437 * Free ieee80211_hw memory.
1439 rt2x00lib_remove_hw(rt2x00dev
);
1442 * Free firmware image.
1444 rt2x00lib_free_firmware(rt2x00dev
);
1447 * Free ring structures.
1449 rt2x00lib_free_rings(rt2x00dev
);
1451 EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev
);
1454 * Device state handlers
1457 int rt2x00lib_suspend(struct rt2x00_dev
*rt2x00dev
, pm_message_t state
)
1461 NOTICE(rt2x00dev
, "Going to sleep.\n");
1462 __clear_bit(DEVICE_PRESENT
, &rt2x00dev
->flags
);
1465 * Only continue if mac80211 has open interfaces.
1467 if (!test_bit(DEVICE_STARTED
, &rt2x00dev
->flags
))
1469 __set_bit(DEVICE_STARTED_SUSPEND
, &rt2x00dev
->flags
);
1472 * Disable radio and unitialize all items
1473 * that must be recreated on resume.
1475 rt2x00lib_stop(rt2x00dev
);
1476 rt2x00lib_uninitialize(rt2x00dev
);
1477 rt2x00debug_deregister(rt2x00dev
);
1481 * Set device mode to sleep for power management.
1483 retval
= rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_SLEEP
);
1489 EXPORT_SYMBOL_GPL(rt2x00lib_suspend
);
1491 int rt2x00lib_resume(struct rt2x00_dev
*rt2x00dev
)
1493 struct interface
*intf
= &rt2x00dev
->interface
;
1496 NOTICE(rt2x00dev
, "Waking up.\n");
1499 * Open the debugfs entry.
1501 rt2x00debug_register(rt2x00dev
);
1504 * Only continue if mac80211 had open interfaces.
1506 if (!__test_and_clear_bit(DEVICE_STARTED_SUSPEND
, &rt2x00dev
->flags
))
1510 * Reinitialize device and all active interfaces.
1512 retval
= rt2x00lib_start(rt2x00dev
);
1517 * Reconfigure device.
1519 rt2x00lib_config(rt2x00dev
, &rt2x00dev
->hw
->conf
, 1);
1520 if (!rt2x00dev
->hw
->conf
.radio_enabled
)
1521 rt2x00lib_disable_radio(rt2x00dev
);
1523 rt2x00lib_config_mac_addr(rt2x00dev
, intf
->mac
);
1524 rt2x00lib_config_bssid(rt2x00dev
, intf
->bssid
);
1525 rt2x00lib_config_type(rt2x00dev
, intf
->type
);
1528 * We are ready again to receive requests from mac80211.
1530 __set_bit(DEVICE_PRESENT
, &rt2x00dev
->flags
);
1533 * It is possible that during that mac80211 has attempted
1534 * to send frames while we were suspending or resuming.
1535 * In that case we have disabled the TX queue and should
1536 * now enable it again
1538 ieee80211_start_queues(rt2x00dev
->hw
);
1541 * When in Master or Ad-hoc mode,
1542 * restart Beacon transmitting by faking a beacondone event.
1544 if (intf
->type
== IEEE80211_IF_TYPE_AP
||
1545 intf
->type
== IEEE80211_IF_TYPE_IBSS
)
1546 rt2x00lib_beacondone(rt2x00dev
);
1551 rt2x00lib_disable_radio(rt2x00dev
);
1552 rt2x00lib_uninitialize(rt2x00dev
);
1553 rt2x00debug_deregister(rt2x00dev
);
1557 EXPORT_SYMBOL_GPL(rt2x00lib_resume
);
1558 #endif /* CONFIG_PM */
1561 * rt2x00lib module information.
1563 MODULE_AUTHOR(DRV_PROJECT
);
1564 MODULE_VERSION(DRV_VERSION
);
1565 MODULE_DESCRIPTION("rt2x00 library");
1566 MODULE_LICENSE("GPL");