blob: a3b6e27d91219a54778114f2f8195713cf911e61 [file] [log] [blame]
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -07001/*
2 * Copyright (c) 2008-2009 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef ATH_H
18#define ATH_H
19
Oleksij Rempelf1d267c2014-01-15 17:37:42 +010020#include <linux/etherdevice.h>
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -070021#include <linux/skbuff.h>
Luis R. Rodriguezbcd8f542009-09-09 22:43:17 -070022#include <linux/if_ether.h>
Felix Fietkaub5bfc562010-10-08 22:13:53 +020023#include <linux/spinlock.h>
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070024#include <net/mac80211.h>
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -070025
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -080026/*
27 * The key cache is used for h/w cipher state and also for
28 * tracking station state such as the current tx antenna.
29 * We also setup a mapping table between key cache slot indices
30 * and station state to short-circuit node lookups on rx.
31 * Different parts have different size key caches. We handle
32 * up to ATH_KEYMAX entries (could dynamically allocate state).
33 */
34#define ATH_KEYMAX 128 /* max key cache size we handle */
35
Luis R. Rodriguez17753742009-09-09 22:19:26 -070036static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
37
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -080038struct ath_ani {
39 bool caldone;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -080040 unsigned int longcal_timer;
41 unsigned int shortcal_timer;
42 unsigned int resetcal_timer;
43 unsigned int checkani_timer;
44 struct timer_list timer;
45};
46
Felix Fietkaub5bfc562010-10-08 22:13:53 +020047struct ath_cycle_counters {
48 u32 cycles;
49 u32 rx_busy;
50 u32 rx_frame;
51 u32 tx_frame;
52};
53
Luis R. Rodriguez211f5852009-10-06 21:19:07 -040054enum ath_device_state {
55 ATH_HW_UNAVAILABLE,
56 ATH_HW_INITIALIZED,
57};
58
Oleksij Rempeleefa01d2014-02-27 11:40:46 +010059enum ath_op_flags {
60 ATH_OP_INVALID,
61 ATH_OP_BEACONS,
62 ATH_OP_ANI_RUN,
63 ATH_OP_PRIM_STA_VIF,
64 ATH_OP_HW_RESET,
65 ATH_OP_SCANNING,
Felix Fietkau26f16c22014-06-11 16:18:00 +053066 ATH_OP_MULTI_CHANNEL,
Oleksij Rempeleefa01d2014-02-27 11:40:46 +010067};
68
Sujith497ad9a2010-04-01 10:28:20 +053069enum ath_bus_type {
70 ATH_PCI,
71 ATH_AHB,
72 ATH_USB,
73};
74
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -070075struct reg_dmn_pair_mapping {
Kalle Valoef8c0012014-02-13 18:13:12 +020076 u16 reg_domain;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -070077 u16 reg_5ghz_ctl;
78 u16 reg_2ghz_ctl;
79};
80
81struct ath_regulatory {
82 char alpha2[2];
83 u16 country_code;
84 u16 max_power_level;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -070085 u16 current_rd;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -070086 int16_t power_limit;
87 struct reg_dmn_pair_mapping *regpair;
88};
89
Bruno Randolf34a13052010-09-08 16:04:33 +090090enum ath_crypt_caps {
Bruno Randolfce2220d2010-09-17 11:36:25 +090091 ATH_CRYPT_CAP_CIPHER_AESCCM = BIT(0),
92 ATH_CRYPT_CAP_MIC_COMBINED = BIT(1),
Bruno Randolf34a13052010-09-08 16:04:33 +090093};
94
Bruno Randolf1bba5b72010-09-08 16:04:38 +090095struct ath_keyval {
96 u8 kv_type;
97 u8 kv_pad;
98 u16 kv_len;
99 u8 kv_val[16]; /* TK */
100 u8 kv_mic[8]; /* Michael MIC key */
101 u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
102 * supports both MIC keys in the same key cache entry;
103 * in that case, kv_mic is the RX key) */
104};
105
106enum ath_cipher {
107 ATH_CIPHER_WEP = 0,
108 ATH_CIPHER_AES_OCB = 1,
109 ATH_CIPHER_AES_CCM = 2,
110 ATH_CIPHER_CKIP = 3,
111 ATH_CIPHER_TKIP = 4,
112 ATH_CIPHER_CLR = 5,
113 ATH_CIPHER_MIC = 127
114};
115
Sujith50f56312010-04-16 11:53:50 +0530116/**
117 * struct ath_ops - Register read/write operations
118 *
119 * @read: Register read
Sujith Manoharan09a525d2011-01-04 13:17:18 +0530120 * @multi_read: Multiple register read
Sujith50f56312010-04-16 11:53:50 +0530121 * @write: Register write
122 * @enable_write_buffer: Enable multiple register writes
Felix Fietkau435c1612010-10-05 12:03:42 +0200123 * @write_flush: flush buffered register writes and disable buffering
Sujith50f56312010-04-16 11:53:50 +0530124 */
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -0700125struct ath_ops {
126 unsigned int (*read)(void *, u32 reg_offset);
Sujith Manoharan09a525d2011-01-04 13:17:18 +0530127 void (*multi_read)(void *, u32 *addr, u32 *val, u16 count);
Sujith50f56312010-04-16 11:53:50 +0530128 void (*write)(void *, u32 val, u32 reg_offset);
129 void (*enable_write_buffer)(void *);
Sujith50f56312010-04-16 11:53:50 +0530130 void (*write_flush) (void *);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100131 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -0700132};
133
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -0700134struct ath_common;
Felix Fietkau0cb9e062011-04-13 21:56:43 +0200135struct ath_bus_ops;
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -0700136
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -0700137struct ath_common {
Luis R. Rodriguez13b81552009-09-10 17:52:45 -0700138 void *ah;
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400139 void *priv;
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -0700140 struct ieee80211_hw *hw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700141 int debug_mask;
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400142 enum ath_device_state state;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100143 unsigned long op_flags;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700144
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800145 struct ath_ani ani;
146
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -0700147 u16 cachelsz;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700148 u16 curaid;
149 u8 macaddr[ETH_ALEN];
150 u8 curbssid[ETH_ALEN];
151 u8 bssidmask[ETH_ALEN];
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700152
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800153 u32 rx_bufsize;
154
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800155 u32 keymax;
156 DECLARE_BITMAP(keymap, ATH_KEYMAX);
Felix Fietkau56363dd2010-08-28 18:21:21 +0200157 DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
Felix Fietkaubed3d9c2012-06-23 19:23:31 +0200158 DECLARE_BITMAP(ccmp_keymap, ATH_KEYMAX);
Bruno Randolf34a13052010-09-08 16:04:33 +0900159 enum ath_crypt_caps crypt_caps;
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800160
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200161 unsigned int clockrate;
162
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200163 spinlock_t cc_lock;
164 struct ath_cycle_counters cc_ani;
165 struct ath_cycle_counters cc_survey;
166
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700167 struct ath_regulatory regulatory;
Luis R. Rodriguezde1c7322011-12-08 23:59:24 +0530168 struct ath_regulatory reg_world_copy;
Luis R. Rodriguez9adca122009-09-10 18:04:47 -0700169 const struct ath_ops *ops;
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -0700170 const struct ath_bus_ops *bus_ops;
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -0800171
172 bool btcoex_enabled;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530173 bool disable_ani;
Sujith Manoharan63081302013-08-04 14:21:55 +0530174 bool bt_ant_diversity;
Oleksij Rempel2f2cb322014-02-04 10:27:38 +0100175
176 int last_rssi;
Oleksij Rempel13f71052014-02-25 14:48:50 +0100177 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -0700178};
179
180struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
181 u32 len,
182 gfp_t gfp_mask);
Oleksij Rempelf1d267c2014-01-15 17:37:42 +0100183bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr);
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -0700184
Luis R. Rodriguez13b81552009-09-10 17:52:45 -0700185void ath_hw_setbssidmask(struct ath_common *common);
Bruno Randolf1bba5b72010-09-08 16:04:38 +0900186void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key);
187int ath_key_config(struct ath_common *common,
188 struct ieee80211_vif *vif,
189 struct ieee80211_sta *sta,
190 struct ieee80211_key_conf *key);
191bool ath_hw_keyreset(struct ath_common *common, u16 entry);
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200192void ath_hw_cycle_counters_update(struct ath_common *common);
193int32_t ath_hw_get_listen_time(struct ath_common *common);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -0700194
Ben Greear98b36a02012-03-08 10:20:55 -0800195__printf(3, 4)
196void ath_printk(const char *level, const struct ath_common *common,
197 const char *fmt, ...);
Joe Perches21a99f92010-12-02 19:12:35 -0800198
199#define ath_emerg(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800200 ath_printk(KERN_EMERG, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800201#define ath_alert(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800202 ath_printk(KERN_ALERT, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800203#define ath_crit(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800204 ath_printk(KERN_CRIT, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800205#define ath_err(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800206 ath_printk(KERN_ERR, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800207#define ath_warn(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800208 ath_printk(KERN_WARNING, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800209#define ath_notice(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800210 ath_printk(KERN_NOTICE, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800211#define ath_info(common, fmt, ...) \
Ben Greear98b36a02012-03-08 10:20:55 -0800212 ath_printk(KERN_INFO, common, fmt, ##__VA_ARGS__)
Joe Perches21a99f92010-12-02 19:12:35 -0800213
214/**
215 * enum ath_debug_level - atheros wireless debug level
216 *
217 * @ATH_DBG_RESET: reset processing
218 * @ATH_DBG_QUEUE: hardware queue management
219 * @ATH_DBG_EEPROM: eeprom processing
220 * @ATH_DBG_CALIBRATE: periodic calibration
221 * @ATH_DBG_INTERRUPT: interrupt processing
222 * @ATH_DBG_REGULATORY: regulatory processing
223 * @ATH_DBG_ANI: adaptive noise immunitive processing
224 * @ATH_DBG_XMIT: basic xmit operation
225 * @ATH_DBG_BEACON: beacon handling
226 * @ATH_DBG_CONFIG: configuration of the hardware
227 * @ATH_DBG_FATAL: fatal errors, this is the default, DBG_DEFAULT
228 * @ATH_DBG_PS: power save processing
229 * @ATH_DBG_HWTIMER: hardware timer handling
230 * @ATH_DBG_BTCOEX: bluetooth coexistance
231 * @ATH_DBG_BSTUCK: stuck beacons
Luis R. Rodriguez55e435d2011-12-14 13:56:36 -0800232 * @ATH_DBG_MCI: Message Coexistence Interface, a private protocol
233 * used exclusively for WLAN-BT coexistence starting from
234 * AR9462.
Zefir Kurtisi9b203c82011-12-14 20:16:32 -0800235 * @ATH_DBG_DFS: radar datection
Mohammed Shafi Shajakhanb3ba6c52012-07-10 14:56:34 +0530236 * @ATH_DBG_WOW: Wake on Wireless
Lorenzo Bianconic774d572014-09-16 02:13:09 +0200237 * @ATH_DBG_DYNACK: dynack handling
Joe Perches21a99f92010-12-02 19:12:35 -0800238 * @ATH_DBG_ANY: enable all debugging
239 *
240 * The debug level is used to control the amount and type of debugging output
241 * we want to see. Each driver has its own method for enabling debugging and
242 * modifying debug level states -- but this is typically done through a
243 * module parameter 'debug' along with a respective 'debug' debugfs file
244 * entry.
245 */
246enum ATH_DEBUG {
247 ATH_DBG_RESET = 0x00000001,
248 ATH_DBG_QUEUE = 0x00000002,
249 ATH_DBG_EEPROM = 0x00000004,
250 ATH_DBG_CALIBRATE = 0x00000008,
251 ATH_DBG_INTERRUPT = 0x00000010,
252 ATH_DBG_REGULATORY = 0x00000020,
253 ATH_DBG_ANI = 0x00000040,
254 ATH_DBG_XMIT = 0x00000080,
255 ATH_DBG_BEACON = 0x00000100,
256 ATH_DBG_CONFIG = 0x00000200,
257 ATH_DBG_FATAL = 0x00000400,
258 ATH_DBG_PS = 0x00000800,
Sujith Manoharan14335312013-06-18 10:13:39 +0530259 ATH_DBG_BTCOEX = 0x00001000,
260 ATH_DBG_WMI = 0x00002000,
261 ATH_DBG_BSTUCK = 0x00004000,
262 ATH_DBG_MCI = 0x00008000,
263 ATH_DBG_DFS = 0x00010000,
264 ATH_DBG_WOW = 0x00020000,
Sujith Manoharan27328a72014-08-22 20:39:24 +0530265 ATH_DBG_CHAN_CTX = 0x00040000,
Lorenzo Bianconic774d572014-09-16 02:13:09 +0200266 ATH_DBG_DYNACK = 0x00080000,
Joe Perches21a99f92010-12-02 19:12:35 -0800267 ATH_DBG_ANY = 0xffffffff
268};
269
270#define ATH_DBG_DEFAULT (ATH_DBG_FATAL)
271
272#ifdef CONFIG_ATH_DEBUG
273
Joe Perches7b8112d2011-08-26 01:56:38 -0700274#define ath_dbg(common, dbg_mask, fmt, ...) \
275do { \
Joe Perchesd2182b62011-12-15 14:55:53 -0800276 if ((common)->debug_mask & ATH_DBG_##dbg_mask) \
Ben Greear98b36a02012-03-08 10:20:55 -0800277 ath_printk(KERN_DEBUG, common, fmt, ##__VA_ARGS__); \
Joe Perches7b8112d2011-08-26 01:56:38 -0700278} while (0)
279
Joe Perches21a99f92010-12-02 19:12:35 -0800280#define ATH_DBG_WARN(foo, arg...) WARN(foo, arg)
Ben Greeard7fd1b502010-12-06 13:13:07 -0800281#define ATH_DBG_WARN_ON_ONCE(foo) WARN_ON_ONCE(foo)
Joe Perches21a99f92010-12-02 19:12:35 -0800282
283#else
284
Joe Perchesb9075fa2011-10-31 17:11:33 -0700285static inline __attribute__ ((format (printf, 3, 4)))
Joe Perchesd2182b62011-12-15 14:55:53 -0800286void _ath_dbg(struct ath_common *common, enum ATH_DEBUG dbg_mask,
Joe Perches7b8112d2011-08-26 01:56:38 -0700287 const char *fmt, ...)
Joe Perches21a99f92010-12-02 19:12:35 -0800288{
Joe Perches21a99f92010-12-02 19:12:35 -0800289}
Joe Perchesd2182b62011-12-15 14:55:53 -0800290#define ath_dbg(common, dbg_mask, fmt, ...) \
291 _ath_dbg(common, ATH_DBG_##dbg_mask, fmt, ##__VA_ARGS__)
292
Joe Perches21a99f92010-12-02 19:12:35 -0800293#define ATH_DBG_WARN(foo, arg...) do {} while (0)
John W. Linvilleb7613372010-12-09 09:08:47 -0500294#define ATH_DBG_WARN_ON_ONCE(foo) ({ \
295 int __ret_warn_once = !!(foo); \
296 unlikely(__ret_warn_once); \
297})
Joe Perches21a99f92010-12-02 19:12:35 -0800298
299#endif /* CONFIG_ATH_DEBUG */
300
301/** Returns string describing opmode, or NULL if unknown mode. */
302#ifdef CONFIG_ATH_DEBUG
303const char *ath_opmode_to_string(enum nl80211_iftype opmode);
304#else
305static inline const char *ath_opmode_to_string(enum nl80211_iftype opmode)
306{
307 return "UNKNOWN";
308}
309#endif
310
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -0700311#endif /* ATH_H */