0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef ATH_H
0018 #define ATH_H
0019
0020 #include <linux/etherdevice.h>
0021 #include <linux/skbuff.h>
0022 #include <linux/if_ether.h>
0023 #include <linux/spinlock.h>
0024 #include <net/mac80211.h>
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #define ATH_KEYMAX 128
0035
0036 struct ath_ani {
0037 bool caldone;
0038 unsigned int longcal_timer;
0039 unsigned int shortcal_timer;
0040 unsigned int resetcal_timer;
0041 unsigned int checkani_timer;
0042 struct timer_list timer;
0043 };
0044
0045 struct ath_cycle_counters {
0046 u32 cycles;
0047 u32 rx_busy;
0048 u32 rx_frame;
0049 u32 tx_frame;
0050 };
0051
0052 enum ath_device_state {
0053 ATH_HW_UNAVAILABLE,
0054 ATH_HW_INITIALIZED,
0055 };
0056
0057 enum ath_op_flags {
0058 ATH_OP_INVALID,
0059 ATH_OP_BEACONS,
0060 ATH_OP_ANI_RUN,
0061 ATH_OP_PRIM_STA_VIF,
0062 ATH_OP_HW_RESET,
0063 ATH_OP_SCANNING,
0064 ATH_OP_MULTI_CHANNEL,
0065 ATH_OP_WOW_ENABLED,
0066 };
0067
0068 enum ath_bus_type {
0069 ATH_PCI,
0070 ATH_AHB,
0071 ATH_USB,
0072 };
0073
0074 struct reg_dmn_pair_mapping {
0075 u16 reg_domain;
0076 u16 reg_5ghz_ctl;
0077 u16 reg_2ghz_ctl;
0078 };
0079
0080 struct ath_regulatory {
0081 char alpha2[2];
0082 enum nl80211_dfs_regions region;
0083 u16 country_code;
0084 u16 max_power_level;
0085 u16 current_rd;
0086 int16_t power_limit;
0087 struct reg_dmn_pair_mapping *regpair;
0088 };
0089
0090 enum ath_crypt_caps {
0091 ATH_CRYPT_CAP_CIPHER_AESCCM = BIT(0),
0092 ATH_CRYPT_CAP_MIC_COMBINED = BIT(1),
0093 };
0094
0095 struct ath_keyval {
0096 u8 kv_type;
0097 u8 kv_pad;
0098 u16 kv_len;
0099 u8 kv_val[16];
0100 u8 kv_mic[8];
0101 u8 kv_txmic[8];
0102
0103
0104 };
0105
0106 enum ath_cipher {
0107 ATH_CIPHER_WEP = 0,
0108 ATH_CIPHER_AES_OCB = 1,
0109 ATH_CIPHER_AES_CCM = 2,
0110 ATH_CIPHER_CKIP = 3,
0111 ATH_CIPHER_TKIP = 4,
0112 ATH_CIPHER_CLR = 5,
0113 ATH_CIPHER_MIC = 127
0114 };
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 struct ath_ops {
0126 unsigned int (*read)(void *, u32 reg_offset);
0127 void (*multi_read)(void *, u32 *addr, u32 *val, u16 count);
0128 void (*write)(void *, u32 val, u32 reg_offset);
0129 void (*enable_write_buffer)(void *);
0130 void (*write_flush) (void *);
0131 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
0132 void (*enable_rmw_buffer)(void *);
0133 void (*rmw_flush) (void *);
0134
0135 };
0136
0137 struct ath_common;
0138 struct ath_bus_ops;
0139
0140 struct ath_ps_ops {
0141 void (*wakeup)(struct ath_common *common);
0142 void (*restore)(struct ath_common *common);
0143 };
0144
0145 struct ath_common {
0146 void *ah;
0147 void *priv;
0148 struct ieee80211_hw *hw;
0149 int debug_mask;
0150 enum ath_device_state state;
0151 unsigned long op_flags;
0152
0153 struct ath_ani ani;
0154
0155 u16 cachelsz;
0156 u16 curaid;
0157 u8 macaddr[ETH_ALEN];
0158 u8 curbssid[ETH_ALEN] __aligned(2);
0159 u8 bssidmask[ETH_ALEN];
0160
0161 u32 rx_bufsize;
0162
0163 u32 keymax;
0164 DECLARE_BITMAP(keymap, ATH_KEYMAX);
0165 DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
0166 DECLARE_BITMAP(ccmp_keymap, ATH_KEYMAX);
0167 enum ath_crypt_caps crypt_caps;
0168
0169 unsigned int clockrate;
0170
0171 spinlock_t cc_lock;
0172 struct ath_cycle_counters cc_ani;
0173 struct ath_cycle_counters cc_survey;
0174
0175 struct ath_regulatory regulatory;
0176 struct ath_regulatory reg_world_copy;
0177 const struct ath_ops *ops;
0178 const struct ath_bus_ops *bus_ops;
0179 const struct ath_ps_ops *ps_ops;
0180
0181 bool btcoex_enabled;
0182 bool disable_ani;
0183 bool bt_ant_diversity;
0184
0185 int last_rssi;
0186 struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
0187 };
0188
0189 static inline const struct ath_ps_ops *ath_ps_ops(struct ath_common *common)
0190 {
0191 return common->ps_ops;
0192 }
0193
0194 struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
0195 u32 len,
0196 gfp_t gfp_mask);
0197 bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr);
0198
0199 void ath_hw_setbssidmask(struct ath_common *common);
0200 void ath_key_delete(struct ath_common *common, u8 hw_key_idx);
0201 int ath_key_config(struct ath_common *common,
0202 struct ieee80211_vif *vif,
0203 struct ieee80211_sta *sta,
0204 struct ieee80211_key_conf *key);
0205 bool ath_hw_keyreset(struct ath_common *common, u16 entry);
0206 bool ath_hw_keysetmac(struct ath_common *common, u16 entry, const u8 *mac);
0207 void ath_hw_cycle_counters_update(struct ath_common *common);
0208 int32_t ath_hw_get_listen_time(struct ath_common *common);
0209
0210 __printf(3, 4)
0211 void ath_printk(const char *level, const struct ath_common *common,
0212 const char *fmt, ...);
0213
0214 #define ath_emerg(common, fmt, ...) \
0215 ath_printk(KERN_EMERG, common, fmt, ##__VA_ARGS__)
0216 #define ath_alert(common, fmt, ...) \
0217 ath_printk(KERN_ALERT, common, fmt, ##__VA_ARGS__)
0218 #define ath_crit(common, fmt, ...) \
0219 ath_printk(KERN_CRIT, common, fmt, ##__VA_ARGS__)
0220 #define ath_err(common, fmt, ...) \
0221 ath_printk(KERN_ERR, common, fmt, ##__VA_ARGS__)
0222 #define ath_warn(common, fmt, ...) \
0223 ath_printk(KERN_WARNING, common, fmt, ##__VA_ARGS__)
0224 #define ath_notice(common, fmt, ...) \
0225 ath_printk(KERN_NOTICE, common, fmt, ##__VA_ARGS__)
0226 #define ath_info(common, fmt, ...) \
0227 ath_printk(KERN_INFO, common, fmt, ##__VA_ARGS__)
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262 enum ATH_DEBUG {
0263 ATH_DBG_RESET = 0x00000001,
0264 ATH_DBG_QUEUE = 0x00000002,
0265 ATH_DBG_EEPROM = 0x00000004,
0266 ATH_DBG_CALIBRATE = 0x00000008,
0267 ATH_DBG_INTERRUPT = 0x00000010,
0268 ATH_DBG_REGULATORY = 0x00000020,
0269 ATH_DBG_ANI = 0x00000040,
0270 ATH_DBG_XMIT = 0x00000080,
0271 ATH_DBG_BEACON = 0x00000100,
0272 ATH_DBG_CONFIG = 0x00000200,
0273 ATH_DBG_FATAL = 0x00000400,
0274 ATH_DBG_PS = 0x00000800,
0275 ATH_DBG_BTCOEX = 0x00001000,
0276 ATH_DBG_WMI = 0x00002000,
0277 ATH_DBG_BSTUCK = 0x00004000,
0278 ATH_DBG_MCI = 0x00008000,
0279 ATH_DBG_DFS = 0x00010000,
0280 ATH_DBG_WOW = 0x00020000,
0281 ATH_DBG_CHAN_CTX = 0x00040000,
0282 ATH_DBG_DYNACK = 0x00080000,
0283 ATH_DBG_SPECTRAL_SCAN = 0x00100000,
0284 ATH_DBG_ANY = 0xffffffff
0285 };
0286
0287 #define ATH_DBG_DEFAULT (ATH_DBG_FATAL)
0288 #define ATH_DBG_MAX_LEN 512
0289
0290 #ifdef CONFIG_ATH_DEBUG
0291
0292 #define ath_dbg(common, dbg_mask, fmt, ...) \
0293 do { \
0294 if ((common)->debug_mask & ATH_DBG_##dbg_mask) \
0295 ath_printk(KERN_DEBUG, common, fmt, ##__VA_ARGS__); \
0296 } while (0)
0297
0298 #define ATH_DBG_WARN(foo, arg...) WARN(foo, arg)
0299 #define ATH_DBG_WARN_ON_ONCE(foo) WARN_ON_ONCE(foo)
0300
0301 #else
0302
0303 static inline __attribute__ ((format (printf, 3, 4)))
0304 void _ath_dbg(struct ath_common *common, enum ATH_DEBUG dbg_mask,
0305 const char *fmt, ...)
0306 {
0307 }
0308 #define ath_dbg(common, dbg_mask, fmt, ...) \
0309 _ath_dbg(common, ATH_DBG_##dbg_mask, fmt, ##__VA_ARGS__)
0310
0311 #define ATH_DBG_WARN(foo, arg...) do {} while (0)
0312 #define ATH_DBG_WARN_ON_ONCE(foo) ({ \
0313 int __ret_warn_once = !!(foo); \
0314 unlikely(__ret_warn_once); \
0315 })
0316
0317 #endif
0318
0319
0320 #ifdef CONFIG_ATH_DEBUG
0321 const char *ath_opmode_to_string(enum nl80211_iftype opmode);
0322 #else
0323 static inline const char *ath_opmode_to_string(enum nl80211_iftype opmode)
0324 {
0325 return "UNKNOWN";
0326 }
0327 #endif
0328
0329 extern const char *ath_bus_type_strings[];
0330 static inline const char *ath_bus_type_to_string(enum ath_bus_type bustype)
0331 {
0332 return ath_bus_type_strings[bustype];
0333 }
0334
0335 #endif