rt2x00: Fix rt2500usb HW crypto: WEP 128 & AES
[safe/jmp/linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00.h
index 6c72542..39ecf3b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-       Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
+       Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
        <http://rt2x00.serialmonkey.com>
 
        This program is free software; you can redistribute it and/or modify
 #define RT2X00_H
 
 #include <linux/bitops.h>
-#include <linux/prefetch.h>
 #include <linux/skbuff.h>
 #include <linux/workqueue.h>
 #include <linux/firmware.h>
+#include <linux/leds.h>
 #include <linux/mutex.h>
 #include <linux/etherdevice.h>
 
 #include <net/mac80211.h>
 
 #include "rt2x00debug.h"
+#include "rt2x00leds.h"
 #include "rt2x00reg.h"
-#include "rt2x00ring.h"
+#include "rt2x00queue.h"
 
 /*
  * Module information.
  */
-#define DRV_VERSION    "2.0.14"
+#define DRV_VERSION    "2.2.3"
 #define DRV_PROJECT    "http://rt2x00.serialmonkey.com"
 
 /*
  */
 #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...)    \
        printk(__kernlvl "%s -> %s: %s - " __msg,                       \
-              wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args)
+              wiphy_name((__dev)->hw->wiphy), __func__, __lvl, ##__args)
 
 #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
        printk(__kernlvl "%s -> %s: %s - " __msg,               \
-              KBUILD_MODNAME, __FUNCTION__, __lvl, ##__args)
+              KBUILD_MODNAME, __func__, __lvl, ##__args)
 
 #ifdef CONFIG_RT2X00_DEBUG
 #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...)        \
        DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
 
 /*
- * Ring sizes.
- * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes.
- * DATA_FRAME_SIZE is used for TX, RX, ATIM and PRIO rings.
- * MGMT_FRAME_SIZE is used for the BEACON ring.
- */
-#define DATA_FRAME_SIZE        2432
-#define MGMT_FRAME_SIZE        256
-
-/*
- * Number of entries in a packet ring.
- * PCI devices only need 1 Beacon entry,
- * but USB devices require a second because they
- * have to send a Guardian byte first.
+ * Duration calculations
+ * The rate variable passed is: 100kbs.
+ * To convert from bytes to bits we multiply size with 8,
+ * then the size is multiplied with 10 to make the
+ * real rate -> rate argument correction.
  */
-#define RX_ENTRIES     12
-#define TX_ENTRIES     12
-#define ATIM_ENTRIES   1
-#define BEACON_ENTRIES 2
+#define GET_DURATION(__size, __rate)   (((__size) * 8 * 10) / (__rate))
+#define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
 
 /*
  * Standard timing and size defines.
 #define SHORT_PIFS             ( SIFS + SHORT_SLOT_TIME )
 #define DIFS                   ( PIFS + SLOT_TIME )
 #define SHORT_DIFS             ( SHORT_PIFS + SHORT_SLOT_TIME )
-#define EIFS                   ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
-
-/*
- * IEEE802.11 header defines
- */
-static inline int is_rts_frame(u16 fc)
-{
-       return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
-               ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS));
-}
-
-static inline int is_cts_frame(u16 fc)
-{
-       return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
-               ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS));
-}
-
-static inline int is_probe_resp(u16 fc)
-{
-       return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
-               ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP));
-}
-
-static inline int is_beacon(u16 fc)
-{
-       return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
-               ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON));
-}
+#define EIFS                   ( SIFS + DIFS + \
+                                 GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10) )
+#define SHORT_EIFS             ( SIFS + SHORT_DIFS + \
+                                 GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10) )
 
 /*
  * Chipset identification
@@ -187,6 +154,17 @@ struct rf_channel {
 };
 
 /*
+ * Channel information structure
+ */
+struct channel_info {
+       unsigned int flags;
+#define GEOGRAPHY_ALLOWED      0x00000001
+
+       short tx_power1;
+       short tx_power2;
+};
+
+/*
  * Antenna setup values.
  */
 struct antenna_setup {
@@ -347,6 +325,11 @@ static inline int rt2x00_get_link_ant_rssi(struct link *link)
        return DEFAULT_RSSI;
 }
 
