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.
24 Supported chipsets: RT2460, RT2560, RT2570,
25 rt2561, rt2561s, rt2661, rt2571W & rt2671.
29 * Set enviroment defines for rt2x00.h
31 #define DRV_NAME "rt2x00lib"
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/version.h>
36 #include <linux/init.h>
37 #include <linux/delay.h>
38 #include <linux/etherdevice.h>
41 #include "rt2x00lib.h"
42 #include "rt2x00dev.h"
45 * Radio control handlers.
47 int rt2x00lib_enable_radio(struct rt2x00_dev
*rt2x00dev
)
52 * Don't enable the radio twice.
53 * or if the hardware button has been disabled.
55 if (test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
) ||
56 (test_bit(DEVICE_SUPPORT_HW_BUTTON
, &rt2x00dev
->flags
) &&
57 !test_bit(DEVICE_ENABLED_RADIO_HW
, &rt2x00dev
->flags
)))
60 status
= rt2x00dev
->ops
->lib
->set_device_state(
61 rt2x00dev
, STATE_RADIO_ON
);
65 __set_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
);
67 rt2x00lib_toggle_rx(rt2x00dev
, 1);
69 ieee80211_start_queues(rt2x00dev
->hw
);
71 if (is_interface_present(&rt2x00dev
->interface
))
72 rt2x00_start_link_tune(rt2x00dev
);
77 void rt2x00lib_disable_radio(struct rt2x00_dev
*rt2x00dev
)
79 if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
82 rt2x00_stop_link_tune(rt2x00dev
);
84 ieee80211_stop_queues(rt2x00dev
->hw
);
86 rt2x00lib_toggle_rx(rt2x00dev
, 0);
88 rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_RADIO_OFF
);
91 void rt2x00lib_toggle_rx(struct rt2x00_dev
*rt2x00dev
, int enable
)
94 * When we are disabling the rx, we should also stop the link tuner.
97 rt2x00_stop_link_tune(rt2x00dev
);
99 rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
,
100 enable
? STATE_RADIO_RX_ON
: STATE_RADIO_RX_OFF
);
103 * When we are enabling the rx, we should also start the link tuner.
105 if (enable
&& is_interface_present(&rt2x00dev
->interface
))
106 rt2x00_start_link_tune(rt2x00dev
);
109 static void rt2x00lib_link_tuner(struct work_struct
*work
)
111 struct rt2x00_dev
*rt2x00dev
=
112 container_of(work
, struct rt2x00_dev
, link
.work
.work
);
115 * Update promisc mode (this function will first check
116 * if updating is really required).
118 rt2x00lib_config_promisc(rt2x00dev
, rt2x00dev
->interface
.promisc
);
121 * Cancel all link tuning if the eeprom has indicated
122 * it is not required.
124 if (test_bit(CONFIG_DISABLE_LINK_TUNING
, &rt2x00dev
->flags
))
127 rt2x00dev
->ops
->lib
->link_tuner(rt2x00dev
);
130 * Increase tuner counter, and reschedule the next link tuner run.
132 rt2x00dev
->link
.count
++;
133 queue_delayed_work(rt2x00dev
->hw
->workqueue
, &rt2x00dev
->link
.work
,
140 void rt2x00lib_config_type(struct rt2x00_dev
*rt2x00dev
, const int type
)
142 if (!(is_interface_present(&rt2x00dev
->interface
) ^
143 test_bit(INTERFACE_ENABLED
, &rt2x00dev
->flags
)) &&
144 !(is_monitor_present(&rt2x00dev
->interface
) ^
145 test_bit(INTERFACE_ENABLED_MONITOR
, &rt2x00dev
->flags
)))
148 rt2x00dev
->ops
->lib
->config_type(rt2x00dev
, type
);
150 if (type
!= IEEE80211_IF_TYPE_MNTR
) {
151 if (is_interface_present(&rt2x00dev
->interface
))
152 __set_bit(INTERFACE_ENABLED
, &rt2x00dev
->flags
);
154 __clear_bit(INTERFACE_ENABLED
, &rt2x00dev
->flags
);
156 if (is_monitor_present(&rt2x00dev
->interface
))
157 __set_bit(INTERFACE_ENABLED_MONITOR
,
160 __clear_bit(INTERFACE_ENABLED_MONITOR
,
165 void rt2x00lib_config_phymode(struct rt2x00_dev
*rt2x00dev
, const int phymode
)
167 if (rt2x00dev
->rx_status
.phymode
== phymode
)
170 rt2x00dev
->ops
->lib
->config_phymode(rt2x00dev
, phymode
);
172 rt2x00dev
->rx_status
.phymode
= phymode
;
175 void rt2x00lib_config_channel(struct rt2x00_dev
*rt2x00dev
, const int value
,
176 const int channel
, const int freq
, const int txpower
)
178 if (channel
== rt2x00dev
->rx_status
.channel
)
181 rt2x00dev
->ops
->lib
->config_channel(rt2x00dev
, value
, channel
, txpower
);
183 INFO(rt2x00dev
, "Switching channel. "
184 "RF1: 0x%08x, RF2: 0x%08x, RF3: 0x%08x, RF3: 0x%08x.\n",
185 rt2x00dev
->rf1
, rt2x00dev
->rf2
,
186 rt2x00dev
->rf3
, rt2x00dev
->rf4
);
188 rt2x00dev
->rx_status
.freq
= freq
;
189 rt2x00dev
->rx_status
.channel
= channel
;
192 void rt2x00lib_config_promisc(struct rt2x00_dev
*rt2x00dev
, const int promisc
)
195 * Monitor mode implies promisc mode enabled.
196 * In all other instances, check if we need to toggle promisc mode.
198 if (is_monitor_present(&rt2x00dev
->interface
) &&
199 !test_bit(INTERFACE_ENABLED_PROMISC
, &rt2x00dev
->flags
)) {
200 rt2x00dev
->ops
->lib
->config_promisc(rt2x00dev
, 1);
201 __set_bit(INTERFACE_ENABLED_PROMISC
, &rt2x00dev
->flags
);
204 if (test_bit(INTERFACE_ENABLED_PROMISC
, &rt2x00dev
->flags
) != promisc
) {
205 rt2x00dev
->ops
->lib
->config_promisc(rt2x00dev
, promisc
);
206 __change_bit(INTERFACE_ENABLED_PROMISC
, &rt2x00dev
->flags
);
210 void rt2x00lib_config_txpower(struct rt2x00_dev
*rt2x00dev
, const int txpower
)
212 if (txpower
== rt2x00dev
->tx_power
)
215 rt2x00dev
->ops
->lib
->config_txpower(rt2x00dev
, txpower
);
217 rt2x00dev
->tx_power
= txpower
;
220 void rt2x00lib_config_antenna(struct rt2x00_dev
*rt2x00dev
,
221 const int antenna_tx
, const int antenna_rx
)
223 if (rt2x00dev
->rx_status
.antenna
== antenna_rx
)
226 rt2x00dev
->ops
->lib
->config_antenna(rt2x00dev
, antenna_tx
, antenna_rx
);
228 rt2x00dev
->rx_status
.antenna
= antenna_rx
;
232 * Driver initialization handlers.
234 static void rt2x00lib_channel(struct ieee80211_channel
*entry
,
235 const int channel
, const int tx_power
, const int value
)
237 entry
->chan
= channel
;
239 entry
->freq
= 2407 + (5 * channel
);
241 entry
->freq
= 5000 + (5 * channel
);
244 IEEE80211_CHAN_W_IBSS
|
245 IEEE80211_CHAN_W_ACTIVE_SCAN
|
246 IEEE80211_CHAN_W_SCAN
;
247 entry
->power_level
= tx_power
;
248 entry
->antenna_max
= 0xff;
251 static void rt2x00lib_rate(struct ieee80211_rate
*entry
,
252 const int rate
,const int mask
, const int plcp
, const int flags
)
256 DEVICE_SET_RATE_FIELD(rate
, RATE
) |
257 DEVICE_SET_RATE_FIELD(mask
, RATEMASK
) |
258 DEVICE_SET_RATE_FIELD(plcp
, PLCP
);
259 entry
->flags
= flags
;
260 entry
->val2
= entry
->val
;
261 if (entry
->flags
& IEEE80211_RATE_PREAMBLE2
)
262 entry
->val2
|= DEVICE_SET_RATE_FIELD(1, PREAMBLE
);
263 entry
->min_rssi_ack
= 0;
264 entry
->min_rssi_ack_delta
= 0;
267 static int rt2x00lib_init_hw_modes(struct rt2x00_dev
*rt2x00dev
,
268 struct hw_mode_spec
*spec
)
270 struct ieee80211_hw
*hw
= rt2x00dev
->hw
;
271 struct ieee80211_hw_mode
*hwmodes
;
272 struct ieee80211_channel
*channels
;
273 struct ieee80211_rate
*rates
;
275 unsigned char tx_power
;
277 hwmodes
= kzalloc(sizeof(*hwmodes
) * spec
->num_modes
, GFP_KERNEL
);
281 channels
= kzalloc(sizeof(*channels
) * spec
->num_channels
, GFP_KERNEL
);
283 goto exit_free_modes
;
285 rates
= kzalloc(sizeof(*rates
) * spec
->num_rates
, GFP_KERNEL
);
287 goto exit_free_channels
;
290 * Initialize Rate list.
292 rt2x00lib_rate(&rates
[0], 10, 0x001, 0x00, IEEE80211_RATE_CCK
);
293 rt2x00lib_rate(&rates
[1], 20, 0x003, 0x01, IEEE80211_RATE_CCK_2
);
294 rt2x00lib_rate(&rates
[2], 55, 0x007, 0x02, IEEE80211_RATE_CCK_2
);
295 rt2x00lib_rate(&rates
[3], 110, 0x00f, 0x03, IEEE80211_RATE_CCK_2
);
297 if (spec
->num_rates
> 4) {
298 rt2x00lib_rate(&rates
[4], 60, 0x01f, 0x0b, IEEE80211_RATE_OFDM
);
299 rt2x00lib_rate(&rates
[5], 90, 0x03f, 0x0f, IEEE80211_RATE_OFDM
);
300 rt2x00lib_rate(&rates
[6], 120, 0x07f, 0x0a, IEEE80211_RATE_OFDM
);
301 rt2x00lib_rate(&rates
[7], 180, 0x0ff, 0x0e, IEEE80211_RATE_OFDM
);
302 rt2x00lib_rate(&rates
[8], 240, 0x1ff, 0x09, IEEE80211_RATE_OFDM
);
303 rt2x00lib_rate(&rates
[9], 360, 0x3ff, 0x0d, IEEE80211_RATE_OFDM
);
304 rt2x00lib_rate(&rates
[10], 480, 0x7ff, 0x08, IEEE80211_RATE_OFDM
);
305 rt2x00lib_rate(&rates
[11], 540, 0xfff, 0x0c, IEEE80211_RATE_OFDM
);
309 * Initialize Channel list.
311 for (i
= 0; i
< 14; i
++)
312 rt2x00lib_channel(&channels
[i
], i
+ 1,
313 spec
->tx_power_bg
[i
], spec
->chan_val_bg
[i
]);
315 if (spec
->num_channels
> 14) {
316 for (i
= 14; i
< spec
->num_channels
; i
++) {
318 channels
[i
].chan
= 36;
320 channels
[i
].chan
= 100;
322 channels
[i
].chan
= 149;
323 channels
[i
].chan
+= ((i
- 14) * 4);
325 if (spec
->tx_power_a
)
326 tx_power
= spec
->tx_power_a
[i
];
328 tx_power
= spec
->tx_power_default
;
330 rt2x00lib_channel(&channels
[i
],
331 channels
[i
].chan
, tx_power
,
332 spec
->chan_val_a
[i
]);
337 * Intitialize 802.11b
341 if (spec
->num_modes
> HWMODE_B
) {
342 hwmodes
[HWMODE_B
].mode
= MODE_IEEE80211B
;
343 hwmodes
[HWMODE_B
].num_channels
= 14;
344 hwmodes
[HWMODE_B
].num_rates
= 4;
345 hwmodes
[HWMODE_B
].channels
= channels
;
346 hwmodes
[HWMODE_B
].rates
= rates
;
350 * Intitialize 802.11g
354 if (spec
->num_modes
> HWMODE_G
) {
355 hwmodes
[HWMODE_G
].mode
= MODE_IEEE80211G
;
356 hwmodes
[HWMODE_G
].num_channels
= 14;
357 hwmodes
[HWMODE_G
].num_rates
= spec
->num_rates
;
358 hwmodes
[HWMODE_G
].channels
= channels
;
359 hwmodes
[HWMODE_G
].rates
= rates
;
363 * Intitialize 802.11a
365 * Channels: OFDM, UNII, HiperLAN2.
367 if (spec
->num_modes
> HWMODE_A
) {
368 hwmodes
[HWMODE_A
].mode
= MODE_IEEE80211A
;
369 hwmodes
[HWMODE_A
].num_channels
= spec
->num_channels
- 14;
370 hwmodes
[HWMODE_A
].num_rates
= spec
->num_rates
- 4;
371 hwmodes
[HWMODE_A
].channels
= &channels
[14];
372 hwmodes
[HWMODE_A
].rates
= &rates
[4];
375 if (spec
->num_modes
> HWMODE_G
&&
376 ieee80211_register_hwmode(hw
, &hwmodes
[HWMODE_G
]))
377 goto exit_free_rates
;
379 if (spec
->num_modes
> HWMODE_B
&&
380 ieee80211_register_hwmode(hw
, &hwmodes
[HWMODE_B
]))
381 goto exit_free_rates
;
383 if (spec
->num_modes
> HWMODE_A
&&
384 ieee80211_register_hwmode(hw
, &hwmodes
[HWMODE_A
]))
385 goto exit_free_rates
;
387 rt2x00dev
->hwmodes
= hwmodes
;
401 ERROR(rt2x00dev
, "Allocation ieee80211 modes failed.\n");
405 static void rt2x00lib_deinit_hw(struct rt2x00_dev
*rt2x00dev
)
407 if (test_bit(DEVICE_INITIALIZED_HW
, &rt2x00dev
->flags
))
408 ieee80211_unregister_hw(rt2x00dev
->hw
);
410 if (likely(rt2x00dev
->hwmodes
)) {
411 kfree(rt2x00dev
->hwmodes
->channels
);
412 kfree(rt2x00dev
->hwmodes
->rates
);
413 kfree(rt2x00dev
->hwmodes
);
414 rt2x00dev
->hwmodes
= NULL
;
418 static int rt2x00lib_init_hw(struct rt2x00_dev
*rt2x00dev
)
420 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
424 * Initialize HW modes.
426 status
= rt2x00lib_init_hw_modes(rt2x00dev
, spec
);
433 status
= ieee80211_register_hw(rt2x00dev
->hw
);
435 rt2x00lib_deinit_hw(rt2x00dev
);
439 __set_bit(DEVICE_INITIALIZED_HW
, &rt2x00dev
->flags
);
445 * Initialization/uninitialization handlers.
447 static int rt2x00lib_alloc_ring_entries(struct data_ring
*ring
,
448 const u16 max_entries
, const u16 data_size
, const u16 desc_size
)
450 struct data_entry
*entry
;
453 ring
->stats
.limit
= max_entries
;
454 ring
->data_size
= data_size
;
455 ring
->desc_size
= desc_size
;
458 * Allocate all ring entries.
460 entry
= kzalloc(ring
->stats
.limit
* sizeof(*entry
), GFP_KERNEL
);
464 for (i
= 0; i
< ring
->stats
.limit
; i
++) {
466 entry
[i
].ring
= ring
;
475 static int rt2x00lib_allocate_ring_entries(struct rt2x00_dev
*rt2x00dev
)
477 struct data_ring
*ring
;
480 * Allocate the RX ring.
482 if (rt2x00lib_alloc_ring_entries(rt2x00dev
->rx
,
483 RX_ENTRIES
, DATA_FRAME_SIZE
, rt2x00dev
->ops
->rxd_size
))
487 * First allocate the TX rings.
489 txring_for_each(rt2x00dev
, ring
) {
490 if (rt2x00lib_alloc_ring_entries(ring
,
491 TX_ENTRIES
, DATA_FRAME_SIZE
, rt2x00dev
->ops
->txd_size
))
496 * Allocate the BEACON ring.
498 if (rt2x00lib_alloc_ring_entries(&rt2x00dev
->bcn
[0],
499 BEACON_ENTRIES
, MGMT_FRAME_SIZE
, rt2x00dev
->ops
->txd_size
))
503 * Allocate the Atim ring.
505 if (test_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
)) {
506 if (rt2x00lib_alloc_ring_entries(&rt2x00dev
->bcn
[1],
507 ATIM_ENTRIES
, DATA_FRAME_SIZE
, rt2x00dev
->ops
->txd_size
))
514 static void rt2x00lib_free_ring_entries(struct rt2x00_dev
*rt2x00dev
)
516 struct data_ring
*ring
;
518 ring_for_each(rt2x00dev
, ring
) {
524 int rt2x00lib_initialize(struct rt2x00_dev
*rt2x00dev
)
528 if (test_bit(DEVICE_INITIALIZED
, &rt2x00dev
->flags
))
532 * Allocate all data rings.
534 status
= rt2x00lib_allocate_ring_entries(rt2x00dev
);
536 ERROR(rt2x00dev
, "DMA allocation failed.\n");
541 * Initialize the device.
543 status
= rt2x00dev
->ops
->lib
->initialize(rt2x00dev
);
547 __set_bit(DEVICE_INITIALIZED
, &rt2x00dev
->flags
);
550 * Register the rfkill handler.
552 status
= rt2x00lib_register_rfkill(rt2x00dev
);
554 goto exit_unitialize
;
559 rt2x00lib_uninitialize(rt2x00dev
);
562 rt2x00lib_free_ring_entries(rt2x00dev
);
567 void rt2x00lib_uninitialize(struct rt2x00_dev
*rt2x00dev
)
569 if (!__test_and_clear_bit(DEVICE_INITIALIZED
, &rt2x00dev
->flags
))
575 rt2x00lib_unregister_rfkill(rt2x00dev
);
578 * Allow the HW to uninitialize.
580 rt2x00dev
->ops
->lib
->uninitialize(rt2x00dev
);
583 * Free allocated datarings.
585 rt2x00lib_free_ring_entries(rt2x00dev
);
589 * driver allocation handlers.
591 static int rt2x00lib_alloc_rings(struct rt2x00_dev
*rt2x00dev
)
593 struct data_ring
*ring
;
594 unsigned int ring_num
;
597 * We need the following rings:
601 * Atim: 1 (if supported)
603 ring_num
= 2 + rt2x00dev
->hw
->queues
+
604 test_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
);
606 ring
= kzalloc(sizeof(*ring
) * ring_num
, GFP_KERNEL
);
608 ERROR(rt2x00dev
, "Ring allocation failed.\n");
613 * Initialize pointers
615 rt2x00dev
->rx
= &ring
[0];
616 rt2x00dev
->tx
= &ring
[1];
617 rt2x00dev
->bcn
= &ring
[1 + rt2x00dev
->hw
->queues
];
620 * Initialize ring parameters.
622 * cw_max: 2^10 = 1024.
624 ring_for_each(rt2x00dev
, ring
) {
625 ring
->rt2x00dev
= rt2x00dev
;
626 ring
->tx_params
.aifs
= 2;
627 ring
->tx_params
.cw_min
= 5;
628 ring
->tx_params
.cw_max
= 10;
634 int rt2x00lib_probe_dev(struct rt2x00_dev
*rt2x00dev
)
636 int retval
= -ENOMEM
;
639 * Let the driver probe the device to detect the capabilities.
641 retval
= rt2x00dev
->ops
->lib
->init_hw(rt2x00dev
);
643 ERROR(rt2x00dev
, "Failed to allocate device.\n");
648 * Initialize configuration work.
650 INIT_DELAYED_WORK(&rt2x00dev
->link
.work
, rt2x00lib_link_tuner
);
653 * Reset current working type.
655 rt2x00dev
->interface
.type
= -EINVAL
;
658 * Allocate ring array.
660 retval
= rt2x00lib_alloc_rings(rt2x00dev
);
665 * Initialize ieee80211 structure.
667 retval
= rt2x00lib_init_hw(rt2x00dev
);
669 ERROR(rt2x00dev
, "Failed to initialize hw.\n");
676 retval
= rt2x00lib_allocate_rfkill(rt2x00dev
);
681 * Open the debugfs entry.
683 rt2x00debug_register(rt2x00dev
);
686 * Check if we need to load the firmware.
688 if (test_bit(FIRMWARE_REQUIRED
, &rt2x00dev
->flags
)) {
690 * Request firmware and wait with further
691 * initializing of the card until the firmware
694 retval
= rt2x00lib_load_firmware(rt2x00dev
);
702 rt2x00lib_remove_dev(rt2x00dev
);
706 EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev
);
708 void rt2x00lib_remove_dev(struct rt2x00_dev
*rt2x00dev
)
713 rt2x00lib_disable_radio(rt2x00dev
);
716 * Uninitialize device.
718 rt2x00lib_uninitialize(rt2x00dev
);
721 * Close debugfs entry.
723 rt2x00debug_deregister(rt2x00dev
);
728 rt2x00lib_free_rfkill(rt2x00dev
);
731 * Free ieee80211_hw memory.
733 rt2x00lib_deinit_hw(rt2x00dev
);
736 * Free ring structures.
738 kfree(rt2x00dev
->rx
);
739 rt2x00dev
->rx
= NULL
;
740 rt2x00dev
->tx
= NULL
;
741 rt2x00dev
->bcn
= NULL
;
744 * Free EEPROM memory.
746 kfree(rt2x00dev
->eeprom
);
747 rt2x00dev
->eeprom
= NULL
;
749 EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev
);
752 * Device state handlers
754 int rt2x00lib_suspend(struct rt2x00_dev
*rt2x00dev
,
759 NOTICE(rt2x00dev
, "Going to sleep.\n");
761 rt2x00lib_disable_radio(rt2x00dev
);
764 * Set device mode to sleep for power management.
766 retval
= rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_SLEEP
);
770 rt2x00lib_remove_dev(rt2x00dev
);
774 EXPORT_SYMBOL_GPL(rt2x00lib_suspend
);
776 int rt2x00lib_resume(struct rt2x00_dev
*rt2x00dev
)
780 NOTICE(rt2x00dev
, "Waking up.\n");
782 retval
= rt2x00lib_probe_dev(rt2x00dev
);
784 ERROR(rt2x00dev
, "Failed to allocate device.\n");
790 EXPORT_SYMBOL_GPL(rt2x00lib_resume
);
793 * Interrupt context handlers.
795 void rt2x00lib_txdone(struct data_entry
*entry
,
796 const int status
, const int retry
)
798 struct rt2x00_dev
*rt2x00dev
= entry
->ring
->rt2x00dev
;
799 struct ieee80211_tx_status
*tx_status
= &entry
->tx_status
;
800 struct ieee80211_low_level_stats
*stats
= &rt2x00dev
->low_level_stats
;
803 * Update TX statistics.
805 tx_status
->flags
= 0;
806 tx_status
->ack_signal
= 0;
807 tx_status
->excessive_retries
= (status
== TX_FAIL_RETRY
);
808 tx_status
->retry_count
= retry
;
810 if (!(tx_status
->control
.flags
& IEEE80211_TXCTL_NO_ACK
)) {
811 if (status
== TX_SUCCESS
|| status
== TX_SUCCESS_RETRY
)
812 tx_status
->flags
|= IEEE80211_TX_STATUS_ACK
;
814 stats
->dot11ACKFailureCount
++;
817 tx_status
->queue_length
= entry
->ring
->stats
.limit
;
818 tx_status
->queue_number
= tx_status
->control
.queue
;
820 if (tx_status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
821 if (status
== TX_SUCCESS
|| status
== TX_SUCCESS_RETRY
)
822 stats
->dot11RTSSuccessCount
++;
824 stats
->dot11RTSFailureCount
++;
828 * Send the tx_status to mac80211,
829 * that method also cleans up the skb structure.
831 ieee80211_tx_status_irqsafe(rt2x00dev
->hw
, entry
->skb
, tx_status
);
835 EXPORT_SYMBOL_GPL(rt2x00lib_txdone
);
837 void rt2x00lib_rxdone(struct data_entry
*entry
, char *data
,
838 const int size
, const int signal
, const int rssi
, const int ofdm
)
840 struct rt2x00_dev
*rt2x00dev
= entry
->ring
->rt2x00dev
;
841 struct ieee80211_rx_status
*rx_status
= &rt2x00dev
->rx_status
;
842 struct ieee80211_hw_mode
*mode
;
843 struct ieee80211_rate
*rate
;
849 * Update RX statistics.
851 mode
= &rt2x00dev
->hwmodes
[rt2x00dev
->curr_hwmode
];
852 for (i
= 0; i
< mode
->num_rates
; i
++) {
853 rate
= &mode
->rates
[i
];
856 * When frame was received with an OFDM bitrate,
857 * the signal is the PLCP value. If it was received with
858 * a CCK bitrate the signal is the rate in 0.5kbit/s.
861 val
= DEVICE_GET_RATE_FIELD(rate
->val
, RATE
);
863 val
= DEVICE_GET_RATE_FIELD(rate
->val
, PLCP
);
867 * Check for preamble bit.
877 rx_status
->rate
= val
;
878 rx_status
->ssi
= rssi
;
879 rt2x00_update_link_rssi(&rt2x00dev
->link
, rssi
);
882 * Let's allocate a sk_buff where we can store the received data in,
883 * note that if data is NULL, we still have to allocate a sk_buff
884 * but that we should use that to replace the sk_buff which is already
887 skb
= dev_alloc_skb(size
+ NET_IP_ALIGN
);
891 skb_reserve(skb
, NET_IP_ALIGN
);
895 memcpy(skb
->data
, data
, size
);
900 ieee80211_rx_irqsafe(rt2x00dev
->hw
, entry
->skb
, rx_status
);
903 EXPORT_SYMBOL_GPL(rt2x00lib_rxdone
);
906 * TX descriptor initializer
908 void rt2x00lib_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
909 struct data_entry
*entry
, struct data_desc
*txd
,
910 struct ieee80211_hdr
*ieee80211hdr
, unsigned int length
,
911 struct ieee80211_tx_control
*control
)
913 struct data_entry_desc desc
;
924 if (control
->queue
< rt2x00dev
->hw
->queues
)
925 desc
.queue
= control
->queue
;
930 * Read required fields from ieee80211 header.
932 frame_control
= le16_to_cpu(ieee80211hdr
->frame_control
);
933 seq_ctrl
= le16_to_cpu(ieee80211hdr
->seq_ctrl
);
935 tx_rate
= control
->tx_rate
;
938 * Check if this is a rts frame
940 if (is_rts_frame(frame_control
)) {
941 __set_bit(ENTRY_TXD_RTS_FRAME
, &entry
->flags
);
942 if (control
->rts_cts_rate
)
943 tx_rate
= control
->rts_cts_rate
;
949 if (DEVICE_GET_RATE_FIELD(tx_rate
, RATEMASK
) & DEV_OFDM_RATE
)
950 __set_bit(ENTRY_TXD_OFDM_RATE
, &entry
->flags
);
953 * Check if more fragments are pending
955 if (ieee80211_get_morefrag(ieee80211hdr
))
956 __set_bit(ENTRY_TXD_MORE_FRAG
, &entry
->flags
);
959 * Beacons and probe responses require the tsf timestamp
960 * to be inserted into the frame.
962 if (control
->queue
== IEEE80211_TX_QUEUE_BEACON
||
963 is_probe_resp(frame_control
))
964 __set_bit(ENTRY_TXD_REQ_TIMESTAMP
, &entry
->flags
);
967 * Check if ACK is required
969 if (!(control
->flags
& IEEE80211_TXCTL_NO_ACK
))
970 __set_bit(ENTRY_TXD_REQ_ACK
, &entry
->flags
);
973 * Determine with what IFS priority this frame should be send.
974 * Set ifs to IFS_SIFS when the this is not the first fragment,
975 * or this fragment came after RTS/CTS.
977 if ((seq_ctrl
& IEEE80211_SCTL_FRAG
) > 0 ||
978 test_bit(ENTRY_TXD_RTS_FRAME
, &entry
->flags
))
981 desc
.ifs
= IFS_BACKOFF
;
984 * How the length should be processed depends
985 * on if we are working with OFDM rates or not.
987 if (test_bit(ENTRY_TXD_OFDM_RATE
, &entry
->flags
)) {
989 desc
.length_high
= ((length
+ FCS_LEN
) >> 6) & 0x3f;
990 desc
.length_low
= ((length
+ FCS_LEN
) & 0x3f);
993 bitrate
= DEVICE_GET_RATE_FIELD(tx_rate
, RATE
);
996 * Convert length to microseconds.
998 residual
= get_duration_res(length
+ FCS_LEN
, bitrate
);
999 duration
= get_duration(length
+ FCS_LEN
, bitrate
);
1004 desc
.length_high
= duration
>> 8;
1005 desc
.length_low
= duration
& 0xff;
1009 * Create the signal and service values.
1011 desc
.signal
= DEVICE_GET_RATE_FIELD(tx_rate
, PLCP
);
1012 if (DEVICE_GET_RATE_FIELD(tx_rate
, PREAMBLE
))
1013 desc
.signal
|= 0x08;
1015 desc
.service
= 0x04;
1016 if (residual
<= (8 % 11))
1017 desc
.service
|= 0x80;
1019 rt2x00dev
->ops
->lib
->write_tx_desc(rt2x00dev
, entry
, txd
, &desc
,
1020 ieee80211hdr
, length
, control
);
1022 EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc
);
1025 * rt2x00lib module information.
1027 MODULE_AUTHOR(DRV_PROJECT
);
1028 MODULE_VERSION(DRV_VERSION
);
1029 MODULE_DESCRIPTION("rt2x00 library");
1030 MODULE_LICENSE("GPL");