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 "rt2x00dev.h"
44 * Radio control handlers.
46 int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
51 * Don't enable the radio twice.
52 * or if the hardware button has been disabled.
54 if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
55 (test_bit(DEVICE_SUPPORT_HW_BUTTON, &rt2x00dev->flags) &&
56 !test_bit(DEVICE_ENABLED_RADIO_HW, &rt2x00dev->flags)))
59 status = rt2x00dev->ops->lib->set_device_state(
60 rt2x00dev, STATE_RADIO_ON);
64 __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
66 rt2x00lib_toggle_rx(rt2x00dev, 1);
68 ieee80211_start_queues(rt2x00dev->hw);
73 void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
75 if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
78 ieee80211_stop_queues(rt2x00dev->hw);
80 rt2x00lib_toggle_rx(rt2x00dev, 0);
82 rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
85 void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, int enable)
88 * When we are disabling the rx, we should also stop the link tuner.
90 if (!enable && work_pending(&rt2x00dev->link.work.work))
91 rt2x00_stop_link_tune(rt2x00dev);
93 rt2x00dev->ops->lib->set_device_state(rt2x00dev,
94 enable ? STATE_RADIO_RX_ON : STATE_RADIO_RX_OFF);
97 * When we are enabling the rx, we should also start the link tuner.
100 rt2x00_start_link_tune(rt2x00dev);
103 static void rt2x00lib_link_tuner(struct work_struct *work)
105 struct rt2x00_dev *rt2x00dev =
106 container_of(work, struct rt2x00_dev, link.work.work);
110 * Update promisc mode (this function will first check
111 * if updating is really required).
113 rt2x00lib_config_promisc(rt2x00dev, rt2x00dev->interface.promisc);
116 * Cancel all link tuning if the eeprom has indicated
117 * it is not required.
119 if (test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags))
123 * Retrieve link quality.
124 * Also convert rssi to dBm using the max_rssi value.
126 rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
127 rssi -= rt2x00dev->hw->max_rssi;
129 rt2x00dev->ops->lib->link_tuner(rt2x00dev, rssi);
132 * Increase tuner counter, and reschedule the next link tuner run.
134 rt2x00dev->link.count++;
135 queue_delayed_work(rt2x00dev->workqueue, &rt2x00dev->link.work,
142 void rt2x00lib_config_type(struct rt2x00_dev *rt2x00dev, const int type)
144 if (!(is_interface_present(&rt2x00dev->interface) ^
145 test_bit(INTERFACE_ENABLED, &rt2x00dev->flags)) &&
146 !(is_monitor_present(&rt2x00dev->interface) ^
147 test_bit(INTERFACE_ENABLED_MONITOR, &rt2x00dev->flags)))
150 rt2x00dev->ops->lib->config_type(rt2x00dev, type);
152 if (type != IEEE80211_IF_TYPE_MNTR) {
153 if (is_interface_present(&rt2x00dev->interface))
154 __set_bit(INTERFACE_ENABLED, &rt2x00dev->flags);
156 __clear_bit(INTERFACE_ENABLED, &rt2x00dev->flags);
158 if (is_monitor_present(&rt2x00dev->interface))
159 __set_bit(INTERFACE_ENABLED_MONITOR,
162 __clear_bit(INTERFACE_ENABLED_MONITOR,
167 void rt2x00lib_config_phymode(struct rt2x00_dev *rt2x00dev, const int phymode)
169 if (rt2x00dev->rx_status.phymode == phymode)
172 rt2x00dev->ops->lib->config_phymode(rt2x00dev, phymode);
174 rt2x00dev->rx_status.phymode = phymode;
177 void rt2x00lib_config_channel(struct rt2x00_dev *rt2x00dev, const int value,
178 const int channel, const int freq, const int txpower)
180 if (channel == rt2x00dev->rx_status.channel)
183 rt2x00dev->ops->lib->config_channel(rt2x00dev, value, channel, txpower);
185 INFO(rt2x00dev, "Switching channel. "
186 "RF1: 0x%08x, RF2: 0x%08x, RF3: 0x%08x, RF3: 0x%08x.\n",
187 rt2x00dev->rf1, rt2x00dev->rf2,
188 rt2x00dev->rf3, rt2x00dev->rf4);
190 rt2x00dev->rx_status.freq = freq;
191 rt2x00dev->rx_status.channel = channel;
194 void rt2x00lib_config_promisc(struct rt2x00_dev *rt2x00dev, const int promisc)
197 * Monitor mode implies promisc mode enabled.
198 * In all other instances, check if we need to toggle promisc mode.
200 if (is_monitor_present(&rt2x00dev->interface) &&
201 !test_bit(INTERFACE_ENABLED_PROMISC, &rt2x00dev->flags)) {
202 rt2x00dev->ops->lib->config_promisc(rt2x00dev, 1);
203 __set_bit(INTERFACE_ENABLED_PROMISC, &rt2x00dev->flags);
206 if (test_bit(INTERFACE_ENABLED_PROMISC, &rt2x00dev->flags) != promisc) {
207 rt2x00dev->ops->lib->config_promisc(rt2x00dev, promisc);
208 __change_bit(INTERFACE_ENABLED_PROMISC, &rt2x00dev->flags);
212 void rt2x00lib_config_txpower(struct rt2x00_dev *rt2x00dev, const int txpower)
214 if (txpower == rt2x00dev->tx_power)
217 rt2x00dev->ops->lib->config_txpower(rt2x00dev, txpower);
219 rt2x00dev->tx_power = txpower;
222 void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
223 const int antenna_tx, const int antenna_rx)
225 if (rt2x00dev->rx_status.antenna == antenna_rx)
228 rt2x00dev->ops->lib->config_antenna(rt2x00dev, antenna_tx, antenna_rx);
230 rt2x00dev->rx_status.antenna = antenna_rx;
234 * Driver initialization handlers.
236 static void rt2x00lib_channel(struct ieee80211_channel *entry,
237 const int channel, const int tx_power, const int value)
239 entry->chan = channel;
241 entry->freq = 2407 + (5 * channel);
243 entry->freq = 5000 + (5 * channel);
246 IEEE80211_CHAN_W_IBSS |
247 IEEE80211_CHAN_W_ACTIVE_SCAN |
248 IEEE80211_CHAN_W_SCAN;
249 entry->power_level = tx_power;
250 entry->antenna_max = 0xff;
253 static void rt2x00lib_rate(struct ieee80211_rate *entry,
254 const int rate,const int mask, const int plcp, const int flags)
258 DEVICE_SET_RATE_FIELD(rate, RATE) |
259 DEVICE_SET_RATE_FIELD(mask, RATEMASK) |
260 DEVICE_SET_RATE_FIELD(plcp, PLCP);
261 entry->flags = flags;
262 entry->val2 = entry->val;
263 if (entry->flags & IEEE80211_RATE_PREAMBLE2)
264 entry->val2 |= DEVICE_SET_RATE_FIELD(1, PREAMBLE);
265 entry->min_rssi_ack = 0;
266 entry->min_rssi_ack_delta = 0;
269 static int rt2x00lib_init_hw_modes(struct rt2x00_dev *rt2x00dev,
270 struct hw_mode_spec *spec)
272 struct ieee80211_hw *hw = rt2x00dev->hw;
273 struct ieee80211_hw_mode *hwmodes;
274 struct ieee80211_channel *channels;
275 struct ieee80211_rate *rates;
277 unsigned char tx_power;
279 hwmodes = kzalloc(sizeof(*hwmodes) * spec->num_modes, GFP_KERNEL);
283 channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
285 goto exit_free_modes;
287 rates = kzalloc(sizeof(*rates) * spec->num_rates, GFP_KERNEL);
289 goto exit_free_channels;
292 * Initialize Rate list.
294 rt2x00lib_rate(&rates[0], 10, 0x001, 0x00, IEEE80211_RATE_CCK);
295 rt2x00lib_rate(&rates[1], 20, 0x003, 0x01, IEEE80211_RATE_CCK_2);
296 rt2x00lib_rate(&rates[2], 55, 0x007, 0x02, IEEE80211_RATE_CCK_2);
297 rt2x00lib_rate(&rates[3], 110, 0x00f, 0x03, IEEE80211_RATE_CCK_2);
299 if (spec->num_rates > 4) {
300 rt2x00lib_rate(&rates[4], 60, 0x01f, 0x0b, IEEE80211_RATE_OFDM);
301 rt2x00lib_rate(&rates[5], 90, 0x03f, 0x0f, IEEE80211_RATE_OFDM);
302 rt2x00lib_rate(&rates[6], 120, 0x07f, 0x0a, IEEE80211_RATE_OFDM);
303 rt2x00lib_rate(&rates[7], 180, 0x0ff, 0x0e, IEEE80211_RATE_OFDM);
304 rt2x00lib_rate(&rates[8], 240, 0x1ff, 0x09, IEEE80211_RATE_OFDM);
305 rt2x00lib_rate(&rates[9], 360, 0x3ff, 0x0d, IEEE80211_RATE_OFDM);
306 rt2x00lib_rate(&rates[10], 480, 0x7ff, 0x08, IEEE80211_RATE_OFDM);
307 rt2x00lib_rate(&rates[11], 540, 0xfff, 0x0c, IEEE80211_RATE_OFDM);
311 * Initialize Channel list.
313 for (i = 0; i < 14; i++)
314 rt2x00lib_channel(&channels[i], i + 1,
315 spec->tx_power_bg[i], spec->chan_val_bg[i]);
317 if (spec->num_channels > 14) {
318 for (i = 14; i < spec->num_channels; i++) {
320 channels[i].chan = 36;
322 channels[i].chan = 100;
324 channels[i].chan = 149;
325 channels[i].chan += ((i - 14) * 4);
327 if (spec->tx_power_a)
328 tx_power = spec->tx_power_a[i];
330 tx_power = spec->tx_power_default;
332 rt2x00lib_channel(&channels[i],
333 channels[i].chan, tx_power,
334 spec->chan_val_a[i]);
339 * Intitialize 802.11b
343 if (spec->num_modes > HWMODE_B) {
344 hwmodes[HWMODE_B].mode = MODE_IEEE80211B;
345 hwmodes[HWMODE_B].num_channels = 14;
346 hwmodes[HWMODE_B].num_rates = 4;
347 hwmodes[HWMODE_B].channels = channels;
348 hwmodes[HWMODE_B].rates = rates;
352 * Intitialize 802.11g
356 if (spec->num_modes > HWMODE_G) {
357 hwmodes[HWMODE_G].mode = MODE_IEEE80211G;
358 hwmodes[HWMODE_G].num_channels = 14;
359 hwmodes[HWMODE_G].num_rates = spec->num_rates;
360 hwmodes[HWMODE_G].channels = channels;
361 hwmodes[HWMODE_G].rates = rates;
365 * Intitialize 802.11a
367 * Channels: OFDM, UNII, HiperLAN2.
369 if (spec->num_modes > HWMODE_A) {
370 hwmodes[HWMODE_A].mode = MODE_IEEE80211A;
371 hwmodes[HWMODE_A].num_channels = spec->num_channels - 14;
372 hwmodes[HWMODE_A].num_rates = spec->num_rates - 4;
373 hwmodes[HWMODE_A].channels = &channels[14];
374 hwmodes[HWMODE_A].rates = &rates[4];
377 if (spec->num_modes > HWMODE_G &&
378 ieee80211_register_hwmode(hw, &hwmodes[HWMODE_G]))
379 goto exit_free_rates;
381 if (spec->num_modes > HWMODE_B &&
382 ieee80211_register_hwmode(hw, &hwmodes[HWMODE_B]))
383 goto exit_free_rates;
385 if (spec->num_modes > HWMODE_A &&
386 ieee80211_register_hwmode(hw, &hwmodes[HWMODE_A]))
387 goto exit_free_rates;
389 rt2x00dev->hwmodes = hwmodes;
403 ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
407 static void rt2x00lib_deinit_hw(struct rt2x00_dev *rt2x00dev)
409 if (test_bit(DEVICE_INITIALIZED_HW, &rt2x00dev->flags))
410 ieee80211_unregister_hw(rt2x00dev->hw);
412 if (likely(rt2x00dev->hwmodes)) {
413 kfree(rt2x00dev->hwmodes->channels);
414 kfree(rt2x00dev->hwmodes->rates);
415 kfree(rt2x00dev->hwmodes);
416 rt2x00dev->hwmodes = NULL;
420 static int rt2x00lib_init_hw(struct rt2x00_dev *rt2x00dev)
422 struct hw_mode_spec *spec = &rt2x00dev->spec;
428 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->device);
431 * Initialize MAC address.
433 if (!is_valid_ether_addr(spec->mac_addr)) {
434 ERROR(rt2x00dev, "Invalid MAC addr: " MAC_FMT ".\n",
435 MAC_ARG(spec->mac_addr));
439 rt2x00dev->ops->lib->config_mac_addr(rt2x00dev, spec->mac_addr);
440 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, spec->mac_addr);
443 * Initialize HW modes.
445 status = rt2x00lib_init_hw_modes(rt2x00dev, spec);
452 status = ieee80211_register_hw(rt2x00dev->hw);
454 rt2x00lib_deinit_hw(rt2x00dev);
458 __set_bit(DEVICE_INITIALIZED_HW, &rt2x00dev->flags);
464 * Initialization/uninitialization handlers.
466 static int rt2x00lib_alloc_ring(struct data_ring *ring,
467 const u16 max_entries, const u16 data_size, const u16 desc_size)
469 struct data_entry *entry;
472 ring->stats.limit = max_entries;
473 ring->data_size = data_size;
474 ring->desc_size = desc_size;
477 * Allocate all ring entries.
479 entry = kzalloc(ring->stats.limit * sizeof(*entry), GFP_KERNEL);
483 for (i = 0; i < ring->stats.limit; i++) {
485 entry[i].ring = ring;
494 static int rt2x00lib_allocate_rings(struct rt2x00_dev *rt2x00dev)
496 struct data_ring *ring;
499 * Allocate the RX ring.
501 if (rt2x00lib_alloc_ring(rt2x00dev->rx,
502 RX_ENTRIES, DATA_FRAME_SIZE, rt2x00dev->ops->rxd_size))
506 * First allocate the TX rings.
508 txring_for_each(rt2x00dev, ring) {
509 if (rt2x00lib_alloc_ring(ring,
510 TX_ENTRIES, DATA_FRAME_SIZE, rt2x00dev->ops->txd_size))
515 * Allocate the BEACON ring.
517 if (rt2x00lib_alloc_ring(&rt2x00dev->bcn[0],
518 BEACON_ENTRIES, MGMT_FRAME_SIZE, rt2x00dev->ops->txd_size))
522 * Allocate the Atim ring.
524 if (test_bit(DEVICE_SUPPORT_ATIM, &rt2x00dev->flags)) {
525 if (rt2x00lib_alloc_ring(&rt2x00dev->bcn[1],
526 ATIM_ENTRIES, DATA_FRAME_SIZE, rt2x00dev->ops->txd_size))
533 static void rt2x00lib_free_rings(struct rt2x00_dev *rt2x00dev)
535 struct data_ring *ring;
537 ring_for_each(rt2x00dev, ring) {
543 int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
547 if (test_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
551 * Allocate all data rings.
553 status = rt2x00lib_allocate_rings(rt2x00dev);
555 ERROR(rt2x00dev, "DMA allocation failed.\n");
560 * Initialize the device.
562 status = rt2x00dev->ops->lib->initialize(rt2x00dev);
566 __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
569 * Register the rfkill handler.
571 status = rt2x00lib_register_rfkill(rt2x00dev);
573 goto exit_unitialize;
578 rt2x00lib_uninitialize(rt2x00dev);
581 rt2x00lib_free_rings(rt2x00dev);
586 void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
588 if (!__test_and_clear_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
592 * Flush out all pending work.
594 flush_workqueue(rt2x00dev->workqueue);
599 rt2x00lib_unregister_rfkill(rt2x00dev);
602 * Allow the HW to uninitialize.
604 rt2x00dev->ops->lib->uninitialize(rt2x00dev);
607 * Free allocated datarings.
609 rt2x00lib_free_rings(rt2x00dev);
613 * driver allocation handlers.
615 static int rt2x00lib_alloc_rings(struct rt2x00_dev *rt2x00dev)
617 struct data_ring *ring;
618 unsigned int ring_num;
621 * We need the following rings:
625 * Atim: 1 (if supported)
627 ring_num = 2 + rt2x00dev->hw->queues +
628 test_bit(DEVICE_SUPPORT_ATIM, &rt2x00dev->flags);
630 ring = kzalloc(sizeof(*ring) * ring_num, GFP_KERNEL);
632 ERROR(rt2x00dev, "Ring allocation failed.\n");
637 * Initialize pointers
639 rt2x00dev->rx = &ring[0];
640 rt2x00dev->tx = &ring[1];
641 rt2x00dev->bcn = &ring[1 + rt2x00dev->hw->queues];
644 * Initialize ring parameters.
646 * cw_max: 2^10 = 1024.
648 ring_for_each(rt2x00dev, ring) {
649 ring->rt2x00dev = rt2x00dev;
650 ring->tx_params.aifs = 2;
651 ring->tx_params.cw_min = 5;
652 ring->tx_params.cw_max = 10;
658 int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
660 int retval = -ENOMEM;
665 rt2x00dev->workqueue = create_singlethread_workqueue(DRV_NAME);
666 if (!rt2x00dev->workqueue)
670 * Let the driver probe the device to detect the capabilities.
672 retval = rt2x00dev->ops->lib->init_hw(rt2x00dev);
674 ERROR(rt2x00dev, "Failed to allocate device.\n");
679 * Initialize configuration work.
681 INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
684 * Reset current working type.
686 rt2x00dev->interface.type = -EINVAL;
689 * Allocate ring array.
691 retval = rt2x00lib_alloc_rings(rt2x00dev);
696 * Initialize ieee80211 structure.
698 retval = rt2x00lib_init_hw(rt2x00dev);
700 ERROR(rt2x00dev, "Failed to initialize hw.\n");
707 retval = rt2x00lib_allocate_rfkill(rt2x00dev);
712 * Open the debugfs entry.
714 rt2x00debug_register(rt2x00dev);
717 * Check if we need to load the firmware.
719 if (test_bit(FIRMWARE_REQUIRED, &rt2x00dev->flags)) {
721 * Request firmware and wait with further
722 * initializing of the card until the firmware
725 retval = rt2x00lib_load_firmware(rt2x00dev);
733 rt2x00lib_remove_dev(rt2x00dev);
737 EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
739 void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
744 rt2x00lib_disable_radio(rt2x00dev);
747 * Uninitialize device.
749 rt2x00lib_uninitialize(rt2x00dev);
752 * Close debugfs entry.
754 rt2x00debug_deregister(rt2x00dev);
759 rt2x00lib_free_rfkill(rt2x00dev);
762 * Free ieee80211_hw memory.
764 rt2x00lib_deinit_hw(rt2x00dev);
769 if (likely(rt2x00dev->workqueue)) {
770 destroy_workqueue(rt2x00dev->workqueue);
771 rt2x00dev->workqueue = NULL;
775 * Free ring structures.
777 kfree(rt2x00dev->rx);
778 rt2x00dev->rx = NULL;
779 rt2x00dev->tx = NULL;
780 rt2x00dev->bcn = NULL;
783 * Free EEPROM memory.
785 kfree(rt2x00dev->eeprom);
786 rt2x00dev->eeprom = NULL;
788 EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
791 * Device state handlers
793 int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev,
798 NOTICE(rt2x00dev, "Going to sleep.\n");
800 rt2x00lib_disable_radio(rt2x00dev);
803 * Set device mode to sleep for power management.
805 retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP);
809 rt2x00lib_remove_dev(rt2x00dev);
813 EXPORT_SYMBOL_GPL(rt2x00lib_suspend);
815 int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
819 NOTICE(rt2x00dev, "Waking up.\n");
821 retval = rt2x00lib_probe_dev(rt2x00dev);
823 ERROR(rt2x00dev, "Failed to allocate device.\n");
828 * Set device mode to awake for power management.
830 retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE);
836 EXPORT_SYMBOL_GPL(rt2x00lib_resume);
839 * Interrupt context handlers.
841 void rt2x00lib_txdone(struct data_entry *entry,
842 const int status, const int retry)
844 struct rt2x00_dev *rt2x00dev = entry->ring->rt2x00dev;
845 struct ieee80211_tx_status *tx_status = &entry->tx_status;
846 struct ieee80211_low_level_stats *stats = &rt2x00dev->low_level_stats;
849 * Update TX statistics.
851 tx_status->flags = 0;
852 tx_status->ack_signal = 0;
853 tx_status->excessive_retries = (status == TX_FAIL_RETRY);
854 tx_status->retry_count = retry;
856 if (!(tx_status->control.flags & IEEE80211_TXCTL_NO_ACK)) {
857 if (status == TX_SUCCESS || status == TX_SUCCESS_RETRY)
858 tx_status->flags |= IEEE80211_TX_STATUS_ACK;
860 stats->dot11ACKFailureCount++;
863 tx_status->queue_length = entry->ring->stats.limit;
864 tx_status->queue_number = tx_status->control.queue;
866 if (tx_status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) {
867 if (status == TX_SUCCESS || status == TX_SUCCESS_RETRY)
868 stats->dot11RTSSuccessCount++;
870 stats->dot11RTSFailureCount++;
874 * Send the tx_status to mac80211,
875 * that method also cleans up the skb structure.
877 ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb, tx_status);
881 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
883 void rt2x00lib_rxdone(struct data_entry *entry, char *data,
884 const int size, const int signal, const int rssi, const int ofdm)
886 struct rt2x00_dev *rt2x00dev = entry->ring->rt2x00dev;
887 struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
888 struct ieee80211_hw_mode *mode;
889 struct ieee80211_rate *rate;
895 * Update RX statistics.
897 mode = &rt2x00dev->hwmodes[rt2x00dev->curr_hwmode];
898 for (i = 0; i < mode->num_rates; i++) {
899 rate = &mode->rates[i];
902 * When frame was received with an OFDM bitrate,
903 * the signal is the PLCP value. If it was received with
904 * a CCK bitrate the signal is the rate in 0.5kbit/s.
907 val = DEVICE_GET_RATE_FIELD(rate->val, RATE);
909 val = DEVICE_GET_RATE_FIELD(rate->val, PLCP);
913 * Check for preamble bit.
922 rx_status->rate = val;
923 rx_status->ssi = rssi;
924 rx_status->noise = rt2x00dev->link.curr_noise;
925 rt2x00_update_link_rssi(&rt2x00dev->link, rssi);
928 * Let's allocate a sk_buff where we can store the received data in,
929 * note that if data is NULL, we still have to allocate a sk_buff
930 * but that we should use that to replace the sk_buff which is already
933 skb = dev_alloc_skb(size + NET_IP_ALIGN);
937 skb_reserve(skb, NET_IP_ALIGN);
941 memcpy(skb->data, data, size);
946 ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status);
949 EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
952 * TX descriptor initializer
954 void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
955 struct data_entry *entry, struct data_desc *txd,
956 struct ieee80211_hdr *ieee80211hdr, unsigned int length,
957 struct ieee80211_tx_control *control)
959 struct data_entry_desc desc;
970 if (control->queue < rt2x00dev->hw->queues)
971 desc.queue = control->queue;
976 * Read required fields from ieee80211 header.
978 frame_control = le16_to_cpu(ieee80211hdr->frame_control);
979 seq_ctrl = le16_to_cpu(ieee80211hdr->seq_ctrl);
981 tx_rate = control->tx_rate;
984 * Check if this is a rts frame
986 if (is_rts_frame(frame_control)) {
987 __set_bit(ENTRY_TXD_RTS_FRAME, &entry->flags);
988 if (control->rts_cts_rate)
989 tx_rate = control->rts_cts_rate;
995 if (DEVICE_GET_RATE_FIELD(tx_rate, RATEMASK) & DEV_OFDM_RATE)
996 __set_bit(ENTRY_TXD_OFDM_RATE, &entry->flags);
999 * Check if more fragments are pending
1001 if (ieee80211_get_morefrag(ieee80211hdr))
1002 __set_bit(ENTRY_TXD_MORE_FRAG, &entry->flags);
1005 * Check if this is a new sequence
1007 if ((seq_ctrl & IEEE80211_SCTL_FRAG) == 0)
1008 __set_bit(ENTRY_TXD_NEW_SEQ, &entry->flags);
1011 * Beacons and probe responses require the tsf timestamp
1012 * to be inserted into the frame.
1014 if (control->queue == IEEE80211_TX_QUEUE_BEACON ||
1015 is_probe_resp(frame_control))
1016 __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &entry->flags);
1019 * Check if ACK is required
1021 if (!(control->flags & IEEE80211_TXCTL_NO_ACK))
1022 __set_bit(ENTRY_TXD_REQ_ACK, &entry->flags);
1025 * Determine with what IFS priority this frame should be send.
1026 * Set ifs to IFS_SIFS when the this is not the first fragment,
1027 * or this fragment came after RTS/CTS.
1029 if ((seq_ctrl & IEEE80211_SCTL_FRAG) > 0 ||
1030 test_bit(ENTRY_TXD_RTS_FRAME, &entry->flags))
1031 desc.ifs = IFS_SIFS;
1033 desc.ifs = IFS_BACKOFF;
1036 * How the length should be processed depends
1037 * on if we are working with OFDM rates or not.
1039 if (test_bit(ENTRY_TXD_OFDM_RATE, &entry->flags)) {
1041 desc.length_high = ((length + FCS_LEN) >> 6) & 0x3f;
1042 desc.length_low = ((length + FCS_LEN) & 0x3f);
1045 bitrate = DEVICE_GET_RATE_FIELD(tx_rate, RATE);
1048 * Convert length to microseconds.
1050 residual = get_duration_res(length + FCS_LEN, bitrate);
1051 duration = get_duration(length + FCS_LEN, bitrate);
1056 desc.length_high = duration >> 8;
1057 desc.length_low = duration & 0xff;
1061 * Create the signal and service values.
1063 desc.signal = DEVICE_GET_RATE_FIELD(tx_rate, PLCP);
1064 if (DEVICE_GET_RATE_FIELD(tx_rate, PREAMBLE))
1065 desc.signal |= 0x08;
1067 desc.service = 0x04;
1068 if (residual <= (8 % 11))
1069 desc.service |= 0x80;
1071 rt2x00dev->ops->lib->write_tx_desc(rt2x00dev, entry, txd, &desc,
1072 ieee80211hdr, length, control);
1074 EXPORT_SYMBOL_GPL(rt2x00lib_write_tx_desc);
1077 * rt2x00lib module information.
1079 MODULE_AUTHOR(DRV_PROJECT);
1080 MODULE_VERSION(DRV_VERSION);
1081 MODULE_DESCRIPTION("rt2x00 library");
1082 MODULE_LICENSE("GPL");