+static inline void rt2x00_reset_link_ant_rssi(struct link *link)
+{
+       link->ant.rssi_ant = 0;
+}
+
 static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
                                                   enum antenna ant)
 {
@@ -364,20 +347,15 @@ static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
 
 /*
  * Interface structure
- * Configuration details about the current interface.
+ * Per interface configuration details, this structure
+ * is allocated as the private data for ieee80211_vif.
  */
-struct interface {
-       /*
-        * Interface identification. The value is assigned
-        * to us by the 80211 stack, and is used to request
-        * new beacons.
-        */
-       struct ieee80211_vif *id;
-
+struct rt2x00_intf {
        /*
-        * Current working type (IEEE80211_IF_TYPE_*).
+        * All fields within the rt2x00_intf structure
+        * must be protected with a spinlock.
         */
-       int type;
+       spinlock_t lock;
 
        /*
         * MAC of the device.
@@ -388,42 +366,62 @@ struct interface {
         * BBSID of the AP to associate with.
         */
        u8 bssid[ETH_ALEN];
-};
 
-static inline int is_interface_present(struct interface *intf)
-{
-       return !!intf->id;
-}
+       /*
+        * Entry in the beacon queue which belongs to
+        * this interface. Each interface has its own
+        * dedicated beacon entry.
+        */
+       struct queue_entry *beacon;
 
-static inline int is_interface_type(struct interface *intf, int type)
+       /*
+        * Actions that needed rescheduling.
+        */
+       unsigned int delayed_flags;
+#define DELAYED_UPDATE_BEACON          0x00000001
+#define DELAYED_CONFIG_ERP             0x00000002
+#define DELAYED_LED_ASSOC              0x00000004
+
+       /*
+        * Software sequence counter, this is only required
+        * for hardware which doesn't support hardware
+        * sequence counting.
+        */
+       spinlock_t seqlock;
+       u16 seqno;
+};
+
+static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
 {
-       return intf->type == type;
+       return (struct rt2x00_intf *)vif->drv_priv;
 }
 
-/*
+/**
+ * struct hw_mode_spec: Hardware specifications structure
+ *
  * Details about the supported modes, rates and channels
  * of a particular chipset. This is used by rt2x00lib
  * to build the ieee80211_hw_mode array for mac80211.
+ *
+ * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
+ * @supported_rates: Rate types which are supported (CCK, OFDM).
+ * @num_channels: Number of supported channels. This is used as array size
+ *     for @tx_power_a, @tx_power_bg and @channels.
+ * @channels: Device/chipset specific channel values (See &struct rf_channel).
+ * @channels_info: Additional information for channels (See &struct channel_info).
  */
 struct hw_mode_spec {
-       /*
-        * Number of modes, rates and channels.
-        */
-       int num_modes;
-       int num_rates;
-       int num_channels;
+       unsigned int supported_bands;
+#define SUPPORT_BAND_2GHZ      0x00000001
+#define SUPPORT_BAND_5GHZ      0x00000002
 
-       /*
-        * txpower values.
-        */
-       const u8 *tx_power_a;
-       const u8 *tx_power_bg;
-       u8 tx_power_default;
+       unsigned int supported_rates;
+#define SUPPORT_RATE_CCK       0x00000001
+#define SUPPORT_RATE_OFDM      0x00000002
 
-       /*
-        * Device/chipset specific value.
-        */
+       unsigned int num_channels;
        const struct rf_channel *channels;
+       const struct channel_info *channels_info;
 };
 
 /*
@@ -435,13 +433,23 @@ struct hw_mode_spec {
  */
 struct rt2x00lib_conf {
        struct ieee80211_conf *conf;
+
        struct rf_channel rf;
+       struct channel_info channel;
+};
+
+/*
+ * Configuration structure for erp settings.
+ */
+struct rt2x00lib_erp {
+       int short_preamble;
+       int cts_protection;
 
-       struct antenna_setup ant;
+       int ack_timeout;
+       int ack_consume_time;
 
-       int phymode;
+       u64 basic_rates;
 
-       int basic_rates;
        int slot_time;
 
        short sifs;
@@ -451,6 +459,54 @@ struct rt2x00lib_conf {
 };
 
 /*
+ * Configuration structure for hardware encryption.
+ */
+struct rt2x00lib_crypto {
+       enum cipher cipher;
+
+       enum set_key_cmd cmd;
+       const u8 *address;
+
+       u32 bssidx;
+       u32 aid;
+
+       u8 key[16];
+       u8 tx_mic[8];
+       u8 rx_mic[8];
+};
+
+/*
+ * Configuration structure wrapper around the
+ * rt2x00 interface configuration handler.
+ */
+struct rt2x00intf_conf {
+       /*
+        * Interface type
+        */
+       enum nl80211_iftype type;
+
+       /*
+        * TSF sync value, this is dependant on the operation type.
+        */
+       enum tsf_sync sync;
+
+       /*
+        * The MAC and BSSID addressess are simple array of bytes,
+        * these arrays are little endian, so when sending the addressess
+        * to the drivers, copy the it into a endian-signed variable.
+        *
+        * Note that all devices (except rt2500usb) have 32 bits
+        * register word sizes. This means that whatever variable we
+        * pass _must_ be a multiple of 32 bits. Otherwise the device
+        * might not accept what we are sending to it.
+        * This will also make it easier for the driver to write
+        * the data to the device.
+        */
+       __le32 mac[2];
+       __le32 bssid[2];
+};
+
+/*
  * rt2x00lib callback functions.
  */
 struct rt2x00lib_ops {
@@ -464,7 +520,8 @@ struct rt2x00lib_ops {
         */
        int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
        char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
-       int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
+       u16 (*get_firmware_crc) (const void *data, const size_t len);
+       int (*load_firmware) (struct rt2x00_dev *rt2x00dev, const void *data,
                              const size_t len);
 
        /*
@@ -474,12 +531,10 @@ struct rt2x00lib_ops {
        void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
 
        /*
-        * Ring initialization handlers
+        * queue initialization handlers
         */
-       void (*init_rxentry) (struct rt2x00_dev *rt2x00dev,
-                             struct data_entry *entry);
-       void (*init_txentry) (struct rt2x00_dev *rt2x00dev,
-                             struct data_entry *entry);
+       bool (*get_entry_state) (struct queue_entry *entry);
+       void (*clear_entry) (struct queue_entry *entry);
 
        /*
         * Radio control handlers.
@@ -497,42 +552,45 @@ struct rt2x00lib_ops {
         */
        void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
                               struct sk_buff *skb,
-                              struct txdata_entry_desc *desc,
-                              struct ieee80211_tx_control *control);
-       int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
-                             struct data_ring *ring, struct sk_buff *skb,
-                             struct ieee80211_tx_control *control);
-       int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
-                               struct sk_buff *skb);
+                              struct txentry_desc *txdesc);
+       int (*write_tx_data) (struct queue_entry *entry);
+       void (*write_beacon) (struct queue_entry *entry);
+       int (*get_tx_data_len) (struct queue_entry *entry);
        void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
