Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003     Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
0004     Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
0005     Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
0006     <http://rt2x00.serialmonkey.com>
0007 
0008  */
0009 
0010 /*
0011     Module: rt2x00
0012     Abstract: rt2x00 global information.
0013  */
0014 
0015 #ifndef RT2X00_H
0016 #define RT2X00_H
0017 
0018 #include <linux/bitops.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/skbuff.h>
0021 #include <linux/workqueue.h>
0022 #include <linux/firmware.h>
0023 #include <linux/leds.h>
0024 #include <linux/mutex.h>
0025 #include <linux/etherdevice.h>
0026 #include <linux/kfifo.h>
0027 #include <linux/hrtimer.h>
0028 #include <linux/average.h>
0029 #include <linux/usb.h>
0030 #include <linux/clk.h>
0031 
0032 #include <net/mac80211.h>
0033 
0034 #include "rt2x00debug.h"
0035 #include "rt2x00dump.h"
0036 #include "rt2x00leds.h"
0037 #include "rt2x00reg.h"
0038 #include "rt2x00queue.h"
0039 
0040 /*
0041  * Module information.
0042  */
0043 #define DRV_VERSION "2.3.0"
0044 #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
0045 
0046 /* Debug definitions.
0047  * Debug output has to be enabled during compile time.
0048  */
0049 #ifdef CONFIG_RT2X00_DEBUG
0050 #define DEBUG
0051 #endif /* CONFIG_RT2X00_DEBUG */
0052 
0053 /* Utility printing macros
0054  * rt2x00_probe_err is for messages when rt2x00_dev is uninitialized
0055  */
0056 #define rt2x00_probe_err(fmt, ...)                  \
0057     printk(KERN_ERR KBUILD_MODNAME ": %s: Error - " fmt,        \
0058            __func__, ##__VA_ARGS__)
0059 #define rt2x00_err(dev, fmt, ...)                   \
0060     wiphy_err_ratelimited((dev)->hw->wiphy, "%s: Error - " fmt, \
0061           __func__, ##__VA_ARGS__)
0062 #define rt2x00_warn(dev, fmt, ...)                  \
0063     wiphy_warn_ratelimited((dev)->hw->wiphy, "%s: Warning - " fmt,  \
0064            __func__, ##__VA_ARGS__)
0065 #define rt2x00_info(dev, fmt, ...)                  \
0066     wiphy_info((dev)->hw->wiphy, "%s: Info - " fmt,         \
0067            __func__, ##__VA_ARGS__)
0068 
0069 /* Various debug levels */
0070 #define rt2x00_dbg(dev, fmt, ...)                   \
0071     wiphy_dbg((dev)->hw->wiphy, "%s: Debug - " fmt,         \
0072           __func__, ##__VA_ARGS__)
0073 #define rt2x00_eeprom_dbg(dev, fmt, ...)                \
0074     wiphy_dbg((dev)->hw->wiphy, "%s: EEPROM recovery - " fmt,   \
0075           __func__, ##__VA_ARGS__)
0076 
0077 /*
0078  * Duration calculations
0079  * The rate variable passed is: 100kbs.
0080  * To convert from bytes to bits we multiply size with 8,
0081  * then the size is multiplied with 10 to make the
0082  * real rate -> rate argument correction.
0083  */
0084 #define GET_DURATION(__size, __rate)    (((__size) * 8 * 10) / (__rate))
0085 #define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
0086 
0087 /*
0088  * Determine the number of L2 padding bytes required between the header and
0089  * the payload.
0090  */
0091 #define L2PAD_SIZE(__hdrlen)    (-(__hdrlen) & 3)
0092 
0093 /*
0094  * Determine the alignment requirement,
0095  * to make sure the 802.11 payload is padded to a 4-byte boundrary
0096  * we must determine the address of the payload and calculate the
0097  * amount of bytes needed to move the data.
0098  */
0099 #define ALIGN_SIZE(__skb, __header) \
0100     (((unsigned long)((__skb)->data + (__header))) & 3)
0101 
0102 /*
0103  * Constants for extra TX headroom for alignment purposes.
0104  */
0105 #define RT2X00_ALIGN_SIZE   4 /* Only whole frame needs alignment */
0106 #define RT2X00_L2PAD_SIZE   8 /* Both header & payload need alignment */
0107 
0108 /*
0109  * Standard timing and size defines.
0110  * These values should follow the ieee80211 specifications.
0111  */
0112 #define ACK_SIZE        14
0113 #define IEEE80211_HEADER    24
0114 #define PLCP            48
0115 #define BEACON          100
0116 #define PREAMBLE        144
0117 #define SHORT_PREAMBLE      72
0118 #define SLOT_TIME       20
0119 #define SHORT_SLOT_TIME     9
0120 #define SIFS            10
0121 #define PIFS            (SIFS + SLOT_TIME)
0122 #define SHORT_PIFS      (SIFS + SHORT_SLOT_TIME)
0123 #define DIFS            (PIFS + SLOT_TIME)
0124 #define SHORT_DIFS      (SHORT_PIFS + SHORT_SLOT_TIME)
0125 #define EIFS            (SIFS + DIFS + \
0126                   GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10))
0127 #define SHORT_EIFS      (SIFS + SHORT_DIFS + \
0128                   GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10))
0129 
0130 enum rt2x00_chip_intf {
0131     RT2X00_CHIP_INTF_PCI,
0132     RT2X00_CHIP_INTF_PCIE,
0133     RT2X00_CHIP_INTF_USB,
0134     RT2X00_CHIP_INTF_SOC,
0135 };
0136 
0137 /*
0138  * Chipset identification
0139  * The chipset on the device is composed of a RT and RF chip.
0140  * The chipset combination is important for determining device capabilities.
0141  */
0142 struct rt2x00_chip {
0143     u16 rt;
0144 #define RT2460      0x2460
0145 #define RT2560      0x2560
0146 #define RT2570      0x2570
0147 #define RT2661      0x2661
0148 #define RT2573      0x2573
0149 #define RT2860      0x2860  /* 2.4GHz */
0150 #define RT2872      0x2872  /* WSOC */
0151 #define RT2883      0x2883  /* WSOC */
0152 #define RT3070      0x3070
0153 #define RT3071      0x3071
0154 #define RT3090      0x3090  /* 2.4GHz PCIe */
0155 #define RT3290      0x3290
0156 #define RT3352      0x3352  /* WSOC */
0157 #define RT3390      0x3390
0158 #define RT3572      0x3572
0159 #define RT3593      0x3593
0160 #define RT3883      0x3883  /* WSOC */
0161 #define RT5350      0x5350  /* WSOC 2.4GHz */
0162 #define RT5390      0x5390  /* 2.4GHz */
0163 #define RT5392      0x5392  /* 2.4GHz */
0164 #define RT5592      0x5592
0165 #define RT6352      0x6352  /* WSOC 2.4GHz */
0166 
0167     u16 rf;
0168     u16 rev;
0169 
0170     enum rt2x00_chip_intf intf;
0171 };
0172 
0173 /*
0174  * RF register values that belong to a particular channel.
0175  */
0176 struct rf_channel {
0177     int channel;
0178     u32 rf1;
0179     u32 rf2;
0180     u32 rf3;
0181     u32 rf4;
0182 };
0183 
0184 /*
0185  * Information structure for channel survey.
0186  */
0187 struct rt2x00_chan_survey {
0188     u64 time_idle;
0189     u64 time_busy;
0190     u64 time_ext_busy;
0191 };
0192 
0193 /*
0194  * Channel information structure
0195  */
0196 struct channel_info {
0197     unsigned int flags;
0198 #define GEOGRAPHY_ALLOWED   0x00000001
0199 
0200     short max_power;
0201     short default_power1;
0202     short default_power2;
0203     short default_power3;
0204 };
0205 
0206 /*
0207  * Antenna setup values.
0208  */
0209 struct antenna_setup {
0210     enum antenna rx;
0211     enum antenna tx;
0212     u8 rx_chain_num;
0213     u8 tx_chain_num;
0214 };
0215 
0216 /*
0217  * Quality statistics about the currently active link.
0218  */
0219 struct link_qual {
0220     /*
0221      * Statistics required for Link tuning by driver
0222      * The rssi value is provided by rt2x00lib during the
0223      * link_tuner() callback function.
0224      * The false_cca field is filled during the link_stats()
0225      * callback function and could be used during the
0226      * link_tuner() callback function.
0227      */
0228     int rssi;
0229     int false_cca;
0230 
0231     /*
0232      * VGC levels
0233      * Hardware driver will tune the VGC level during each call
0234      * to the link_tuner() callback function. This vgc_level is
0235      * determined based on the link quality statistics like
0236      * average RSSI and the false CCA count.
0237      *
0238      * In some cases the drivers need to differentiate between
0239      * the currently "desired" VGC level and the level configured
0240      * in the hardware. The latter is important to reduce the
0241      * number of BBP register reads to reduce register access
0242      * overhead. For this reason we store both values here.
0243      */
0244     u8 vgc_level;
0245     u8 vgc_level_reg;
0246 
0247     /*
0248      * Statistics required for Signal quality calculation.
0249      * These fields might be changed during the link_stats()
0250      * callback function.
0251      */
0252     int rx_success;
0253     int rx_failed;
0254     int tx_success;
0255     int tx_failed;
0256 };
0257 
0258 DECLARE_EWMA(rssi, 10, 8)
0259 
0260 /*
0261  * Antenna settings about the currently active link.
0262  */
0263 struct link_ant {
0264     /*
0265      * Antenna flags
0266      */
0267     unsigned int flags;
0268 #define ANTENNA_RX_DIVERSITY    0x00000001
0269 #define ANTENNA_TX_DIVERSITY    0x00000002
0270 #define ANTENNA_MODE_SAMPLE 0x00000004
0271 
0272     /*
0273      * Currently active TX/RX antenna setup.
0274      * When software diversity is used, this will indicate
0275      * which antenna is actually used at this time.
0276      */
0277     struct antenna_setup active;
0278 
0279     /*
0280      * RSSI history information for the antenna.
0281      * Used to determine when to switch antenna
0282      * when using software diversity.
0283      */
0284     int rssi_history;
0285 
0286     /*
0287      * Current RSSI average of the currently active antenna.
0288      * Similar to the avg_rssi in the link_qual structure
0289      * this value is updated by using the walking average.
0290      */
0291     struct ewma_rssi rssi_ant;
0292 };
0293 
0294 /*
0295  * To optimize the quality of the link we need to store
0296  * the quality of received frames and periodically
0297  * optimize the link.
0298  */
0299 struct link {
0300     /*
0301      * Link tuner counter
0302      * The number of times the link has been tuned
0303      * since the radio has been switched on.
0304      */
0305     u32 count;
0306 
0307     /*
0308      * Quality measurement values.
0309      */
0310     struct link_qual qual;
0311 
0312     /*
0313      * TX/RX antenna setup.
0314      */
0315     struct link_ant ant;
0316 
0317     /*
0318      * Currently active average RSSI value
0319      */
0320     struct ewma_rssi avg_rssi;
0321 
0322     /*
0323      * Work structure for scheduling periodic link tuning.
0324      */
0325     struct delayed_work work;
0326 
0327     /*
0328      * Work structure for scheduling periodic watchdog monitoring.
0329      * This work must be scheduled on the kernel workqueue, while
0330      * all other work structures must be queued on the mac80211
0331      * workqueue. This guarantees that the watchdog can schedule
0332      * other work structures and wait for their completion in order
0333      * to bring the device/driver back into the desired state.
0334      */
0335     struct delayed_work watchdog_work;
0336     unsigned int watchdog_interval;
0337     bool watchdog_disabled;
0338 
0339     /*
0340      * Work structure for scheduling periodic AGC adjustments.
0341      */
0342     struct delayed_work agc_work;
0343 
0344     /*
0345      * Work structure for scheduling periodic VCO calibration.
0346      */
0347     struct delayed_work vco_work;
0348 };
0349 
0350 enum rt2x00_delayed_flags {
0351     DELAYED_UPDATE_BEACON,
0352 };
0353 
0354 /*
0355  * Interface structure
0356  * Per interface configuration details, this structure
0357  * is allocated as the private data for ieee80211_vif.
0358  */
0359 struct rt2x00_intf {
0360     /*
0361      * beacon->skb must be protected with the mutex.
0362      */
0363     struct mutex beacon_skb_mutex;
0364 
0365     /*
0366      * Entry in the beacon queue which belongs to
0367      * this interface. Each interface has its own
0368      * dedicated beacon entry.
0369      */
0370     struct queue_entry *beacon;
0371     bool enable_beacon;
0372 
0373     /*
0374      * Actions that needed rescheduling.
0375      */
0376     unsigned long delayed_flags;
0377 
0378     /*
0379      * Software sequence counter, this is only required
0380      * for hardware which doesn't support hardware
0381      * sequence counting.
0382      */
0383     atomic_t seqno;
0384 };
0385 
0386 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
0387 {
0388     return (struct rt2x00_intf *)vif->drv_priv;
0389 }
0390 
0391 /**
0392  * struct hw_mode_spec: Hardware specifications structure
0393  *
0394  * Details about the supported modes, rates and channels
0395  * of a particular chipset. This is used by rt2x00lib
0396  * to build the ieee80211_hw_mode array for mac80211.
0397  *
0398  * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
0399  * @supported_rates: Rate types which are supported (CCK, OFDM).
0400  * @num_channels: Number of supported channels. This is used as array size
0401  *  for @tx_power_a, @tx_power_bg and @channels.
0402  * @channels: Device/chipset specific channel values (See &struct rf_channel).
0403  * @channels_info: Additional information for channels (See &struct channel_info).
0404  * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
0405  */
0406 struct hw_mode_spec {
0407     unsigned int supported_bands;
0408 #define SUPPORT_BAND_2GHZ   0x00000001
0409 #define SUPPORT_BAND_5GHZ   0x00000002
0410 
0411     unsigned int supported_rates;
0412 #define SUPPORT_RATE_CCK    0x00000001
0413 #define SUPPORT_RATE_OFDM   0x00000002
0414 
0415     unsigned int num_channels;
0416     const struct rf_channel *channels;
0417     const struct channel_info *channels_info;
0418 
0419     struct ieee80211_sta_ht_cap ht;
0420 };
0421 
0422 /*
0423  * Configuration structure wrapper around the
0424  * mac80211 configuration structure.
0425  * When mac80211 configures the driver, rt2x00lib
0426  * can precalculate values which are equal for all
0427  * rt2x00 drivers. Those values can be stored in here.
0428  */
0429 struct rt2x00lib_conf {
0430     struct ieee80211_conf *conf;
0431 
0432     struct rf_channel rf;
0433     struct channel_info channel;
0434 };
0435 
0436 /*
0437  * Configuration structure for erp settings.
0438  */
0439 struct rt2x00lib_erp {
0440     int short_preamble;
0441     int cts_protection;
0442 
0443     u32 basic_rates;
0444 
0445     int slot_time;
0446 
0447     short sifs;
0448     short pifs;
0449     short difs;
0450     short eifs;
0451 
0452     u16 beacon_int;
0453     u16 ht_opmode;
0454 };
0455 
0456 /*
0457  * Configuration structure for hardware encryption.
0458  */
0459 struct rt2x00lib_crypto {
0460     enum cipher cipher;
0461 
0462     enum set_key_cmd cmd;
0463     const u8 *address;
0464 
0465     u32 bssidx;
0466 
0467     u8 key[16];
0468     u8 tx_mic[8];
0469     u8 rx_mic[8];
0470 
0471     int wcid;
0472 };
0473 
0474 /*
0475  * Configuration structure wrapper around the
0476  * rt2x00 interface configuration handler.
0477  */
0478 struct rt2x00intf_conf {
0479     /*
0480      * Interface type
0481      */
0482     enum nl80211_iftype type;
0483 
0484     /*
0485      * TSF sync value, this is dependent on the operation type.
0486      */
0487     enum tsf_sync sync;
0488 
0489     /*
0490      * The MAC and BSSID addresses are simple array of bytes,
0491      * these arrays are little endian, so when sending the addresses
0492      * to the drivers, copy the it into a endian-signed variable.
0493      *
0494      * Note that all devices (except rt2500usb) have 32 bits
0495      * register word sizes. This means that whatever variable we
0496      * pass _must_ be a multiple of 32 bits. Otherwise the device
0497      * might not accept what we are sending to it.
0498      * This will also make it easier for the driver to write
0499      * the data to the device.
0500      */
0501     __le32 mac[2];
0502     __le32 bssid[2];
0503 };
0504 
0505 /*
0506  * Private structure for storing STA details
0507  * wcid: Wireless Client ID
0508  */
0509 struct rt2x00_sta {
0510     int wcid;
0511 };
0512 
0513 static inline struct rt2x00_sta* sta_to_rt2x00_sta(struct ieee80211_sta *sta)
0514 {
0515     return (struct rt2x00_sta *)sta->drv_priv;
0516 }
0517 
0518 /*
0519  * rt2x00lib callback functions.
0520  */
0521 struct rt2x00lib_ops {
0522     /*
0523      * Interrupt handlers.
0524      */
0525     irq_handler_t irq_handler;
0526 
0527     /*
0528      * TX status tasklet handler.
0529      */
0530     void (*txstatus_tasklet) (struct tasklet_struct *t);
0531     void (*pretbtt_tasklet) (struct tasklet_struct *t);
0532     void (*tbtt_tasklet) (struct tasklet_struct *t);
0533     void (*rxdone_tasklet) (struct tasklet_struct *t);
0534     void (*autowake_tasklet) (struct tasklet_struct *t);
0535 
0536     /*
0537      * Device init handlers.
0538      */
0539     int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
0540     char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
0541     int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
0542                    const u8 *data, const size_t len);
0543     int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
0544                   const u8 *data, const size_t len);
0545 
0546     /*
0547      * Device initialization/deinitialization handlers.
0548      */
0549     int (*initialize) (struct rt2x00_dev *rt2x00dev);
0550     void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
0551 
0552     /*
0553      * queue initialization handlers
0554      */
0555     bool (*get_entry_state) (struct queue_entry *entry);
0556     void (*clear_entry) (struct queue_entry *entry);
0557 
0558     /*
0559      * Radio control handlers.
0560      */
0561     int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
0562                  enum dev_state state);
0563     int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
0564     void (*link_stats) (struct rt2x00_dev *rt2x00dev,
0565                 struct link_qual *qual);
0566     void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
0567                  struct link_qual *qual);
0568     void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
0569                 struct link_qual *qual, const u32 count);
0570     void (*gain_calibration) (struct rt2x00_dev *rt2x00dev);
0571     void (*vco_calibration) (struct rt2x00_dev *rt2x00dev);
0572 
0573     /*
0574      * Data queue handlers.
0575      */
0576     void (*watchdog) (struct rt2x00_dev *rt2x00dev);
0577     void (*start_queue) (struct data_queue *queue);
0578     void (*kick_queue) (struct data_queue *queue);
0579     void (*stop_queue) (struct data_queue *queue);
0580     void (*flush_queue) (struct data_queue *queue, bool drop);
0581     void (*tx_dma_done) (struct queue_entry *entry);
0582 
0583     /*
0584      * TX control handlers
0585      */
0586     void (*write_tx_desc) (struct queue_entry *entry,
0587                    struct txentry_desc *txdesc);
0588     void (*write_tx_data) (struct queue_entry *entry,
0589                    struct txentry_desc *txdesc);
0590     void (*write_beacon) (struct queue_entry *entry,
0591                   struct txentry_desc *txdesc);
0592     void (*clear_beacon) (struct queue_entry *entry);
0593     int (*get_tx_data_len) (struct queue_entry *entry);
0594 
0595     /*
0596      * RX control handlers
0597      */
0598     void (*fill_rxdone) (struct queue_entry *entry,
0599                  struct rxdone_entry_desc *rxdesc);
0600 
0601     /*
0602      * Configuration handlers.
0603      */
0604     int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
0605                   struct rt2x00lib_crypto *crypto,
0606                   struct ieee80211_key_conf *key);
0607     int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
0608                     struct rt2x00lib_crypto *crypto,
0609                     struct ieee80211_key_conf *key);
0610     void (*config_filter) (struct rt2x00_dev *rt2x00dev,
0611                    const unsigned int filter_flags);
0612     void (*config_intf) (struct rt2x00_dev *rt2x00dev,
0613                  struct rt2x00_intf *intf,
0614                  struct rt2x00intf_conf *conf,
0615                  const unsigned int flags);
0616 #define CONFIG_UPDATE_TYPE      ( 1 << 1 )
0617 #define CONFIG_UPDATE_MAC       ( 1 << 2 )
0618 #define CONFIG_UPDATE_BSSID     ( 1 << 3 )
0619 
0620     void (*config_erp) (struct rt2x00_dev *rt2x00dev,
0621                 struct rt2x00lib_erp *erp,
0622                 u32 changed);
0623     void (*config_ant) (struct rt2x00_dev *rt2x00dev,
0624                 struct antenna_setup *ant);
0625     void (*config) (struct rt2x00_dev *rt2x00dev,
0626             struct rt2x00lib_conf *libconf,
0627             const unsigned int changed_flags);
0628     void (*pre_reset_hw) (struct rt2x00_dev *rt2x00dev);
0629     int (*sta_add) (struct rt2x00_dev *rt2x00dev,
0630             struct ieee80211_vif *vif,
0631             struct ieee80211_sta *sta);
0632     int (*sta_remove) (struct rt2x00_dev *rt2x00dev,
0633                struct ieee80211_sta *sta);
0634 };
0635 
0636 /*
0637  * rt2x00 driver callback operation structure.
0638  */
0639 struct rt2x00_ops {
0640     const char *name;
0641     const unsigned int drv_data_size;
0642     const unsigned int max_ap_intf;
0643     const unsigned int eeprom_size;
0644     const unsigned int rf_size;
0645     const unsigned int tx_queues;
0646     void (*queue_init)(struct data_queue *queue);
0647     const struct rt2x00lib_ops *lib;
0648     const void *drv;
0649     const struct ieee80211_ops *hw;
0650 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
0651     const struct rt2x00debug *debugfs;
0652 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
0653 };
0654 
0655 /*
0656  * rt2x00 state flags
0657  */
0658 enum rt2x00_state_flags {
0659     /*
0660      * Device flags
0661      */
0662     DEVICE_STATE_PRESENT,
0663     DEVICE_STATE_REGISTERED_HW,
0664     DEVICE_STATE_INITIALIZED,
0665     DEVICE_STATE_STARTED,
0666     DEVICE_STATE_ENABLED_RADIO,
0667     DEVICE_STATE_SCANNING,
0668     DEVICE_STATE_FLUSHING,
0669     DEVICE_STATE_RESET,
0670 
0671     /*
0672      * Driver configuration
0673      */
0674     CONFIG_CHANNEL_HT40,
0675     CONFIG_POWERSAVING,
0676     CONFIG_HT_DISABLED,
0677     CONFIG_MONITORING,
0678 
0679     /*
0680      * Mark we currently are sequentially reading TX_STA_FIFO register
0681      * FIXME: this is for only rt2800usb, should go to private data
0682      */
0683     TX_STATUS_READING,
0684 };
0685 
0686 /*
0687  * rt2x00 capability flags
0688  */
0689 enum rt2x00_capability_flags {
0690     /*
0691      * Requirements
0692      */
0693     REQUIRE_FIRMWARE,
0694     REQUIRE_BEACON_GUARD,
0695     REQUIRE_ATIM_QUEUE,
0696     REQUIRE_DMA,
0697     REQUIRE_COPY_IV,
0698     REQUIRE_L2PAD,
0699     REQUIRE_TXSTATUS_FIFO,
0700     REQUIRE_TASKLET_CONTEXT,
0701     REQUIRE_SW_SEQNO,
0702     REQUIRE_HT_TX_DESC,
0703     REQUIRE_PS_AUTOWAKE,
0704     REQUIRE_DELAYED_RFKILL,
0705 
0706     /*
0707      * Capabilities
0708      */
0709     CAPABILITY_HW_BUTTON,
0710     CAPABILITY_HW_CRYPTO,
0711     CAPABILITY_POWER_LIMIT,
0712     CAPABILITY_CONTROL_FILTERS,
0713     CAPABILITY_CONTROL_FILTER_PSPOLL,
0714     CAPABILITY_PRE_TBTT_INTERRUPT,
0715     CAPABILITY_LINK_TUNING,
0716     CAPABILITY_FRAME_TYPE,
0717     CAPABILITY_RF_SEQUENCE,
0718     CAPABILITY_EXTERNAL_LNA_A,
0719     CAPABILITY_EXTERNAL_LNA_BG,
0720     CAPABILITY_DOUBLE_ANTENNA,
0721     CAPABILITY_BT_COEXIST,
0722     CAPABILITY_VCO_RECALIBRATION,
0723     CAPABILITY_EXTERNAL_PA_TX0,
0724     CAPABILITY_EXTERNAL_PA_TX1,
0725     CAPABILITY_RESTART_HW,
0726 };
0727 
0728 /*
0729  * Interface combinations
0730  */
0731 enum {
0732     IF_COMB_AP = 0,
0733     NUM_IF_COMB,
0734 };
0735 
0736 /*
0737  * rt2x00 device structure.
0738  */
0739 struct rt2x00_dev {
0740     /*
0741      * Device structure.
0742      * The structure stored in here depends on the
0743      * system bus (PCI or USB).
0744      * When accessing this variable, the rt2x00dev_{pci,usb}
0745      * macros should be used for correct typecasting.
0746      */
0747     struct device *dev;
0748 
0749     /*
0750      * Callback functions.
0751      */
0752     const struct rt2x00_ops *ops;
0753 
0754     /*
0755      * Driver data.
0756      */
0757     void *drv_data;
0758 
0759     /*
0760      * IEEE80211 control structure.
0761      */
0762     struct ieee80211_hw *hw;
0763     struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
0764     struct rt2x00_chan_survey *chan_survey;
0765     enum nl80211_band curr_band;
0766     int curr_freq;
0767 
0768     /*
0769      * If enabled, the debugfs interface structures
0770      * required for deregistration of debugfs.
0771      */
0772 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
0773     struct rt2x00debug_intf *debugfs_intf;
0774 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
0775 
0776     /*
0777      * LED structure for changing the LED status
0778      * by mac8011 or the kernel.
0779      */
0780 #ifdef CONFIG_RT2X00_LIB_LEDS
0781     struct rt2x00_led led_radio;
0782     struct rt2x00_led led_assoc;
0783     struct rt2x00_led led_qual;
0784     u16 led_mcu_reg;
0785 #endif /* CONFIG_RT2X00_LIB_LEDS */
0786 
0787     /*
0788      * Device state flags.
0789      * In these flags the current status is stored.
0790      * Access to these flags should occur atomically.
0791      */
0792     unsigned long flags;
0793 
0794     /*
0795      * Device capabiltiy flags.
0796      * In these flags the device/driver capabilities are stored.
0797      * Access to these flags should occur non-atomically.
0798      */
0799     unsigned long cap_flags;
0800 
0801     /*
0802      * Device information, Bus IRQ and name (PCI, SoC)
0803      */
0804     int irq;
0805     const char *name;
0806 
0807     /*
0808      * Chipset identification.
0809      */
0810     struct rt2x00_chip chip;
0811 
0812     /*
0813      * hw capability specifications.
0814      */
0815     struct hw_mode_spec spec;
0816 
0817     /*
0818      * This is the default TX/RX antenna setup as indicated
0819      * by the device's EEPROM.
0820      */
0821     struct antenna_setup default_ant;
0822 
0823     /*
0824      * Register pointers
0825      * csr.base: CSR base register address. (PCI)
0826      * csr.cache: CSR cache for usb_control_msg. (USB)
0827      */
0828     union csr {
0829         void __iomem *base;
0830         void *cache;
0831     } csr;
0832 
0833     /*
0834      * Mutex to protect register accesses.
0835      * For PCI and USB devices it protects against concurrent indirect
0836      * register access (BBP, RF, MCU) since accessing those
0837      * registers require multiple calls to the CSR registers.
0838      * For USB devices it also protects the csr_cache since that
0839      * field is used for normal CSR access and it cannot support
0840      * multiple callers simultaneously.
0841      */
0842     struct mutex csr_mutex;
0843 
0844     /*
0845      * Mutex to synchronize config and link tuner.
0846      */
0847     struct mutex conf_mutex;
0848     /*
0849      * Current packet filter configuration for the device.
0850      * This contains all currently active FIF_* flags send
0851      * to us by mac80211 during configure_filter().
0852      */
0853     unsigned int packet_filter;
0854 
0855     /*
0856      * Interface details:
0857      *  - Open ap interface count.
0858      *  - Open sta interface count.
0859      *  - Association count.
0860      *  - Beaconing enabled count.
0861      */
0862     unsigned int intf_ap_count;
0863     unsigned int intf_sta_count;
0864     unsigned int intf_associated;
0865     unsigned int intf_beaconing;
0866 
0867     /*
0868      * Interface combinations
0869      */
0870     struct ieee80211_iface_limit if_limits_ap;
0871     struct ieee80211_iface_combination if_combinations[NUM_IF_COMB];
0872 
0873     /*
0874      * Link quality
0875      */
0876     struct link link;
0877 
0878     /*
0879      * EEPROM data.
0880      */
0881     __le16 *eeprom;
0882 
0883     /*
0884      * Active RF register values.
0885      * These are stored here so we don't need
0886      * to read the rf registers and can directly
0887      * use this value instead.
0888      * This field should be accessed by using
0889      * rt2x00_rf_read() and rt2x00_rf_write().
0890      */
0891     u32 *rf;
0892 
0893     /*
0894      * LNA gain
0895      */
0896     short lna_gain;
0897 
0898     /*
0899      * Current TX power value.
0900      */
0901     u16 tx_power;
0902 
0903     /*
0904      * Current retry values.
0905      */
0906     u8 short_retry;
0907     u8 long_retry;
0908 
0909     /*
0910      * Rssi <-> Dbm offset
0911      */
0912     u8 rssi_offset;
0913 
0914     /*
0915      * Frequency offset.
0916      */
0917     u8 freq_offset;
0918 
0919     /*
0920      * Association id.
0921      */
0922     u16 aid;
0923 
0924     /*
0925      * Beacon interval.
0926      */
0927     u16 beacon_int;
0928 
0929     /**
0930      * Timestamp of last received beacon
0931      */
0932     unsigned long last_beacon;
0933 
0934     /*
0935      * Low level statistics which will have
0936      * to be kept up to date while device is running.
0937      */
0938     struct ieee80211_low_level_stats low_level_stats;
0939 
0940     /**
0941      * Work queue for all work which should not be placed
0942      * on the mac80211 workqueue (because of dependencies
0943      * between various work structures).
0944      */
0945     struct workqueue_struct *workqueue;
0946 
0947     /*
0948      * Scheduled work.
0949      * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
0950      * which means it cannot be placed on the hw->workqueue
0951      * due to RTNL locking requirements.
0952      */
0953     struct work_struct intf_work;
0954 
0955     /**
0956      * Scheduled work for TX/RX done handling (USB devices)
0957      */
0958     struct work_struct rxdone_work;
0959     struct work_struct txdone_work;
0960 
0961     /*
0962      * Powersaving work
0963      */
0964     struct delayed_work autowakeup_work;
0965     struct work_struct sleep_work;
0966 
0967     /*
0968      * Data queue arrays for RX, TX, Beacon and ATIM.
0969      */
0970     unsigned int data_queues;
0971     struct data_queue *rx;
0972     struct data_queue *tx;
0973     struct data_queue *bcn;
0974     struct data_queue *atim;
0975 
0976     /*
0977      * Firmware image.
0978      */
0979     const struct firmware *fw;
0980 
0981     /*
0982      * FIFO for storing tx status reports between isr and tasklet.
0983      */
0984     DECLARE_KFIFO_PTR(txstatus_fifo, u32);
0985 
0986     /*
0987      * Timer to ensure tx status reports are read (rt2800usb).
0988      */
0989     struct hrtimer txstatus_timer;
0990 
0991     /*
0992      * Tasklet for processing tx status reports (rt2800pci).
0993      */
0994     struct tasklet_struct txstatus_tasklet;
0995     struct tasklet_struct pretbtt_tasklet;
0996     struct tasklet_struct tbtt_tasklet;
0997     struct tasklet_struct rxdone_tasklet;
0998     struct tasklet_struct autowake_tasklet;
0999 
1000     /*
1001      * Used for VCO periodic calibration.
1002      */
1003     int rf_channel;
1004 
1005     /*
1006      * Protect the interrupt mask register.
1007      */
1008     spinlock_t irqmask_lock;
1009 
1010     /*
1011      * List of BlockAckReq TX entries that need driver BlockAck processing.
1012      */
1013     struct list_head bar_list;
1014     spinlock_t bar_list_lock;
1015 
1016     /* Extra TX headroom required for alignment purposes. */
1017     unsigned int extra_tx_headroom;
1018 
1019     struct usb_anchor *anchor;
1020     unsigned int num_proto_errs;
1021 
1022     /* Clock for System On Chip devices. */
1023     struct clk *clk;
1024 };
1025 
1026 struct rt2x00_bar_list_entry {
1027     struct list_head list;
1028     struct rcu_head head;
1029 
1030     struct queue_entry *entry;
1031     int block_acked;
1032 
1033     /* Relevant parts of the IEEE80211 BAR header */
1034     __u8 ra[6];
1035     __u8 ta[6];
1036     __le16 control;
1037     __le16 start_seq_num;
1038 };
1039 
1040 /*
1041  * Register defines.
1042  * Some registers require multiple attempts before success,
1043  * in those cases REGISTER_BUSY_COUNT attempts should be
1044  * taken with a REGISTER_BUSY_DELAY interval. Due to USB
1045  * bus delays, we do not have to loop so many times to wait
1046  * for valid register value on that bus.
1047  */
1048 #define REGISTER_BUSY_COUNT 100
1049 #define REGISTER_USB_BUSY_COUNT 20
1050 #define REGISTER_BUSY_DELAY 100
1051 
1052 /*
1053  * Generic RF access.
1054  * The RF is being accessed by word index.
1055  */
1056 static inline u32 rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
1057                  const unsigned int word)
1058 {
1059     BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
1060     return rt2x00dev->rf[word - 1];
1061 }
1062 
1063 static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
1064                    const unsigned int word, u32 data)
1065 {
1066     BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
1067     rt2x00dev->rf[word - 1] = data;
1068 }
1069 
1070 /*
1071  * Generic EEPROM access. The EEPROM is being accessed by word or byte index.
1072  */
1073 static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
1074                        const unsigned int word)
1075 {
1076     return (void *)&rt2x00dev->eeprom[word];
1077 }
1078 
1079 static inline u16 rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
1080                      const unsigned int word)
1081 {
1082     return le16_to_cpu(rt2x00dev->eeprom[word]);
1083 }
1084 
1085 static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
1086                        const unsigned int word, u16 data)
1087 {
1088     rt2x00dev->eeprom[word] = cpu_to_le16(data);
1089 }
1090 
1091 static inline u8 rt2x00_eeprom_byte(struct rt2x00_dev *rt2x00dev,
1092                     const unsigned int byte)
1093 {
1094     return *(((u8 *)rt2x00dev->eeprom) + byte);
1095 }
1096 
1097 /*
1098  * Chipset handlers
1099  */
1100 static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
1101                    const u16 rt, const u16 rf, const u16 rev)
1102 {
1103     rt2x00dev->chip.rt = rt;
1104     rt2x00dev->chip.rf = rf;
1105     rt2x00dev->chip.rev = rev;
1106 
1107     rt2x00_info(rt2x00dev, "Chipset detected - rt: %04x, rf: %04x, rev: %04x\n",
1108             rt2x00dev->chip.rt, rt2x00dev->chip.rf,
1109             rt2x00dev->chip.rev);
1110 }
1111 
1112 static inline void rt2x00_set_rt(struct rt2x00_dev *rt2x00dev,
1113                  const u16 rt, const u16 rev)
1114 {
1115     rt2x00dev->chip.rt = rt;
1116     rt2x00dev->chip.rev = rev;
1117 
1118     rt2x00_info(rt2x00dev, "RT chipset %04x, rev %04x detected\n",
1119             rt2x00dev->chip.rt, rt2x00dev->chip.rev);
1120 }
1121 
1122 static inline void rt2x00_set_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
1123 {
1124     rt2x00dev->chip.rf = rf;
1125 
1126     rt2x00_info(rt2x00dev, "RF chipset %04x detected\n",
1127             rt2x00dev->chip.rf);
1128 }
1129 
1130 static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
1131 {
1132     return (rt2x00dev->chip.rt == rt);
1133 }
1134 
1135 static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
1136 {
1137     return (rt2x00dev->chip.rf == rf);
1138 }
1139 
1140 static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
1141 {
1142     return rt2x00dev->chip.rev;
1143 }
1144 
1145 static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
1146                  const u16 rt, const u16 rev)
1147 {
1148     return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
1149 }
1150 
1151 static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
1152                     const u16 rt, const u16 rev)
1153 {
1154     return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
1155 }
1156 
1157 static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
1158                      const u16 rt, const u16 rev)
1159 {
1160     return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
1161 }
1162 
1163 static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
1164                     enum rt2x00_chip_intf intf)
1165 {
1166     rt2x00dev->chip.intf = intf;
1167 }
1168 
1169 static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
1170                    enum rt2x00_chip_intf intf)
1171 {
1172     return (rt2x00dev->chip.intf == intf);
1173 }
1174 
1175 static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
1176 {
1177     return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
1178            rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
1179 }
1180 
1181 static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
1182 {
1183     return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
1184 }
1185 
1186 static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
1187 {
1188     return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
1189 }
1190 
1191 static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
1192 {
1193     return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
1194 }
1195 
1196 /* Helpers for capability flags */
1197 
1198 static inline bool
1199 rt2x00_has_cap_flag(struct rt2x00_dev *rt2x00dev,
1200             enum rt2x00_capability_flags cap_flag)
1201 {
1202     return test_bit(cap_flag, &rt2x00dev->cap_flags);
1203 }
1204 
1205 static inline bool
1206 rt2x00_has_cap_hw_crypto(struct rt2x00_dev *rt2x00dev)
1207 {
1208     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_HW_CRYPTO);
1209 }
1210 
1211 static inline bool
1212 rt2x00_has_cap_power_limit(struct rt2x00_dev *rt2x00dev)
1213 {
1214     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_POWER_LIMIT);
1215 }
1216 
1217 static inline bool
1218 rt2x00_has_cap_control_filters(struct rt2x00_dev *rt2x00dev)
1219 {
1220     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_CONTROL_FILTERS);
1221 }
1222 
1223 static inline bool
1224 rt2x00_has_cap_control_filter_pspoll(struct rt2x00_dev *rt2x00dev)
1225 {
1226     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_CONTROL_FILTER_PSPOLL);
1227 }
1228 
1229 static inline bool
1230 rt2x00_has_cap_pre_tbtt_interrupt(struct rt2x00_dev *rt2x00dev)
1231 {
1232     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_PRE_TBTT_INTERRUPT);
1233 }
1234 
1235 static inline bool
1236 rt2x00_has_cap_link_tuning(struct rt2x00_dev *rt2x00dev)
1237 {
1238     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_LINK_TUNING);
1239 }
1240 
1241 static inline bool
1242 rt2x00_has_cap_frame_type(struct rt2x00_dev *rt2x00dev)
1243 {
1244     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_FRAME_TYPE);
1245 }
1246 
1247 static inline bool
1248 rt2x00_has_cap_rf_sequence(struct rt2x00_dev *rt2x00dev)
1249 {
1250     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_RF_SEQUENCE);
1251 }
1252 
1253 static inline bool
1254 rt2x00_has_cap_external_lna_a(struct rt2x00_dev *rt2x00dev)
1255 {
1256     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_EXTERNAL_LNA_A);
1257 }
1258 
1259 static inline bool
1260 rt2x00_has_cap_external_lna_bg(struct rt2x00_dev *rt2x00dev)
1261 {
1262     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_EXTERNAL_LNA_BG);
1263 }
1264 
1265 static inline bool
1266 rt2x00_has_cap_double_antenna(struct rt2x00_dev *rt2x00dev)
1267 {
1268     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_DOUBLE_ANTENNA);
1269 }
1270 
1271 static inline bool
1272 rt2x00_has_cap_bt_coexist(struct rt2x00_dev *rt2x00dev)
1273 {
1274     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_BT_COEXIST);
1275 }
1276 
1277 static inline bool
1278 rt2x00_has_cap_vco_recalibration(struct rt2x00_dev *rt2x00dev)
1279 {
1280     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_VCO_RECALIBRATION);
1281 }
1282 
1283 static inline bool
1284 rt2x00_has_cap_restart_hw(struct rt2x00_dev *rt2x00dev)
1285 {
1286     return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_RESTART_HW);
1287 }
1288 
1289 /**
1290  * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
1291  * @entry: Pointer to &struct queue_entry
1292  *
1293  * Returns -ENOMEM if mapping fail, 0 otherwise.
1294  */
1295 int rt2x00queue_map_txskb(struct queue_entry *entry);
1296 
1297 /**
1298  * rt2x00queue_unmap_skb - Unmap a skb from DMA.
1299  * @entry: Pointer to &struct queue_entry
1300  */
1301 void rt2x00queue_unmap_skb(struct queue_entry *entry);
1302 
1303 /**
1304  * rt2x00queue_get_tx_queue - Convert tx queue index to queue pointer
1305  * @rt2x00dev: Pointer to &struct rt2x00_dev.
1306  * @queue: rt2x00 queue index (see &enum data_queue_qid).
1307  *
1308  * Returns NULL for non tx queues.
1309  */
1310 static inline struct data_queue *
1311 rt2x00queue_get_tx_queue(struct rt2x00_dev *rt2x00dev,
1312              const enum data_queue_qid queue)
1313 {
1314     if (queue < rt2x00dev->ops->tx_queues && rt2x00dev->tx)
1315         return &rt2x00dev->tx[queue];
1316 
1317     if (queue == QID_ATIM)
1318         return rt2x00dev->atim;
1319 
1320     return NULL;
1321 }
1322 
1323 /**
1324  * rt2x00queue_get_entry - Get queue entry where the given index points to.
1325  * @queue: Pointer to &struct data_queue from where we obtain the entry.
1326  * @index: Index identifier for obtaining the correct index.
1327  */
1328 struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
1329                       enum queue_index index);
1330 
1331 /**
1332  * rt2x00queue_pause_queue - Pause a data queue
1333  * @queue: Pointer to &struct data_queue.
1334  *
1335  * This function will pause the data queue locally, preventing
1336  * new frames to be added to the queue (while the hardware is
1337  * still allowed to run).
1338  */
1339 void rt2x00queue_pause_queue(struct data_queue *queue);
1340 
1341 /**
1342  * rt2x00queue_unpause_queue - unpause a data queue
1343  * @queue: Pointer to &struct data_queue.
1344  *
1345  * This function will unpause the data queue locally, allowing
1346  * new frames to be added to the queue again.
1347  */
1348 void rt2x00queue_unpause_queue(struct data_queue *queue);
1349 
1350 /**
1351  * rt2x00queue_start_queue - Start a data queue
1352  * @queue: Pointer to &struct data_queue.
1353  *
1354  * This function will start handling all pending frames in the queue.
1355  */
1356 void rt2x00queue_start_queue(struct data_queue *queue);
1357 
1358 /**
1359  * rt2x00queue_stop_queue - Halt a data queue
1360  * @queue: Pointer to &struct data_queue.
1361  *
1362  * This function will stop all pending frames in the queue.
1363  */
1364 void rt2x00queue_stop_queue(struct data_queue *queue);
1365 
1366 /**
1367  * rt2x00queue_flush_queue - Flush a data queue
1368  * @queue: Pointer to &struct data_queue.
1369  * @drop: True to drop all pending frames.
1370  *
1371  * This function will flush the queue. After this call
1372  * the queue is guaranteed to be empty.
1373  */
1374 void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
1375 
1376 /**
1377  * rt2x00queue_start_queues - Start all data queues
1378  * @rt2x00dev: Pointer to &struct rt2x00_dev.
1379  *
1380  * This function will loop through all available queues to start them
1381  */
1382 void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
1383 
1384 /**
1385  * rt2x00queue_stop_queues - Halt all data queues
1386  * @rt2x00dev: Pointer to &struct rt2x00_dev.
1387  *
1388  * This function will loop through all available queues to stop
1389  * any pending frames.
1390  */
1391 void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
1392 
1393 /**
1394  * rt2x00queue_flush_queues - Flush all data queues
1395  * @rt2x00dev: Pointer to &struct rt2x00_dev.
1396  * @drop: True to drop all pending frames.
1397  *
1398  * This function will loop through all available queues to flush
1399  * any pending frames.
1400  */
1401 void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
1402 
1403 /*
1404  * Debugfs handlers.
1405  */
1406 /**
1407  * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
1408  * @rt2x00dev: Pointer to &struct rt2x00_dev.
1409  * @type: The type of frame that is being dumped.
1410  * @entry: The queue entry containing the frame to be dumped.
1411  */
1412 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1413 void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
1414                 enum rt2x00_dump_type type, struct queue_entry *entry);
1415 #else
1416 static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
1417                       enum rt2x00_dump_type type,
1418                       struct queue_entry *entry)
1419 {
1420 }
1421 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1422 
1423 /*
1424  * Utility functions.
1425  */
1426 u32 rt2x00lib_get_bssidx(struct rt2x00_dev *rt2x00dev,
1427              struct ieee80211_vif *vif);
1428 void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr);
1429 
1430 /*
1431  * Interrupt context handlers.
1432  */
1433 void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
1434 void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
1435 void rt2x00lib_dmastart(struct queue_entry *entry);
1436 void rt2x00lib_dmadone(struct queue_entry *entry);
1437 void rt2x00lib_txdone(struct queue_entry *entry,
1438               struct txdone_entry_desc *txdesc);
1439 void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
1440                   struct txdone_entry_desc *txdesc);
1441 void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
1442 void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp);
1443 
1444 /*
1445  * mac80211 handlers.
1446  */
1447 void rt2x00mac_tx(struct ieee80211_hw *hw,
1448           struct ieee80211_tx_control *control,
1449           struct sk_buff *skb);
1450 int rt2x00mac_start(struct ieee80211_hw *hw);
1451 void rt2x00mac_stop(struct ieee80211_hw *hw);
1452 void rt2x00mac_reconfig_complete(struct ieee80211_hw *hw,
1453                  enum ieee80211_reconfig_type reconfig_type);
1454 int rt2x00mac_add_interface(struct ieee80211_hw *hw,
1455                 struct ieee80211_vif *vif);
1456 void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
1457                 struct ieee80211_vif *vif);
1458 int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
1459 void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
1460                 unsigned int changed_flags,
1461                 unsigned int *total_flags,
1462                 u64 multicast);
1463 int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
1464               bool set);
1465 #ifdef CONFIG_RT2X00_LIB_CRYPTO
1466 int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1467               struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1468               struct ieee80211_key_conf *key);
1469 #else
1470 #define rt2x00mac_set_key   NULL
1471 #endif /* CONFIG_RT2X00_LIB_CRYPTO */
1472 void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw,
1473                  struct ieee80211_vif *vif,
1474                  const u8 *mac_addr);
1475 void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw,
1476                 struct ieee80211_vif *vif);
1477 int rt2x00mac_get_stats(struct ieee80211_hw *hw,
1478             struct ieee80211_low_level_stats *stats);
1479 void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
1480                 struct ieee80211_vif *vif,
1481                 struct ieee80211_bss_conf *bss_conf,
1482                 u64 changes);
1483 int rt2x00mac_conf_tx(struct ieee80211_hw *hw,
1484               struct ieee80211_vif *vif,
1485               unsigned int link_id, u16 queue,
1486               const struct ieee80211_tx_queue_params *params);
1487 void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
1488 void rt2x00mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1489              u32 queues, bool drop);
1490 int rt2x00mac_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant);
1491 int rt2x00mac_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
1492 void rt2x00mac_get_ringparam(struct ieee80211_hw *hw,
1493                  u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max);
1494 bool rt2x00mac_tx_frames_pending(struct ieee80211_hw *hw);
1495 
1496 /*
1497  * Driver allocation handlers.
1498  */
1499 int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
1500 void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
1501 
1502 int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev);
1503 int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
1504 
1505 #endif /* RT2X00_H */