Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003     Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
0004     Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
0005     <http://rt2x00.serialmonkey.com>
0006 
0007  */
0008 
0009 /*
0010     Module: rt2x00lib
0011     Abstract: Data structures and definitions for the rt2x00lib module.
0012  */
0013 
0014 #ifndef RT2X00LIB_H
0015 #define RT2X00LIB_H
0016 
0017 /*
0018  * Interval defines
0019  */
0020 #define WATCHDOG_INTERVAL   round_jiffies_relative(HZ)
0021 #define LINK_TUNE_SECONDS   1
0022 #define LINK_TUNE_INTERVAL  round_jiffies_relative(LINK_TUNE_SECONDS * HZ)
0023 #define AGC_SECONDS     4
0024 #define VCO_SECONDS     10
0025 
0026 /*
0027  * rt2x00_rate: Per rate device information
0028  */
0029 struct rt2x00_rate {
0030     unsigned short flags;
0031 #define DEV_RATE_CCK            0x0001
0032 #define DEV_RATE_OFDM           0x0002
0033 #define DEV_RATE_SHORT_PREAMBLE     0x0004
0034 
0035     unsigned short bitrate; /* In 100kbit/s */
0036     unsigned short ratemask;
0037 
0038     unsigned short plcp;
0039     unsigned short mcs;
0040 };
0041 
0042 extern const struct rt2x00_rate rt2x00_supported_rates[12];
0043 
0044 static inline const struct rt2x00_rate *rt2x00_get_rate(const u16 hw_value)
0045 {
0046     return &rt2x00_supported_rates[hw_value & 0xff];
0047 }
0048 
0049 #define RATE_MCS(__mode, __mcs) \
0050     ((((__mode) & 0x00ff) << 8) | ((__mcs) & 0x00ff))
0051 
0052 static inline int rt2x00_get_rate_mcs(const u16 mcs_value)
0053 {
0054     return (mcs_value & 0x00ff);
0055 }
0056 
0057 /*
0058  * Radio control handlers.
0059  */
0060 int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev);
0061 void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev);
0062 
0063 /*
0064  * Initialization handlers.
0065  */
0066 int rt2x00lib_start(struct rt2x00_dev *rt2x00dev);
0067 void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev);
0068 
0069 /*
0070  * Configuration handlers.
0071  */
0072 void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
0073                struct rt2x00_intf *intf,
0074                enum nl80211_iftype type,
0075                const u8 *mac, const u8 *bssid);
0076 void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
0077               struct rt2x00_intf *intf,
0078               struct ieee80211_bss_conf *conf,
0079               u32 changed);
0080 void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
0081                   struct antenna_setup ant);
0082 void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
0083               struct ieee80211_conf *conf,
0084               const unsigned int changed_flags);
0085 
0086 /**
0087  * DOC: Queue handlers
0088  */
0089 
0090 /**
0091  * rt2x00queue_alloc_rxskb - allocate a skb for RX purposes.
0092  * @entry: The entry for which the skb will be applicable.
0093  */
0094 struct sk_buff *rt2x00queue_alloc_rxskb(struct queue_entry *entry, gfp_t gfp);
0095 
0096 /**
0097  * rt2x00queue_free_skb - free a skb
0098  * @entry: The entry for which the skb will be applicable.
0099  */
0100 void rt2x00queue_free_skb(struct queue_entry *entry);
0101 
0102 /**
0103  * rt2x00queue_align_frame - Align 802.11 frame to 4-byte boundary
0104  * @skb: The skb to align
0105  *
0106  * Align the start of the 802.11 frame to a 4-byte boundary, this could
0107  * mean the payload is not aligned properly though.
0108  */
0109 void rt2x00queue_align_frame(struct sk_buff *skb);
0110 
0111 /**
0112  * rt2x00queue_insert_l2pad - Align 802.11 header & payload to 4-byte boundary
0113  * @skb: The skb to align
0114  * @header_length: Length of 802.11 header
0115  *
0116  * Apply L2 padding to align both header and payload to 4-byte boundary
0117  */
0118 void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length);
0119 
0120 /**
0121  * rt2x00queue_insert_l2pad - Remove L2 padding from 802.11 frame
0122  * @skb: The skb to align
0123  * @header_length: Length of 802.11 header
0124  *
0125  * Remove L2 padding used to align both header and payload to 4-byte boundary,
0126  * by removing the L2 padding the header will no longer be 4-byte aligned.
0127  */
0128 void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length);
0129 
0130 /**
0131  * rt2x00queue_write_tx_frame - Write TX frame to hardware
0132  * @queue: Queue over which the frame should be send
0133  * @skb: The skb to send
0134  * @local: frame is not from mac80211
0135  */
0136 int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
0137                    struct ieee80211_sta *sta, bool local);
0138 
0139 /**
0140  * rt2x00queue_update_beacon - Send new beacon from mac80211
0141  *  to hardware. Handles locking by itself (mutex).
0142  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0143  * @vif: Interface for which the beacon should be updated.
0144  */
0145 int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
0146                   struct ieee80211_vif *vif);
0147 
0148 /**
0149  * rt2x00queue_update_beacon_locked - Send new beacon from mac80211
0150  *  to hardware. Caller needs to ensure locking.
0151  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0152  * @vif: Interface for which the beacon should be updated.
0153  */
0154 int rt2x00queue_update_beacon_locked(struct rt2x00_dev *rt2x00dev,
0155                      struct ieee80211_vif *vif);
0156 
0157 /**
0158  * rt2x00queue_clear_beacon - Clear beacon in hardware
0159  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0160  * @vif: Interface for which the beacon should be updated.
0161  */
0162 int rt2x00queue_clear_beacon(struct rt2x00_dev *rt2x00dev,
0163                  struct ieee80211_vif *vif);
0164 
0165 /**
0166  * rt2x00queue_index_inc - Index incrementation function
0167  * @entry: Queue entry (&struct queue_entry) to perform the action on.
0168  * @index: Index type (&enum queue_index) to perform the action on.
0169  *
0170  * This function will increase the requested index on the entry's queue,
0171  * it will grab the appropriate locks and handle queue overflow events by
0172  * resetting the index to the start of the queue.
0173  */
0174 void rt2x00queue_index_inc(struct queue_entry *entry, enum queue_index index);
0175 
0176 /**
0177  * rt2x00queue_init_queues - Initialize all data queues
0178  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0179  *
0180  * This function will loop through all available queues to clear all
0181  * index numbers and set the queue entry to the correct initialization
0182  * state.
0183  */
0184 void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev);
0185 
0186 int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev);
0187 void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev);
0188 int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev);
0189 void rt2x00queue_free(struct rt2x00_dev *rt2x00dev);
0190 
0191 /**
0192  * rt2x00link_update_stats - Update link statistics from RX frame
0193  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0194  * @skb: Received frame
0195  * @rxdesc: Received frame descriptor
0196  *
0197  * Update link statistics based on the information from the
0198  * received frame descriptor.
0199  */
0200 void rt2x00link_update_stats(struct rt2x00_dev *rt2x00dev,
0201                  struct sk_buff *skb,
0202                  struct rxdone_entry_desc *rxdesc);
0203 
0204 /**
0205  * rt2x00link_start_tuner - Start periodic link tuner work
0206  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0207  *
0208  * This start the link tuner periodic work, this work will
0209  * be executed periodically until &rt2x00link_stop_tuner has
0210  * been called.
0211  */
0212 void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev);
0213 
0214 /**
0215  * rt2x00link_stop_tuner - Stop periodic link tuner work
0216  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0217  *
0218  * After this function completed the link tuner will not
0219  * be running until &rt2x00link_start_tuner is called.
0220  */
0221 void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev);
0222 
0223 /**
0224  * rt2x00link_reset_tuner - Reset periodic link tuner work
0225  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0226  * @antenna: Should the antenna tuning also be reset
0227  *
0228  * The VGC limit configured in the hardware will be reset to 0
0229  * which forces the driver to rediscover the correct value for
0230  * the current association. This is needed when configuration
0231  * options have changed which could drastically change the
0232  * SNR level or link quality (i.e. changing the antenna setting).
0233  *
0234  * Resetting the link tuner will also cause the periodic work counter
0235  * to be reset. Any driver which has a fixed limit on the number
0236  * of rounds the link tuner is supposed to work will accept the
0237  * tuner actions again if this limit was previously reached.
0238  *
0239  * If @antenna is set to true a the software antenna diversity
0240  * tuning will also be reset.
0241  */
0242 void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna);
0243 
0244 /**
0245  * rt2x00link_start_watchdog - Start periodic watchdog monitoring
0246  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0247  *
0248  * This start the watchdog periodic work, this work will
0249  *be executed periodically until &rt2x00link_stop_watchdog has
0250  * been called.
0251  */
0252 void rt2x00link_start_watchdog(struct rt2x00_dev *rt2x00dev);
0253 
0254 /**
0255  * rt2x00link_stop_watchdog - Stop periodic watchdog monitoring
0256  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0257  *
0258  * After this function completed the watchdog monitoring will not
0259  * be running until &rt2x00link_start_watchdog is called.
0260  */
0261 void rt2x00link_stop_watchdog(struct rt2x00_dev *rt2x00dev);
0262 
0263 /**
0264  * rt2x00link_register - Initialize link tuning & watchdog functionality
0265  * @rt2x00dev: Pointer to &struct rt2x00_dev.
0266  *
0267  * Initialize work structure and all link tuning and watchdog related
0268  * parameters. This will not start the periodic work itself.
0269  */
0270 void rt2x00link_register(struct rt2x00_dev *rt2x00dev);
0271 
0272 /*
0273  * Firmware handlers.
0274  */
0275 #ifdef CONFIG_RT2X00_LIB_FIRMWARE
0276 int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev);
0277 void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev);
0278 #else
0279 static inline int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
0280 {
0281     return 0;
0282 }
0283 static inline void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
0284 {
0285 }
0286 #endif /* CONFIG_RT2X00_LIB_FIRMWARE */
0287 
0288 /*
0289  * Debugfs handlers.
0290  */
0291 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
0292 void rt2x00debug_register(struct rt2x00_dev *rt2x00dev);
0293 void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev);
0294 void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
0295                    struct rxdone_entry_desc *rxdesc);
0296 #else
0297 static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
0298 {
0299 }
0300 
0301 static inline void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
0302 {
0303 }
0304 
0305 static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
0306                          struct rxdone_entry_desc *rxdesc)
0307 {
0308 }
0309 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
0310 
0311 /*
0312  * Crypto handlers.
0313  */
0314 #ifdef CONFIG_RT2X00_LIB_CRYPTO
0315 enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key);
0316 void rt2x00crypto_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
0317                        struct sk_buff *skb,
0318                        struct txentry_desc *txdesc);
0319 unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
0320                       struct sk_buff *skb);
0321 void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
0322                  struct txentry_desc *txdesc);
0323 void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
0324                    struct txentry_desc *txdesc);
0325 void rt2x00crypto_tx_insert_iv(struct sk_buff *skb, unsigned int header_length);
0326 void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
0327                    unsigned int header_length,
0328                    struct rxdone_entry_desc *rxdesc);
0329 #else
0330 static inline enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key)
0331 {
0332     return CIPHER_NONE;
0333 }
0334 
0335 static inline void rt2x00crypto_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
0336                              struct sk_buff *skb,
0337                              struct txentry_desc *txdesc)
0338 {
0339 }
0340 
0341 static inline unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
0342                             struct sk_buff *skb)
0343 {
0344     return 0;
0345 }
0346 
0347 static inline void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
0348                        struct txentry_desc *txdesc)
0349 {
0350 }
0351 
0352 static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
0353                          struct txentry_desc *txdesc)
0354 {
0355 }
0356 
0357 static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb,
0358                          unsigned int header_length)
0359 {
0360 }
0361 
0362 static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
0363                          unsigned int header_length,
0364                          struct rxdone_entry_desc *rxdesc)
0365 {
0366 }
0367 #endif /* CONFIG_RT2X00_LIB_CRYPTO */
0368 
0369 /*
0370  * RFkill handlers.
0371  */
0372 static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
0373 {
0374     if (test_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags))
0375         wiphy_rfkill_start_polling(rt2x00dev->hw->wiphy);
0376 }
0377 
0378 static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
0379 {
0380     if (test_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags))
0381         wiphy_rfkill_stop_polling(rt2x00dev->hw->wiphy);
0382 }
0383 
0384 /*
0385  * LED handlers
0386  */
0387 #ifdef CONFIG_RT2X00_LIB_LEDS
0388 void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi);
0389 void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev, bool enabled);
0390 void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled);
0391 void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev, bool enabled);
0392 void rt2x00leds_register(struct rt2x00_dev *rt2x00dev);
0393 void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev);
0394 void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev);
0395 void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev);
0396 #else
0397 static inline void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev,
0398                       int rssi)
0399 {
0400 }
0401 
0402 static inline void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev,
0403                       bool enabled)
0404 {
0405 }
0406 
0407 static inline void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev,
0408                     bool enabled)
0409 {
0410 }
0411 
0412 static inline void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev,
0413                     bool enabled)
0414 {
0415 }
0416 
0417 static inline void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
0418 {
0419 }
0420 
0421 static inline void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev)
0422 {
0423 }
0424 
0425 static inline void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev)
0426 {
0427 }
0428 
0429 static inline void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev)
0430 {
0431 }
0432 #endif /* CONFIG_RT2X00_LIB_LEDS */
0433 
0434 #endif /* RT2X00LIB_H */