-                              unsigned int queue);
+                              const enum data_queue_qid queue);
 
        /*
         * RX control handlers
         */
-       void (*fill_rxdone) (struct data_entry *entry,
-                            struct rxdata_entry_desc *desc);
+       void (*fill_rxdone) (struct queue_entry *entry,
+                            struct rxdone_entry_desc *rxdesc);
 
        /*
         * Configuration handlers.
         */
-       void (*config_mac_addr) (struct rt2x00_dev *rt2x00dev, __le32 *mac);
-       void (*config_bssid) (struct rt2x00_dev *rt2x00dev, __le32 *bssid);
-       void (*config_type) (struct rt2x00_dev *rt2x00dev, const int type,
-                                                          const int tsf_sync);
-       void (*config_preamble) (struct rt2x00_dev *rt2x00dev,
-                                const int short_preamble,
-                                const int ack_timeout,
-                                const int ack_consume_time);
-       void (*config) (struct rt2x00_dev *rt2x00dev, const unsigned int flags,
-                       struct rt2x00lib_conf *libconf);
-#define CONFIG_UPDATE_PHYMODE          ( 1 << 1 )
-#define CONFIG_UPDATE_CHANNEL          ( 1 << 2 )
-#define CONFIG_UPDATE_TXPOWER          ( 1 << 3 )
-#define CONFIG_UPDATE_ANTENNA          ( 1 << 4 )
-#define CONFIG_UPDATE_SLOT_TIME        ( 1 << 5 )
-#define CONFIG_UPDATE_BEACON_INT       ( 1 << 6 )
-#define CONFIG_UPDATE_ALL              0xffff
+       int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
+                                 struct rt2x00lib_crypto *crypto,
+                                 struct ieee80211_key_conf *key);
+       int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
+                                   struct rt2x00lib_crypto *crypto,
+                                   struct ieee80211_key_conf *key);
+       void (*config_filter) (struct rt2x00_dev *rt2x00dev,
+                              const unsigned int filter_flags);
+       void (*config_intf) (struct rt2x00_dev *rt2x00dev,
+                            struct rt2x00_intf *intf,
+                            struct rt2x00intf_conf *conf,
+                            const unsigned int flags);
+#define CONFIG_UPDATE_TYPE             ( 1 << 1 )
+#define CONFIG_UPDATE_MAC              ( 1 << 2 )
+#define CONFIG_UPDATE_BSSID            ( 1 << 3 )
+
+       void (*config_erp) (struct rt2x00_dev *rt2x00dev,
+                           struct rt2x00lib_erp *erp);
+       void (*config_ant) (struct rt2x00_dev *rt2x00dev,
+                           struct antenna_setup *ant);
+       void (*config) (struct rt2x00_dev *rt2x00dev,
+                       struct rt2x00lib_conf *libconf,
+                       const unsigned int changed_flags);
 };
 
 /*
@@ -540,10 +598,15 @@ struct rt2x00lib_ops {
  */
 struct rt2x00_ops {
        const char *name;
-       const unsigned int rxd_size;
-       const unsigned int txd_size;
+       const unsigned int max_sta_intf;
+       const unsigned int max_ap_intf;
        const unsigned int eeprom_size;
        const unsigned int rf_size;
+       const unsigned int tx_queues;
+       const struct data_queue_desc *rx;
+       const struct data_queue_desc *tx;
+       const struct data_queue_desc *bcn;
+       const struct data_queue_desc *atim;
        const struct rt2x00lib_ops *lib;
        const struct ieee80211_ops *hw;
 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
@@ -558,31 +621,39 @@ enum rt2x00_flags {
        /*
         * Device state flags
         */
-       DEVICE_PRESENT,
-       DEVICE_REGISTERED_HW,
-       DEVICE_INITIALIZED,
-       DEVICE_STARTED,
-       DEVICE_STARTED_SUSPEND,
-       DEVICE_ENABLED_RADIO,
-       DEVICE_DISABLED_RADIO_HW,
+       DEVICE_STATE_PRESENT,
+       DEVICE_STATE_REGISTERED_HW,
+       DEVICE_STATE_INITIALIZED,
+       DEVICE_STATE_STARTED,
+       DEVICE_STATE_STARTED_SUSPEND,
+       DEVICE_STATE_ENABLED_RADIO,
+       DEVICE_STATE_DISABLED_RADIO_HW,
 
        /*
-        * Driver features
+        * Driver requirements
         */
        DRIVER_REQUIRE_FIRMWARE,
-       DRIVER_REQUIRE_BEACON_RING,
+       DRIVER_REQUIRE_BEACON_GUARD,
+       DRIVER_REQUIRE_ATIM_QUEUE,
+       DRIVER_REQUIRE_SCHEDULED,
+       DRIVER_REQUIRE_DMA,
 
        /*
-        * Driver configuration
+        * Driver features
         */
        CONFIG_SUPPORT_HW_BUTTON,
+       CONFIG_SUPPORT_HW_CRYPTO,
+
+       /*
+        * Driver configuration
+        */
        CONFIG_FRAME_TYPE,
        CONFIG_RF_SEQUENCE,
        CONFIG_EXTERNAL_LNA_A,
        CONFIG_EXTERNAL_LNA_BG,
        CONFIG_DOUBLE_ANTENNA,
        CONFIG_DISABLE_LINK_TUNING,
-       CONFIG_SHORT_PREAMBLE,
+       CONFIG_CRYPTO_COPY_IV,
 };
 
 /*
@@ -596,9 +667,7 @@ struct rt2x00_dev {
         * When accessing this variable, the rt2x00dev_{pci,usb}
         * macro's should be used for correct typecasting.
         */
-       void *dev;
-#define rt2x00dev_pci(__dev)   ( (struct pci_dev*)(__dev)->dev )
-#define rt2x00dev_usb(__dev)   ( (struct usb_interface*)(__dev)->dev )
+       struct device *dev;
 
        /*
         * Callback functions.
@@ -609,22 +678,19 @@ struct rt2x00_dev {
         * IEEE80211 control structure.
         */
        struct ieee80211_hw *hw;
-       struct ieee80211_hw_mode *hwmodes;
-       unsigned int curr_hwmode;
-#define HWMODE_B       0
-#define HWMODE_G       1
-#define HWMODE_A       2
+       struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
+       enum ieee80211_band curr_band;
 
        /*
         * rfkill structure for RF state switching support.
         * This will only be compiled in when required.
         */
 #ifdef CONFIG_RT2X00_LIB_RFKILL
-unsigned long rfkill_state;
+       unsigned long rfkill_state;
 #define RFKILL_STATE_ALLOCATED         1
 #define RFKILL_STATE_REGISTERED                2
        struct rfkill *rfkill;
-       struct input_polled_dev *poll_dev;
+       struct delayed_work rfkill_work;
 #endif /* CONFIG_RT2X00_LIB_RFKILL */
 
        /*
@@ -636,6 +702,17 @@ unsigned long rfkill_state;
 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
 
        /*
+        * LED structure for changing the LED status
+        * by mac8011 or the kernel.
+        */
+#ifdef CONFIG_RT2X00_LIB_LEDS
+       struct rt2x00_led led_radio;
+       struct rt2x00_led led_assoc;
+       struct rt2x00_led led_qual;
+       u16 led_mcu_reg;
+#endif /* CONFIG_RT2X00_LIB_LEDS */
+
+       /*
         * Device flags.
         * In these flags the current status and some
         * of the device capabilities are stored.
@@ -654,30 +731,30 @@ unsigned long rfkill_state;
 
        /*
         * This is the default TX/RX antenna setup as indicated
-        * by the device's EEPROM. When mac80211 sets its
-        * antenna value to 0 we should be using these values.
+        * by the device's EEPROM.
         */
        struct antenna_setup default_ant;
 
        /*
         * Register pointers
-        * csr_addr: Base register address. (PCI)
-        * csr_cache: CSR cache for usb_control_msg. (USB)
+        * csr.base: CSR base register address. (PCI)
+        * csr.cache: CSR cache for usb_control_msg. (USB)
         */
-       void __iomem *csr_addr;
-       void *csr_cache;
+       union csr {
+               void __iomem *base;
+               void *cache;
+       } csr;
 
        /*
-        * Mutex to protect register accesses on USB devices.
-        * There are 2 reasons this is needed, one is to ensure
-        * use of the csr_cache (for USB devices) by one thread
-        * isn't corrupted by another thread trying to access it.
-        * The other is that access to BBP and RF registers
-        * require multiple BUS transactions and if another thread
-        * attempted to access one of those registers at the same
-        * time one of the writes could silently fail.
+        * Mutex to protect register accesses.
+        * For PCI and USB devices it protects against concurrent indirect
+        * register access (BBP, RF, MCU) since accessing those
+        * registers require multiple calls to the CSR registers.
+        * For USB devices it also protects the csr_cache since that
+        * field is used for normal CSR access and it cannot support
+        * multiple callers simultaneously.
         */
-       struct mutex usb_cache_mutex;
+       struct mutex csr_mutex;
 
        /*
         * Current packet filter configuration for the device.
@@ -687,9 +764,14 @@ unsigned long rfkill_state;
        unsigned int packet_filter;
 
        /*
-        * Interface configuration.
+        * Interface details:
+        *  - Open ap interface count.
+        *  - Open sta interface count.
+        *  - Association count.
         */
-       struct interface interface;
+       unsigned int intf_ap_count;
+       unsigned int intf_sta_count;
+       unsigned int intf_associated;
 
        /*
         * Link quality
@@ -712,9 +794,9 @@ unsigned long rfkill_state;
        u32 *rf;
 
        /*
-        * USB Max frame size (for rt2500usb & rt73usb).
+        * LNA gain
         */
-       u16 usb_maxpacket;
+       short lna_gain;
 
        /*
         * Current TX power value.
@@ -722,14 +804,10 @@ unsigned long rfkill_state;
        u16 tx_power;
 
        /*
-        * LED register (for rt61pci & rt73usb).
-        */
-       u16 led_reg;
-
-       /*
-        * Led mode (LED_MODE_*)
+        * Current retry values.
         */
-       u8 led_mode;
+       u8 short_retry;
+       u8 long_retry;
 
        /*
         * Rssi <-> Dbm offset
@@ -754,20 +832,22 @@ unsigned long rfkill_state;
 
        /*
         * Scheduled work.
+        * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
+        * which means it cannot be placed on the hw->workqueue
+        * due to RTNL locking requirements.
         */
-       struct work_struct beacon_work;
+       struct work_struct intf_work;
        struct work_struct filter_work;
-       struct work_struct config_work;
 
        /*
-        * Data ring arrays for RX, TX and Beacon.
-        * The Beacon array also contains the Atim ring
+        * Data queue arrays for RX, TX and Beacon.
+        * The Beacon array also contains the Atim queue
         * if that is supported by the device.
         */
-       int data_rings;
-       struct data_ring *rx;
-       struct data_ring *tx;
-       struct data_ring *bcn;
+       unsigned int data_queues;
+       struct data_queue *rx;
+       struct data_queue *tx;
+       struct data_queue *bcn;
 
        /*
         * Firmware image.
@@ -776,37 +856,6 @@ unsigned long rfkill_state;
 };
 
 /*
- * For-each loop for the ring array.
- * All rings have been allocated as a single array,
- * this means we can create a very simply loop macro
- * that is capable of looping through all rings.
- * ring_end(), txring_end() and ring_loop() are helper macro's which
- * should not be used directly. Instead the following should be used:
- * ring_for_each() - Loops through all rings (RX, TX, Beacon & Atim)
- * txring_for_each() - Loops through TX data rings (TX only)
- * txringall_for_each() - Loops through all TX rings (TX, Beacon & Atim)
- */
-#define ring_end(__dev) \
-       &(__dev)->rx[(__dev)->data_rings]
-
-#define txring_end(__dev) \
-       &(__dev)->tx[(__dev)->hw->queues]
-
-#define ring_loop(__entry, __start, __end)                     \
-       for ((__entry) = (__start);                             \
-            prefetch(&(__entry)[1]), (__entry) != (__end);     \
-            (__entry) = &(__entry)[1])
-
-#define ring_for_each(__dev, __entry) \
-       ring_loop(__entry, (__dev)->rx, ring_end(__dev))
-
-#define txring_for_each(__dev, __entry) \
-       ring_loop(__entry, (__dev)->tx, txring_end(__dev))
-
-#define txringall_for_each(__dev, __entry) \
-       ring_loop(__entry, (__dev)->tx, ring_end(__dev))
-
-/*
  * Generic RF access.
  * The RF is being accessed by word index.
  */
@@ -881,60 +930,63 @@ static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
                !!(chipset->rev & 0x0000f));
 }
 
