xref: /freebsd/sys/contrib/dev/athk/ath.h (revision eb50aa680f5864c5ae0f0137819bbe61b42a550e)
1ebacd801SBjoern A. Zeeb /*
2ebacd801SBjoern A. Zeeb  * Copyright (c) 2008-2009 Atheros Communications Inc.
3ebacd801SBjoern A. Zeeb  *
4ebacd801SBjoern A. Zeeb  * Permission to use, copy, modify, and/or distribute this software for any
5ebacd801SBjoern A. Zeeb  * purpose with or without fee is hereby granted, provided that the above
6ebacd801SBjoern A. Zeeb  * copyright notice and this permission notice appear in all copies.
7ebacd801SBjoern A. Zeeb  *
8ebacd801SBjoern A. Zeeb  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9ebacd801SBjoern A. Zeeb  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10ebacd801SBjoern A. Zeeb  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11ebacd801SBjoern A. Zeeb  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12ebacd801SBjoern A. Zeeb  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13ebacd801SBjoern A. Zeeb  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14ebacd801SBjoern A. Zeeb  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15ebacd801SBjoern A. Zeeb  */
16ebacd801SBjoern A. Zeeb 
17ebacd801SBjoern A. Zeeb #ifndef ATH_H
18ebacd801SBjoern A. Zeeb #define ATH_H
19ebacd801SBjoern A. Zeeb 
20ebacd801SBjoern A. Zeeb #include <linux/etherdevice.h>
21ebacd801SBjoern A. Zeeb #include <linux/skbuff.h>
22ebacd801SBjoern A. Zeeb #include <linux/if_ether.h>
23ebacd801SBjoern A. Zeeb #include <linux/spinlock.h>
24ebacd801SBjoern A. Zeeb #include <net/mac80211.h>
25*eb50aa68SBjoern A. Zeeb #if defined(__FreeBSD__)
26*eb50aa68SBjoern A. Zeeb #include <linux/stddef.h>
27*eb50aa68SBjoern A. Zeeb #endif
28ebacd801SBjoern A. Zeeb 
29ebacd801SBjoern A. Zeeb /*
30ebacd801SBjoern A. Zeeb  * The key cache is used for h/w cipher state and also for
31ebacd801SBjoern A. Zeeb  * tracking station state such as the current tx antenna.
32ebacd801SBjoern A. Zeeb  * We also setup a mapping table between key cache slot indices
33ebacd801SBjoern A. Zeeb  * and station state to short-circuit node lookups on rx.
34ebacd801SBjoern A. Zeeb  * Different parts have different size key caches.  We handle
35ebacd801SBjoern A. Zeeb  * up to ATH_KEYMAX entries (could dynamically allocate state).
36ebacd801SBjoern A. Zeeb  */
37ebacd801SBjoern A. Zeeb #define	ATH_KEYMAX	        128     /* max key cache size we handle */
38ebacd801SBjoern A. Zeeb 
39ebacd801SBjoern A. Zeeb struct ath_ani {
40ebacd801SBjoern A. Zeeb 	bool caldone;
41ebacd801SBjoern A. Zeeb 	unsigned int longcal_timer;
42ebacd801SBjoern A. Zeeb 	unsigned int shortcal_timer;
43ebacd801SBjoern A. Zeeb 	unsigned int resetcal_timer;
44ebacd801SBjoern A. Zeeb 	unsigned int checkani_timer;
45ebacd801SBjoern A. Zeeb 	struct timer_list timer;
46ebacd801SBjoern A. Zeeb };
47ebacd801SBjoern A. Zeeb 
48ebacd801SBjoern A. Zeeb struct ath_cycle_counters {
49ebacd801SBjoern A. Zeeb 	u32 cycles;
50ebacd801SBjoern A. Zeeb 	u32 rx_busy;
51ebacd801SBjoern A. Zeeb 	u32 rx_frame;
52ebacd801SBjoern A. Zeeb 	u32 tx_frame;
53ebacd801SBjoern A. Zeeb };
54ebacd801SBjoern A. Zeeb 
55ebacd801SBjoern A. Zeeb enum ath_device_state {
56ebacd801SBjoern A. Zeeb 	ATH_HW_UNAVAILABLE,
57ebacd801SBjoern A. Zeeb 	ATH_HW_INITIALIZED,
58ebacd801SBjoern A. Zeeb };
59ebacd801SBjoern A. Zeeb 
60ebacd801SBjoern A. Zeeb enum ath_op_flags {
61ebacd801SBjoern A. Zeeb 	ATH_OP_INVALID,
62ebacd801SBjoern A. Zeeb 	ATH_OP_BEACONS,
63ebacd801SBjoern A. Zeeb 	ATH_OP_ANI_RUN,
64ebacd801SBjoern A. Zeeb 	ATH_OP_PRIM_STA_VIF,
65ebacd801SBjoern A. Zeeb 	ATH_OP_HW_RESET,
66ebacd801SBjoern A. Zeeb 	ATH_OP_SCANNING,
67ebacd801SBjoern A. Zeeb 	ATH_OP_MULTI_CHANNEL,
68ebacd801SBjoern A. Zeeb 	ATH_OP_WOW_ENABLED,
69ebacd801SBjoern A. Zeeb };
70ebacd801SBjoern A. Zeeb 
71ebacd801SBjoern A. Zeeb enum ath_bus_type {
72ebacd801SBjoern A. Zeeb 	ATH_PCI,
73ebacd801SBjoern A. Zeeb 	ATH_AHB,
74ebacd801SBjoern A. Zeeb 	ATH_USB,
75ebacd801SBjoern A. Zeeb };
76ebacd801SBjoern A. Zeeb 
77ebacd801SBjoern A. Zeeb struct reg_dmn_pair_mapping {
78ebacd801SBjoern A. Zeeb 	u16 reg_domain;
79ebacd801SBjoern A. Zeeb 	u16 reg_5ghz_ctl;
80ebacd801SBjoern A. Zeeb 	u16 reg_2ghz_ctl;
81ebacd801SBjoern A. Zeeb };
82ebacd801SBjoern A. Zeeb 
83ebacd801SBjoern A. Zeeb struct ath_regulatory {
84ebacd801SBjoern A. Zeeb 	char alpha2[2];
85ebacd801SBjoern A. Zeeb 	enum nl80211_dfs_regions region;
86ebacd801SBjoern A. Zeeb 	u16 country_code;
87ebacd801SBjoern A. Zeeb 	u16 max_power_level;
88ebacd801SBjoern A. Zeeb 	u16 current_rd;
89ebacd801SBjoern A. Zeeb 	int16_t power_limit;
90ebacd801SBjoern A. Zeeb 	struct reg_dmn_pair_mapping *regpair;
91ebacd801SBjoern A. Zeeb };
92ebacd801SBjoern A. Zeeb 
93ebacd801SBjoern A. Zeeb enum ath_crypt_caps {
94ebacd801SBjoern A. Zeeb 	ATH_CRYPT_CAP_CIPHER_AESCCM		= BIT(0),
95ebacd801SBjoern A. Zeeb 	ATH_CRYPT_CAP_MIC_COMBINED		= BIT(1),
96ebacd801SBjoern A. Zeeb };
97ebacd801SBjoern A. Zeeb 
98ebacd801SBjoern A. Zeeb struct ath_keyval {
99ebacd801SBjoern A. Zeeb 	u8 kv_type;
100ebacd801SBjoern A. Zeeb 	u8 kv_pad;
101ebacd801SBjoern A. Zeeb 	u16 kv_len;
102*eb50aa68SBjoern A. Zeeb 	struct_group(kv_values,
103ebacd801SBjoern A. Zeeb 		u8 kv_val[16]; /* TK */
104ebacd801SBjoern A. Zeeb 		u8 kv_mic[8]; /* Michael MIC key */
105ebacd801SBjoern A. Zeeb 		u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
106ebacd801SBjoern A. Zeeb 				 * supports both MIC keys in the same key cache entry;
107ebacd801SBjoern A. Zeeb 				 * in that case, kv_mic is the RX key) */
108*eb50aa68SBjoern A. Zeeb 	);
109ebacd801SBjoern A. Zeeb };
110ebacd801SBjoern A. Zeeb 
111ebacd801SBjoern A. Zeeb enum ath_cipher {
112ebacd801SBjoern A. Zeeb 	ATH_CIPHER_WEP = 0,
113ebacd801SBjoern A. Zeeb 	ATH_CIPHER_AES_OCB = 1,
114ebacd801SBjoern A. Zeeb 	ATH_CIPHER_AES_CCM = 2,
115ebacd801SBjoern A. Zeeb 	ATH_CIPHER_CKIP = 3,
116ebacd801SBjoern A. Zeeb 	ATH_CIPHER_TKIP = 4,
117ebacd801SBjoern A. Zeeb 	ATH_CIPHER_CLR = 5,
118ebacd801SBjoern A. Zeeb 	ATH_CIPHER_MIC = 127
119ebacd801SBjoern A. Zeeb };
120ebacd801SBjoern A. Zeeb 
121ebacd801SBjoern A. Zeeb /**
122ebacd801SBjoern A. Zeeb  * struct ath_ops - Register read/write operations
123ebacd801SBjoern A. Zeeb  *
124ebacd801SBjoern A. Zeeb  * @read: Register read
125ebacd801SBjoern A. Zeeb  * @multi_read: Multiple register read
126ebacd801SBjoern A. Zeeb  * @write: Register write
127ebacd801SBjoern A. Zeeb  * @enable_write_buffer: Enable multiple register writes
128ebacd801SBjoern A. Zeeb  * @write_flush: flush buffered register writes and disable buffering
129ebacd801SBjoern A. Zeeb  */
130ebacd801SBjoern A. Zeeb struct ath_ops {
131ebacd801SBjoern A. Zeeb 	unsigned int (*read)(void *, u32 reg_offset);
132ebacd801SBjoern A. Zeeb 	void (*multi_read)(void *, u32 *addr, u32 *val, u16 count);
133ebacd801SBjoern A. Zeeb 	void (*write)(void *, u32 val, u32 reg_offset);
134ebacd801SBjoern A. Zeeb 	void (*enable_write_buffer)(void *);
135ebacd801SBjoern A. Zeeb 	void (*write_flush) (void *);
136ebacd801SBjoern A. Zeeb 	u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
137ebacd801SBjoern A. Zeeb 	void (*enable_rmw_buffer)(void *);
138ebacd801SBjoern A. Zeeb 	void (*rmw_flush) (void *);
139ebacd801SBjoern A. Zeeb 
140ebacd801SBjoern A. Zeeb };
141ebacd801SBjoern A. Zeeb 
142ebacd801SBjoern A. Zeeb struct ath_common;
143ebacd801SBjoern A. Zeeb struct ath_bus_ops;
144ebacd801SBjoern A. Zeeb 
145ebacd801SBjoern A. Zeeb struct ath_ps_ops {
146ebacd801SBjoern A. Zeeb 	void (*wakeup)(struct ath_common *common);
147ebacd801SBjoern A. Zeeb 	void (*restore)(struct ath_common *common);
148ebacd801SBjoern A. Zeeb };
149ebacd801SBjoern A. Zeeb 
150ebacd801SBjoern A. Zeeb struct ath_common {
151ebacd801SBjoern A. Zeeb 	void *ah;
152ebacd801SBjoern A. Zeeb 	void *priv;
153ebacd801SBjoern A. Zeeb 	struct ieee80211_hw *hw;
154ebacd801SBjoern A. Zeeb 	int debug_mask;
155ebacd801SBjoern A. Zeeb 	enum ath_device_state state;
156ebacd801SBjoern A. Zeeb 	unsigned long op_flags;
157ebacd801SBjoern A. Zeeb 
158ebacd801SBjoern A. Zeeb 	struct ath_ani ani;
159ebacd801SBjoern A. Zeeb 
160ebacd801SBjoern A. Zeeb 	u16 cachelsz;
161ebacd801SBjoern A. Zeeb 	u16 curaid;
162ebacd801SBjoern A. Zeeb 	u8 macaddr[ETH_ALEN];
163ebacd801SBjoern A. Zeeb 	u8 curbssid[ETH_ALEN] __aligned(2);
164ebacd801SBjoern A. Zeeb 	u8 bssidmask[ETH_ALEN];
165ebacd801SBjoern A. Zeeb 
166ebacd801SBjoern A. Zeeb 	u32 rx_bufsize;
167ebacd801SBjoern A. Zeeb 
168ebacd801SBjoern A. Zeeb 	u32 keymax;
169ebacd801SBjoern A. Zeeb 	DECLARE_BITMAP(keymap, ATH_KEYMAX);
170ebacd801SBjoern A. Zeeb 	DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
171ebacd801SBjoern A. Zeeb 	DECLARE_BITMAP(ccmp_keymap, ATH_KEYMAX);
172ebacd801SBjoern A. Zeeb 	enum ath_crypt_caps crypt_caps;
173ebacd801SBjoern A. Zeeb 
174ebacd801SBjoern A. Zeeb 	unsigned int clockrate;
175ebacd801SBjoern A. Zeeb 
176ebacd801SBjoern A. Zeeb 	spinlock_t cc_lock;
177ebacd801SBjoern A. Zeeb 	struct ath_cycle_counters cc_ani;
178ebacd801SBjoern A. Zeeb 	struct ath_cycle_counters cc_survey;
179ebacd801SBjoern A. Zeeb 
180ebacd801SBjoern A. Zeeb 	struct ath_regulatory regulatory;
181ebacd801SBjoern A. Zeeb 	struct ath_regulatory reg_world_copy;
182ebacd801SBjoern A. Zeeb 	const struct ath_ops *ops;
183ebacd801SBjoern A. Zeeb 	const struct ath_bus_ops *bus_ops;
184ebacd801SBjoern A. Zeeb 	const struct ath_ps_ops *ps_ops;
185ebacd801SBjoern A. Zeeb 
186ebacd801SBjoern A. Zeeb 	bool btcoex_enabled;
187ebacd801SBjoern A. Zeeb 	bool disable_ani;
188ebacd801SBjoern A. Zeeb 	bool bt_ant_diversity;
189ebacd801SBjoern A. Zeeb 
190ebacd801SBjoern A. Zeeb 	int last_rssi;
191ebacd801SBjoern A. Zeeb 	struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
192ebacd801SBjoern A. Zeeb };
193ebacd801SBjoern A. Zeeb 
ath_ps_ops(struct ath_common * common)194ebacd801SBjoern A. Zeeb static inline const struct ath_ps_ops *ath_ps_ops(struct ath_common *common)
195ebacd801SBjoern A. Zeeb {
196ebacd801SBjoern A. Zeeb 	return common->ps_ops;
197ebacd801SBjoern A. Zeeb }
198ebacd801SBjoern A. Zeeb 
199ebacd801SBjoern A. Zeeb struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
200ebacd801SBjoern A. Zeeb 				u32 len,
201ebacd801SBjoern A. Zeeb 				gfp_t gfp_mask);
202ebacd801SBjoern A. Zeeb bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr);
203ebacd801SBjoern A. Zeeb 
204ebacd801SBjoern A. Zeeb void ath_hw_setbssidmask(struct ath_common *common);
205ebacd801SBjoern A. Zeeb void ath_key_delete(struct ath_common *common, u8 hw_key_idx);
206ebacd801SBjoern A. Zeeb int ath_key_config(struct ath_common *common,
207ebacd801SBjoern A. Zeeb 			  struct ieee80211_vif *vif,
208ebacd801SBjoern A. Zeeb 			  struct ieee80211_sta *sta,
209ebacd801SBjoern A. Zeeb 			  struct ieee80211_key_conf *key);
210ebacd801SBjoern A. Zeeb bool ath_hw_keyreset(struct ath_common *common, u16 entry);
211ebacd801SBjoern A. Zeeb bool ath_hw_keysetmac(struct ath_common *common, u16 entry, const u8 *mac);
212ebacd801SBjoern A. Zeeb void ath_hw_cycle_counters_update(struct ath_common *common);
213ebacd801SBjoern A. Zeeb int32_t ath_hw_get_listen_time(struct ath_common *common);
214ebacd801SBjoern A. Zeeb 
215ebacd801SBjoern A. Zeeb __printf(3, 4)
216ebacd801SBjoern A. Zeeb void ath_printk(const char *level, const struct ath_common *common,
217ebacd801SBjoern A. Zeeb 		const char *fmt, ...);
218ebacd801SBjoern A. Zeeb 
219ebacd801SBjoern A. Zeeb #define ath_emerg(common, fmt, ...)				\
220ebacd801SBjoern A. Zeeb 	ath_printk(KERN_EMERG, common, fmt, ##__VA_ARGS__)
221ebacd801SBjoern A. Zeeb #define ath_alert(common, fmt, ...)				\
222ebacd801SBjoern A. Zeeb 	ath_printk(KERN_ALERT, common, fmt, ##__VA_ARGS__)
223ebacd801SBjoern A. Zeeb #define ath_crit(common, fmt, ...)				\
224ebacd801SBjoern A. Zeeb 	ath_printk(KERN_CRIT, common, fmt, ##__VA_ARGS__)
225ebacd801SBjoern A. Zeeb #define ath_err(common, fmt, ...)				\
226ebacd801SBjoern A. Zeeb 	ath_printk(KERN_ERR, common, fmt, ##__VA_ARGS__)
227ebacd801SBjoern A. Zeeb #define ath_warn(common, fmt, ...)				\
228ebacd801SBjoern A. Zeeb 	ath_printk(KERN_WARNING, common, fmt, ##__VA_ARGS__)
229ebacd801SBjoern A. Zeeb #define ath_notice(common, fmt, ...)				\
230ebacd801SBjoern A. Zeeb 	ath_printk(KERN_NOTICE, common, fmt, ##__VA_ARGS__)
231ebacd801SBjoern A. Zeeb #define ath_info(common, fmt, ...)				\
232ebacd801SBjoern A. Zeeb 	ath_printk(KERN_INFO, common, fmt, ##__VA_ARGS__)
233ebacd801SBjoern A. Zeeb 
234ebacd801SBjoern A. Zeeb /**
235ebacd801SBjoern A. Zeeb  * enum ath_debug_level - atheros wireless debug level
236ebacd801SBjoern A. Zeeb  *
237ebacd801SBjoern A. Zeeb  * @ATH_DBG_RESET: reset processing
238ebacd801SBjoern A. Zeeb  * @ATH_DBG_QUEUE: hardware queue management
239ebacd801SBjoern A. Zeeb  * @ATH_DBG_EEPROM: eeprom processing
240ebacd801SBjoern A. Zeeb  * @ATH_DBG_CALIBRATE: periodic calibration
241ebacd801SBjoern A. Zeeb  * @ATH_DBG_INTERRUPT: interrupt processing
242ebacd801SBjoern A. Zeeb  * @ATH_DBG_REGULATORY: regulatory processing
243ebacd801SBjoern A. Zeeb  * @ATH_DBG_ANI: adaptive noise immunitive processing
244ebacd801SBjoern A. Zeeb  * @ATH_DBG_XMIT: basic xmit operation
245ebacd801SBjoern A. Zeeb  * @ATH_DBG_BEACON: beacon handling
246ebacd801SBjoern A. Zeeb  * @ATH_DBG_CONFIG: configuration of the hardware
247ebacd801SBjoern A. Zeeb  * @ATH_DBG_FATAL: fatal errors, this is the default, DBG_DEFAULT
248ebacd801SBjoern A. Zeeb  * @ATH_DBG_PS: power save processing
249ebacd801SBjoern A. Zeeb  * @ATH_DBG_HWTIMER: hardware timer handling
250ebacd801SBjoern A. Zeeb  * @ATH_DBG_BTCOEX: bluetooth coexistance
251ebacd801SBjoern A. Zeeb  * @ATH_DBG_BSTUCK: stuck beacons
252ebacd801SBjoern A. Zeeb  * @ATH_DBG_MCI: Message Coexistence Interface, a private protocol
253ebacd801SBjoern A. Zeeb  *	used exclusively for WLAN-BT coexistence starting from
254ebacd801SBjoern A. Zeeb  *	AR9462.
255ebacd801SBjoern A. Zeeb  * @ATH_DBG_DFS: radar datection
256ebacd801SBjoern A. Zeeb  * @ATH_DBG_WOW: Wake on Wireless
257ebacd801SBjoern A. Zeeb  * @ATH_DBG_DYNACK: dynack handling
258ebacd801SBjoern A. Zeeb  * @ATH_DBG_SPECTRAL_SCAN: FFT spectral scan
259ebacd801SBjoern A. Zeeb  * @ATH_DBG_ANY: enable all debugging
260ebacd801SBjoern A. Zeeb  *
261ebacd801SBjoern A. Zeeb  * The debug level is used to control the amount and type of debugging output
262ebacd801SBjoern A. Zeeb  * we want to see. Each driver has its own method for enabling debugging and
263ebacd801SBjoern A. Zeeb  * modifying debug level states -- but this is typically done through a
264ebacd801SBjoern A. Zeeb  * module parameter 'debug' along with a respective 'debug' debugfs file
265ebacd801SBjoern A. Zeeb  * entry.
266ebacd801SBjoern A. Zeeb  */
267ebacd801SBjoern A. Zeeb enum ATH_DEBUG {
268ebacd801SBjoern A. Zeeb 	ATH_DBG_RESET		= 0x00000001,
269ebacd801SBjoern A. Zeeb 	ATH_DBG_QUEUE		= 0x00000002,
270ebacd801SBjoern A. Zeeb 	ATH_DBG_EEPROM		= 0x00000004,
271ebacd801SBjoern A. Zeeb 	ATH_DBG_CALIBRATE	= 0x00000008,
272ebacd801SBjoern A. Zeeb 	ATH_DBG_INTERRUPT	= 0x00000010,
273ebacd801SBjoern A. Zeeb 	ATH_DBG_REGULATORY	= 0x00000020,
274ebacd801SBjoern A. Zeeb 	ATH_DBG_ANI		= 0x00000040,
275ebacd801SBjoern A. Zeeb 	ATH_DBG_XMIT		= 0x00000080,
276ebacd801SBjoern A. Zeeb 	ATH_DBG_BEACON		= 0x00000100,
277ebacd801SBjoern A. Zeeb 	ATH_DBG_CONFIG		= 0x00000200,
278ebacd801SBjoern A. Zeeb 	ATH_DBG_FATAL		= 0x00000400,
279ebacd801SBjoern A. Zeeb 	ATH_DBG_PS		= 0x00000800,
280ebacd801SBjoern A. Zeeb 	ATH_DBG_BTCOEX		= 0x00001000,
281ebacd801SBjoern A. Zeeb 	ATH_DBG_WMI		= 0x00002000,
282ebacd801SBjoern A. Zeeb 	ATH_DBG_BSTUCK		= 0x00004000,
283ebacd801SBjoern A. Zeeb 	ATH_DBG_MCI		= 0x00008000,
284ebacd801SBjoern A. Zeeb 	ATH_DBG_DFS		= 0x00010000,
285ebacd801SBjoern A. Zeeb 	ATH_DBG_WOW		= 0x00020000,
286ebacd801SBjoern A. Zeeb 	ATH_DBG_CHAN_CTX	= 0x00040000,
287ebacd801SBjoern A. Zeeb 	ATH_DBG_DYNACK		= 0x00080000,
288ebacd801SBjoern A. Zeeb 	ATH_DBG_SPECTRAL_SCAN	= 0x00100000,
289ebacd801SBjoern A. Zeeb 	ATH_DBG_ANY		= 0xffffffff
290ebacd801SBjoern A. Zeeb };
291ebacd801SBjoern A. Zeeb 
292ebacd801SBjoern A. Zeeb #define ATH_DBG_DEFAULT (ATH_DBG_FATAL)
293ebacd801SBjoern A. Zeeb #define ATH_DBG_MAX_LEN 512
294ebacd801SBjoern A. Zeeb 
295ebacd801SBjoern A. Zeeb #ifdef CONFIG_ATH_DEBUG
296ebacd801SBjoern A. Zeeb 
297ebacd801SBjoern A. Zeeb #define ath_dbg(common, dbg_mask, fmt, ...)				\
298ebacd801SBjoern A. Zeeb do {									\
299ebacd801SBjoern A. Zeeb 	if ((common)->debug_mask & ATH_DBG_##dbg_mask)			\
300ebacd801SBjoern A. Zeeb 		ath_printk(KERN_DEBUG, common, fmt, ##__VA_ARGS__);	\
301ebacd801SBjoern A. Zeeb } while (0)
302ebacd801SBjoern A. Zeeb 
303ebacd801SBjoern A. Zeeb #define ATH_DBG_WARN(foo, arg...) WARN(foo, arg)
304ebacd801SBjoern A. Zeeb #define ATH_DBG_WARN_ON_ONCE(foo) WARN_ON_ONCE(foo)
305ebacd801SBjoern A. Zeeb 
306ebacd801SBjoern A. Zeeb #else
307ebacd801SBjoern A. Zeeb 
308ebacd801SBjoern A. Zeeb static inline  __attribute__ ((format (printf, 3, 4)))
_ath_dbg(struct ath_common * common,enum ATH_DEBUG dbg_mask,const char * fmt,...)309ebacd801SBjoern A. Zeeb void _ath_dbg(struct ath_common *common, enum ATH_DEBUG dbg_mask,
310ebacd801SBjoern A. Zeeb 	     const char *fmt, ...)
311ebacd801SBjoern A. Zeeb {
312ebacd801SBjoern A. Zeeb }
313ebacd801SBjoern A. Zeeb #define ath_dbg(common, dbg_mask, fmt, ...)				\
314ebacd801SBjoern A. Zeeb 	_ath_dbg(common, ATH_DBG_##dbg_mask, fmt, ##__VA_ARGS__)
315ebacd801SBjoern A. Zeeb 
316ebacd801SBjoern A. Zeeb #define ATH_DBG_WARN(foo, arg...) do {} while (0)
317ebacd801SBjoern A. Zeeb #define ATH_DBG_WARN_ON_ONCE(foo) ({				\
318ebacd801SBjoern A. Zeeb 	int __ret_warn_once = !!(foo);				\
319ebacd801SBjoern A. Zeeb 	unlikely(__ret_warn_once);				\
320ebacd801SBjoern A. Zeeb })
321ebacd801SBjoern A. Zeeb 
322ebacd801SBjoern A. Zeeb #endif /* CONFIG_ATH_DEBUG */
323ebacd801SBjoern A. Zeeb 
324ebacd801SBjoern A. Zeeb /** Returns string describing opmode, or NULL if unknown mode. */
325ebacd801SBjoern A. Zeeb #ifdef CONFIG_ATH_DEBUG
326ebacd801SBjoern A. Zeeb const char *ath_opmode_to_string(enum nl80211_iftype opmode);
327ebacd801SBjoern A. Zeeb #else
ath_opmode_to_string(enum nl80211_iftype opmode)328ebacd801SBjoern A. Zeeb static inline const char *ath_opmode_to_string(enum nl80211_iftype opmode)
329ebacd801SBjoern A. Zeeb {
330ebacd801SBjoern A. Zeeb 	return "UNKNOWN";
331ebacd801SBjoern A. Zeeb }
332ebacd801SBjoern A. Zeeb #endif
333ebacd801SBjoern A. Zeeb 
334ebacd801SBjoern A. Zeeb extern const char *ath_bus_type_strings[];
ath_bus_type_to_string(enum ath_bus_type bustype)335ebacd801SBjoern A. Zeeb static inline const char *ath_bus_type_to_string(enum ath_bus_type bustype)
336ebacd801SBjoern A. Zeeb {
337ebacd801SBjoern A. Zeeb 	return ath_bus_type_strings[bustype];
338ebacd801SBjoern A. Zeeb }
339ebacd801SBjoern A. Zeeb 
340ebacd801SBjoern A. Zeeb #endif /* ATH_H */
341