rt2x00: Move crypto TX descriptor handling to rt2x00crypto.c
[safe/jmp/linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00.h
index 0da8f97..39ecf3b 100644 (file)
@@ -44,7 +44,7 @@
 /*
  * Module information.
  */
-#define DRV_VERSION    "2.1.7"
+#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)
 
 /*
+ * 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 GET_DURATION(__size, __rate)   (((__size) * 8 * 10) / (__rate))
+#define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
+
+/*
  * Standard timing and size defines.
  * These values should follow the ieee80211 specifications.
  */
 #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
@@ -168,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 {
@@ -361,13 +358,6 @@ struct rt2x00_intf {
        spinlock_t lock;
 
        /*
-        * BSS configuration. Copied from the structure
-        * passed to us through the bss_info_changed()
-        * callback funtion.
-        */
-       struct ieee80211_bss_conf conf;
-
-       /*
         * MAC of the device.
         */
        u8 mac[ETH_ALEN];
@@ -391,6 +381,14 @@ struct rt2x00_intf {
 #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)
@@ -410,10 +408,7 @@ static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  * @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).
- * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL).
- * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
- * @tx_power_default: Default TX power value to use when either
- *     @tx_power_a or @tx_power_bg is missing.
+ * @channels_info: Additional information for channels (See &struct channel_info).
  */
 struct hw_mode_spec {
        unsigned int supported_bands;
@@ -426,10 +421,7 @@ struct hw_mode_spec {
 
        unsigned int num_channels;
        const struct rf_channel *channels;
-
-       const u8 *tx_power_a;
-       const u8 *tx_power_bg;
-       u8 tx_power_default;
+       const struct channel_info *channels_info;
 };
 
 /*
@@ -441,14 +433,24 @@ struct hw_mode_spec {
  */
 struct rt2x00lib_conf {
        struct ieee80211_conf *conf;
+
        struct rf_channel rf;
+       struct channel_info channel;
+};
 
-       struct antenna_setup ant;
+/*
+ * Configuration structure for erp settings.
+ */
+struct rt2x00lib_erp {
+       int short_preamble;
+       int cts_protection;
+
+       int ack_timeout;
+       int ack_consume_time;
 
-       enum ieee80211_band band;
+       u64 basic_rates;
 
-       u32 basic_rates;
-       u32 slot_time;
+       int slot_time;
 
        short sifs;
        short pifs;
@@ -457,13 +459,20 @@ struct rt2x00lib_conf {
 };
 
 /*
- * Configuration structure for erp settings.
+ * Configuration structure for hardware encryption.
  */
-struct rt2x00lib_erp {
-       int short_preamble;
+struct rt2x00lib_crypto {
+       enum cipher cipher;
 
-       int ack_timeout;
-       int ack_consume_time;
+       enum set_key_cmd cmd;
+       const u8 *address;
+
+       u32 bssidx;
+       u32 aid;
+
+       u8 key[16];
+       u8 tx_mic[8];
+       u8 rx_mic[8];
 };
 
 /*
@@ -474,7 +483,7 @@ struct rt2x00intf_conf {
        /*
         * Interface type
         */
-       enum ieee80211_if_types type;
+       enum nl80211_iftype type;
 
        /*
         * TSF sync value, this is dependant on the operation type.
@@ -511,8 +520,8 @@ struct rt2x00lib_ops {
         */
        int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
        char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
-       u16 (*get_firmware_crc) (void *data, const size_t len);
-       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);
 
        /*
@@ -524,10 +533,8 @@ struct rt2x00lib_ops {
        /*
         * queue initialization handlers
         */
-       void (*init_rxentry) (struct rt2x00_dev *rt2x00dev,
-                             struct queue_entry *entry);
-       void (*init_txentry) (struct rt2x00_dev *rt2x00dev,
-                             struct queue_entry *entry);
+       bool (*get_entry_state) (struct queue_entry *entry);
+       void (*clear_entry) (struct queue_entry *entry);
 
        /*
         * Radio control handlers.
@@ -547,8 +554,8 @@ struct rt2x00lib_ops {
                               struct sk_buff *skb,
                               struct txentry_desc *txdesc);
        int (*write_tx_data) (struct queue_entry *entry);
-       int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
-                               struct sk_buff *skb);
+       void (*write_beacon) (struct queue_entry *entry);
+       int (*get_tx_data_len) (struct queue_entry *entry);
        void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
                               const enum data_queue_qid queue);
 
@@ -561,6 +568,12 @@ struct rt2x00lib_ops {
        /*
         * Configuration handlers.
         */
+       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,
@@ -573,16 +586,11 @@ struct rt2x00lib_ops {
 
        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 flags);
-#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
+                       const unsigned int changed_flags);
 };
 
 /*
@@ -613,32 +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_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_CRYPTO_COPY_IV,
 };
 
 /*
@@ -652,11 +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 )
-#define rt2x00dev_usb_dev(__dev)\
-       ( (struct usb_device *)interface_to_usbdev(rt2x00dev_usb(__dev)) )
+       struct device *dev;
 
        /*
         * Callback functions.
@@ -679,7 +690,7 @@ struct rt2x00_dev {
 #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 */
 
        /*
@@ -720,8 +731,7 @@ struct rt2x00_dev {
 
        /*
         * 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;
 
@@ -736,16 +746,15 @@ struct rt2x00_dev {
        } 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.
@@ -785,9 +794,9 @@ struct rt2x00_dev {
        u32 *rf;
 
        /*
-        * USB Max frame size (for rt2500usb & rt73usb).
+        * LNA gain
         */
-       u16 usb_maxpacket;
+       short lna_gain;
 
        /*
         * Current TX power value.
@@ -795,6 +804,12 @@ struct rt2x00_dev {
        u16 tx_power;
 
        /*
+        * Current retry values.
+        */
+       u8 short_retry;
+       u8 long_retry;
+
+       /*
         * Rssi <-> Dbm offset
         */
        u8 rssi_offset;
@@ -817,6 +832,9 @@ struct rt2x00_dev {
 
        /*
         * 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 intf_work;
        struct work_struct filter_work;
@@ -912,61 +930,12 @@ 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.
- */
-static inline u16 get_duration(const unsigned int size, const u8 rate)
-{
-       return ((size * 8 * 10) / rate);
-}
-
-static inline u16 get_duration_res(const unsigned int size, const u8 rate)
-{
-       return ((size * 8 * 10) % rate);
-}
-
-/**
- * rt2x00queue_alloc_rxskb - allocate a skb for RX purposes.
- * @queue: The queue for which the skb will be applicable.
- */
-struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue);
-
-/**
- * rt2x00queue_create_tx_descriptor - Create TX descriptor from mac80211 input
- * @entry: The entry which will be used to transfer the TX frame.
- * @txdesc: rt2x00 TX descriptor which will be initialized by this function.
- *
- * This function will initialize the &struct txentry_desc based on information
- * from mac80211. This descriptor can then be used by rt2x00lib and the drivers
- * to correctly initialize the hardware descriptor.
- * Note that before calling this function the skb->cb array must be untouched
- * by rt2x00lib. Only after this function completes will it be save to
- * overwrite the skb->cb information.
- * The reason for this is that mac80211 writes its own tx information into
- * the skb->cb array, and this function will use that information to initialize
- * the &struct txentry_desc structure.
- */
-void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
-                                     struct txentry_desc *txdesc);
-
 /**
- * rt2x00queue_write_tx_descriptor - Write TX descriptor to hardware
- * @entry: The entry which will be used to transfer the TX frame.
- * @txdesc: TX descriptor which will be used to write hardware descriptor
- *
- * This function will write a TX descriptor initialized by
- * &rt2x00queue_create_tx_descriptor to the hardware. After this call
- * has completed the frame is now owned by the hardware, the hardware
- * queue will have automatically be kicked unless this frame was generated
- * by rt2x00lib, in which case the frame is "special" and must be kicked
- * by the caller.
+ * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
+ * @rt2x00dev: Pointer to &struct rt2x00_dev.
+ * @skb: The skb to map.
  */
-void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
-                                    struct txentry_desc *txdesc);
+void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
 
 /**
  * rt2x00queue_get_queue - Convert queue index to queue pointer
@@ -984,26 +953,14 @@ struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
 struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
                                          enum queue_index index);
 
-/**
- * rt2x00queue_index_inc - Index incrementation function
- * @queue: Queue (&struct data_queue) to perform the action on.
- * @index: Index type (&enum queue_index) to perform the action on.
- *
- * This function will increase the requested index on the queue,
- * it will grab the appropriate locks and handle queue overflow events by
- * resetting the index to the start of the queue.
- */
-void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index);
-
-
 /*
  * Interrupt context handlers.
  */
 void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
 void rt2x00lib_txdone(struct queue_entry *entry,
                      struct txdone_entry_desc *txdesc);
-void rt2x00lib_rxdone(struct queue_entry *entry,
-                     struct rxdone_entry_desc *rxdesc);
+void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
+                     struct queue_entry *entry);
 
 /*
  * mac80211 handlers.
@@ -1015,7 +972,7 @@ 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);
@@ -1023,6 +980,13 @@ 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,