-/*
- * Duration calculations
- * The rate variable passed is: 100kbs.
- * To convert from bytes to bits we multiply size with 8,
- * then the size is multiplied with 10 to make the
- * real rate -> rate argument correction.
+/**
+ * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
+ * @rt2x00dev: Pointer to &struct rt2x00_dev.
+ * @skb: The skb to map.
  */
-static inline u16 get_duration(const unsigned int size, const u8 rate)
-{
-       return ((size * 8 * 10) / rate);
-}
+void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
 
-static inline u16 get_duration_res(const unsigned int size, const u8 rate)
-{
-       return ((size * 8 * 10) % rate);
-}
+/**
+ * rt2x00queue_get_queue - Convert queue index to queue pointer
+ * @rt2x00dev: Pointer to &struct rt2x00_dev.
+ * @queue: rt2x00 queue index (see &enum data_queue_qid).
+ */
+struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
+                                        const enum data_queue_qid queue);
 
-/*
- * Library functions.
+/**
+ * rt2x00queue_get_entry - Get queue entry where the given index points to.
+ * @queue: Pointer to &struct data_queue from where we obtain the entry.
+ * @index: Index identifier for obtaining the correct index.
  */
-struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev,
-                                    const unsigned int queue);
+struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
+                                         enum queue_index index);
 
 /*
  * Interrupt context handlers.
  */
 void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
