0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0042
0043 #define DRV_VERSION "2.3.0"
0044 #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
0045
0046
0047
0048
0049 #ifdef CONFIG_RT2X00_DEBUG
0050 #define DEBUG
0051 #endif
0052
0053
0054
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
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
0079
0080
0081
0082
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
0089
0090
0091 #define L2PAD_SIZE(__hdrlen) (-(__hdrlen) & 3)
0092
0093
0094
0095
0096
0097
0098
0099 #define ALIGN_SIZE(__skb, __header) \
0100 (((unsigned long)((__skb)->data + (__header))) & 3)
0101
0102
0103
0104
0105 #define RT2X00_ALIGN_SIZE 4
0106 #define RT2X00_L2PAD_SIZE 8
0107
0108
0109
0110
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
0139
0140
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
0150 #define RT2872 0x2872
0151 #define RT2883 0x2883
0152 #define RT3070 0x3070
0153 #define RT3071 0x3071
0154 #define RT3090 0x3090
0155 #define RT3290 0x3290
0156 #define RT3352 0x3352
0157 #define RT3390 0x3390
0158 #define RT3572 0x3572
0159 #define RT3593 0x3593
0160 #define RT3883 0x3883
0161 #define RT5350 0x5350
0162 #define RT5390 0x5390
0163 #define RT5392 0x5392
0164 #define RT5592 0x5592
0165 #define RT6352 0x6352
0166
0167 u16 rf;
0168 u16 rev;
0169
0170 enum rt2x00_chip_intf intf;
0171 };
0172
0173
0174
0175
0176 struct rf_channel {
0177 int channel;
0178 u32 rf1;
0179 u32 rf2;
0180 u32 rf3;
0181 u32 rf4;
0182 };
0183
0184
0185
0186
0187 struct rt2x00_chan_survey {
0188 u64 time_idle;
0189 u64 time_busy;
0190 u64 time_ext_busy;
0191 };
0192
0193
0194
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
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
0218
0219 struct link_qual {
0220
0221
0222
0223
0224
0225
0226
0227
0228 int rssi;
0229 int false_cca;
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244 u8 vgc_level;
0245 u8 vgc_level_reg;
0246
0247
0248
0249
0250
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
0262
0263 struct link_ant {
0264
0265
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
0274
0275
0276
0277 struct antenna_setup active;
0278
0279
0280
0281
0282
0283
0284 int rssi_history;
0285
0286
0287
0288
0289
0290
0291 struct ewma_rssi rssi_ant;
0292 };
0293
0294
0295
0296
0297
0298
0299 struct link {
0300
0301
0302
0303
0304
0305 u32 count;
0306
0307
0308
0309
0310 struct link_qual qual;
0311
0312
0313
0314
0315 struct link_ant ant;
0316
0317
0318
0319
0320 struct ewma_rssi avg_rssi;
0321
0322
0323
0324
0325 struct delayed_work work;
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 struct delayed_work watchdog_work;
0336 unsigned int watchdog_interval;
0337 bool watchdog_disabled;
0338
0339
0340
0341
0342 struct delayed_work agc_work;
0343
0344
0345
0346
0347 struct delayed_work vco_work;
0348 };
0349
0350 enum rt2x00_delayed_flags {
0351 DELAYED_UPDATE_BEACON,
0352 };
0353
0354
0355
0356
0357
0358
0359 struct rt2x00_intf {
0360
0361
0362
0363 struct mutex beacon_skb_mutex;
0364
0365
0366
0367
0368
0369
0370 struct queue_entry *beacon;
0371 bool enable_beacon;
0372
0373
0374
0375
0376 unsigned long delayed_flags;
0377
0378
0379
0380
0381
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
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
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
0424
0425
0426
0427
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
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
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
0476
0477
0478 struct rt2x00intf_conf {
0479
0480
0481
0482 enum nl80211_iftype type;
0483
0484
0485
0486
0487 enum tsf_sync sync;
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501 __le32 mac[2];
0502 __le32 bssid[2];
0503 };
0504
0505
0506
0507
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
0520
0521 struct rt2x00lib_ops {
0522
0523
0524
0525 irq_handler_t irq_handler;
0526
0527
0528
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
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
0548
0549 int (*initialize) (struct rt2x00_dev *rt2x00dev);
0550 void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
0551
0552
0553
0554
0555 bool (*get_entry_state) (struct queue_entry *entry);
0556 void (*clear_entry) (struct queue_entry *entry);
0557
0558
0559
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
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
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
0597
0598 void (*fill_rxdone) (struct queue_entry *entry,
0599 struct rxdone_entry_desc *rxdesc);
0600
0601
0602
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
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
0653 };
0654
0655
0656
0657
0658 enum rt2x00_state_flags {
0659
0660
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
0673
0674 CONFIG_CHANNEL_HT40,
0675 CONFIG_POWERSAVING,
0676 CONFIG_HT_DISABLED,
0677 CONFIG_MONITORING,
0678
0679
0680
0681
0682
0683 TX_STATUS_READING,
0684 };
0685
0686
0687
0688
0689 enum rt2x00_capability_flags {
0690
0691
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
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
0730
0731 enum {
0732 IF_COMB_AP = 0,
0733 NUM_IF_COMB,
0734 };
0735
0736
0737
0738
0739 struct rt2x00_dev {
0740
0741
0742
0743
0744
0745
0746
0747 struct device *dev;
0748
0749
0750
0751
0752 const struct rt2x00_ops *ops;
0753
0754
0755
0756
0757 void *drv_data;
0758
0759
0760
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
0770
0771
0772 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
0773 struct rt2x00debug_intf *debugfs_intf;
0774 #endif
0775
0776
0777
0778
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
0786
0787
0788
0789
0790
0791
0792 unsigned long flags;
0793
0794
0795
0796
0797
0798
0799 unsigned long cap_flags;
0800
0801
0802
0803
0804 int irq;
0805 const char *name;
0806
0807
0808
0809
0810 struct rt2x00_chip chip;
0811
0812
0813
0814
0815 struct hw_mode_spec spec;
0816
0817
0818
0819
0820
0821 struct antenna_setup default_ant;
0822
0823
0824
0825
0826
0827
0828 union csr {
0829 void __iomem *base;
0830 void *cache;
0831 } csr;
0832
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842 struct mutex csr_mutex;
0843
0844
0845
0846
0847 struct mutex conf_mutex;
0848
0849
0850
0851
0852
0853 unsigned int packet_filter;
0854
0855
0856
0857
0858
0859
0860
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
0869
0870 struct ieee80211_iface_limit if_limits_ap;
0871 struct ieee80211_iface_combination if_combinations[NUM_IF_COMB];
0872
0873
0874
0875
0876 struct link link;
0877
0878
0879
0880
0881 __le16 *eeprom;
0882
0883
0884
0885
0886
0887
0888
0889
0890
0891 u32 *rf;
0892
0893
0894
0895
0896 short lna_gain;
0897
0898
0899
0900
0901 u16 tx_power;
0902
0903
0904
0905
0906 u8 short_retry;
0907 u8 long_retry;
0908
0909
0910
0911
0912 u8 rssi_offset;
0913
0914
0915
0916
0917 u8 freq_offset;
0918
0919
0920
0921
0922 u16 aid;
0923
0924
0925
0926
0927 u16 beacon_int;
0928
0929
0930
0931
0932 unsigned long last_beacon;
0933
0934
0935
0936
0937
0938 struct ieee80211_low_level_stats low_level_stats;
0939
0940
0941
0942
0943
0944
0945 struct workqueue_struct *workqueue;
0946
0947
0948
0949
0950
0951
0952
0953 struct work_struct intf_work;
0954
0955
0956
0957
0958 struct work_struct rxdone_work;
0959 struct work_struct txdone_work;
0960
0961
0962
0963
0964 struct delayed_work autowakeup_work;
0965 struct work_struct sleep_work;
0966
0967
0968
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
0978
0979 const struct firmware *fw;
0980
0981
0982
0983
0984 DECLARE_KFIFO_PTR(txstatus_fifo, u32);
0985
0986
0987
0988
0989 struct hrtimer txstatus_timer;
0990
0991
0992
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
1002
1003 int rf_channel;
1004
1005
1006
1007
1008 spinlock_t irqmask_lock;
1009
1010
1011
1012
1013 struct list_head bar_list;
1014 spinlock_t bar_list_lock;
1015
1016
1017 unsigned int extra_tx_headroom;
1018
1019 struct usb_anchor *anchor;
1020 unsigned int num_proto_errs;
1021
1022
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
1034 __u8 ra[6];
1035 __u8 ta[6];
1036 __le16 control;
1037 __le16 start_seq_num;
1038 };
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 #define REGISTER_BUSY_COUNT 100
1049 #define REGISTER_USB_BUSY_COUNT 20
1050 #define REGISTER_BUSY_DELAY 100
1051
1052
1053
1054
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
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
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
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
1291
1292
1293
1294
1295 int rt2x00queue_map_txskb(struct queue_entry *entry);
1296
1297
1298
1299
1300
1301 void rt2x00queue_unmap_skb(struct queue_entry *entry);
1302
1303
1304
1305
1306
1307
1308
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
1325
1326
1327
1328 struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
1329 enum queue_index index);
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339 void rt2x00queue_pause_queue(struct data_queue *queue);
1340
1341
1342
1343
1344
1345
1346
1347
1348 void rt2x00queue_unpause_queue(struct data_queue *queue);
1349
1350
1351
1352
1353
1354
1355
1356 void rt2x00queue_start_queue(struct data_queue *queue);
1357
1358
1359
1360
1361
1362
1363
1364 void rt2x00queue_stop_queue(struct data_queue *queue);
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374 void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
1375
1376
1377
1378
1379
1380
1381
1382 void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
1383
1384
1385
1386
1387
1388
1389
1390
1391 void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401 void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
1402
1403
1404
1405
1406
1407
1408
1409
1410
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
1422
1423
1424
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
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
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
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
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