-void rt2x00lib_txdone(struct data_entry *entry,
-                     const int status, const int retry);
-void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb,
-                     struct rxdata_entry_desc *desc);
-
-/*
- * TX descriptor initializer
- */
-void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
-                            struct sk_buff *skb,
-                            struct ieee80211_tx_control *control);
+void rt2x00lib_txdone(struct queue_entry *entry,
+                     struct txdone_entry_desc *txdesc);
+void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
+                     struct queue_entry *entry);
 
 /*
  * mac80211 handlers.
  */
-int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
-                struct ieee80211_tx_control *control);
+int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
 int rt2x00mac_start(struct ieee80211_hw *hw);
 void rt2x00mac_stop(struct ieee80211_hw *hw);
 int rt2x00mac_add_interface(struct ieee80211_hw *hw,
                            struct ieee80211_if_init_conf *conf);
 void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
                                struct ieee80211_if_init_conf *conf);
-int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
+int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
 int rt2x00mac_config_interface(struct ieee80211_hw *hw,
                               struct ieee80211_vif *vif,
                               struct ieee80211_if_conf *conf);
+void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
+                               unsigned int changed_flags,
+                               unsigned int *total_flags,
+                               int mc_count, struct dev_addr_list *mc_list);
+#ifdef CONFIG_RT2X00_LIB_CRYPTO
+int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                     const u8 *local_address, const u8 *address,
+                     struct ieee80211_key_conf *key);
+#else
+#define rt2x00mac_set_key      NULL
+#endif /* CONFIG_RT2X00_LIB_CRYPTO */
 int rt2x00mac_get_stats(struct ieee80211_hw *hw,
                        struct ieee80211_low_level_stats *stats);
 int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
@@ -943,7 +995,7 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
                                struct ieee80211_vif *vif,
                                struct ieee80211_bss_conf *bss_conf,
                                u32 changes);
-int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
+int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
                      const struct ieee80211_tx_queue_params *params);
 
 /*