xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/ath/ath9k/ath9k.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2008-2011 Atheros Communications Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, and/or distribute this software for any
5*4882a593Smuzhiyun  * purpose with or without fee is hereby granted, provided that the above
6*4882a593Smuzhiyun  * copyright notice and this permission notice appear in all copies.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*4882a593Smuzhiyun  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*4882a593Smuzhiyun  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*4882a593Smuzhiyun  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*4882a593Smuzhiyun  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*4882a593Smuzhiyun  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifndef ATH9K_H
18*4882a593Smuzhiyun #define ATH9K_H
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/etherdevice.h>
21*4882a593Smuzhiyun #include <linux/device.h>
22*4882a593Smuzhiyun #include <linux/interrupt.h>
23*4882a593Smuzhiyun #include <linux/leds.h>
24*4882a593Smuzhiyun #include <linux/completion.h>
25*4882a593Smuzhiyun #include <linux/time.h>
26*4882a593Smuzhiyun #include <linux/hw_random.h>
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include "common.h"
29*4882a593Smuzhiyun #include "debug.h"
30*4882a593Smuzhiyun #include "mci.h"
31*4882a593Smuzhiyun #include "dfs.h"
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun struct ath_node;
34*4882a593Smuzhiyun struct ath_vif;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun extern struct ieee80211_ops ath9k_ops;
37*4882a593Smuzhiyun extern int ath9k_modparam_nohwcrypt;
38*4882a593Smuzhiyun extern int ath9k_led_blink;
39*4882a593Smuzhiyun extern bool is_ath9k_unloaded;
40*4882a593Smuzhiyun extern int ath9k_use_chanctx;
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /*************************/
43*4882a593Smuzhiyun /* Descriptor Management */
44*4882a593Smuzhiyun /*************************/
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define ATH_TXSTATUS_RING_SIZE 512
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* Macro to expand scalars to 64-bit objects */
49*4882a593Smuzhiyun #define	ito64(x) (sizeof(x) == 1) ?			\
50*4882a593Smuzhiyun 	(((unsigned long long int)(x)) & (0xff)) :	\
51*4882a593Smuzhiyun 	(sizeof(x) == 2) ?				\
52*4882a593Smuzhiyun 	(((unsigned long long int)(x)) & 0xffff) :	\
53*4882a593Smuzhiyun 	((sizeof(x) == 4) ?				\
54*4882a593Smuzhiyun 	 (((unsigned long long int)(x)) & 0xffffffff) : \
55*4882a593Smuzhiyun 	 (unsigned long long int)(x))
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #define ATH_TXBUF_RESET(_bf) do {				\
58*4882a593Smuzhiyun 		(_bf)->bf_lastbf = NULL;			\
59*4882a593Smuzhiyun 		(_bf)->bf_next = NULL;				\
60*4882a593Smuzhiyun 		memset(&((_bf)->bf_state), 0,			\
61*4882a593Smuzhiyun 		       sizeof(struct ath_buf_state));		\
62*4882a593Smuzhiyun 	} while (0)
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #define	DS2PHYS(_dd, _ds)						\
65*4882a593Smuzhiyun 	((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
66*4882a593Smuzhiyun #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
67*4882a593Smuzhiyun #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun struct ath_descdma {
70*4882a593Smuzhiyun 	void *dd_desc;
71*4882a593Smuzhiyun 	dma_addr_t dd_desc_paddr;
72*4882a593Smuzhiyun 	u32 dd_desc_len;
73*4882a593Smuzhiyun };
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
76*4882a593Smuzhiyun 		      struct list_head *head, const char *name,
77*4882a593Smuzhiyun 		      int nbuf, int ndesc, bool is_tx);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /***********/
80*4882a593Smuzhiyun /* RX / TX */
81*4882a593Smuzhiyun /***********/
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #define	ATH_TXQ_SETUP(sc, i) ((sc)->tx.txqsetup & (1<<i))
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /* increment with wrap-around */
86*4882a593Smuzhiyun #define INCR(_l, _sz)   do {			\
87*4882a593Smuzhiyun 		(_l)++;				\
88*4882a593Smuzhiyun 		(_l) &= ((_sz) - 1);		\
89*4882a593Smuzhiyun 	} while (0)
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #define ATH_RXBUF               512
92*4882a593Smuzhiyun #define ATH_TXBUF               512
93*4882a593Smuzhiyun #define ATH_TXBUF_RESERVE       5
94*4882a593Smuzhiyun #define ATH_TXMAXTRY            13
95*4882a593Smuzhiyun #define ATH_MAX_SW_RETRIES      30
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun #define TID_TO_WME_AC(_tid)				\
98*4882a593Smuzhiyun 	((((_tid) == 0) || ((_tid) == 3)) ? IEEE80211_AC_BE :	\
99*4882a593Smuzhiyun 	 (((_tid) == 1) || ((_tid) == 2)) ? IEEE80211_AC_BK :	\
100*4882a593Smuzhiyun 	 (((_tid) == 4) || ((_tid) == 5)) ? IEEE80211_AC_VI :	\
101*4882a593Smuzhiyun 	 IEEE80211_AC_VO)
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #define ATH_AGGR_DELIM_SZ          4
104*4882a593Smuzhiyun #define ATH_AGGR_MINPLEN           256 /* in bytes, minimum packet length */
105*4882a593Smuzhiyun /* number of delimiters for encryption padding */
106*4882a593Smuzhiyun #define ATH_AGGR_ENCRYPTDELIM      10
107*4882a593Smuzhiyun /* minimum h/w qdepth to be sustained to maximize aggregation */
108*4882a593Smuzhiyun #define ATH_AGGR_MIN_QDEPTH        2
109*4882a593Smuzhiyun /* minimum h/w qdepth for non-aggregated traffic */
110*4882a593Smuzhiyun #define ATH_NON_AGGR_MIN_QDEPTH    8
111*4882a593Smuzhiyun #define ATH_HW_CHECK_POLL_INT      1000
112*4882a593Smuzhiyun #define ATH_TXFIFO_DEPTH           8
113*4882a593Smuzhiyun #define ATH_TX_ERROR               0x01
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /* Stop tx traffic 1ms before the GO goes away */
116*4882a593Smuzhiyun #define ATH_P2P_PS_STOP_TIME       1000
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun #define IEEE80211_SEQ_SEQ_SHIFT    4
119*4882a593Smuzhiyun #define IEEE80211_SEQ_MAX          4096
120*4882a593Smuzhiyun #define IEEE80211_WEP_IVLEN        3
121*4882a593Smuzhiyun #define IEEE80211_WEP_KIDLEN       1
122*4882a593Smuzhiyun #define IEEE80211_WEP_CRCLEN       4
123*4882a593Smuzhiyun #define IEEE80211_MAX_MPDU_LEN     (3840 + FCS_LEN +		\
124*4882a593Smuzhiyun 				    (IEEE80211_WEP_IVLEN +	\
125*4882a593Smuzhiyun 				     IEEE80211_WEP_KIDLEN +	\
126*4882a593Smuzhiyun 				     IEEE80211_WEP_CRCLEN))
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun /* return whether a bit at index _n in bitmap _bm is set
129*4882a593Smuzhiyun  * _sz is the size of the bitmap  */
130*4882a593Smuzhiyun #define ATH_BA_ISSET(_bm, _n)  (((_n) < (WME_BA_BMP_SIZE)) &&		\
131*4882a593Smuzhiyun 				((_bm)[(_n) >> 5] & (1 << ((_n) & 31))))
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* return block-ack bitmap index given sequence and starting sequence */
134*4882a593Smuzhiyun #define ATH_BA_INDEX(_st, _seq) (((_seq) - (_st)) & (IEEE80211_SEQ_MAX - 1))
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /* return the seqno for _start + _offset */
137*4882a593Smuzhiyun #define ATH_BA_INDEX2SEQ(_seq, _offset) (((_seq) + (_offset)) & (IEEE80211_SEQ_MAX - 1))
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /* returns delimiter padding required given the packet length */
140*4882a593Smuzhiyun #define ATH_AGGR_GET_NDELIM(_len)					\
141*4882a593Smuzhiyun        (((_len) >= ATH_AGGR_MINPLEN) ? 0 :                             \
142*4882a593Smuzhiyun         DIV_ROUND_UP(ATH_AGGR_MINPLEN - (_len), ATH_AGGR_DELIM_SZ))
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun #define BAW_WITHIN(_start, _bawsz, _seqno) \
145*4882a593Smuzhiyun 	((((_seqno) - (_start)) & 4095) < (_bawsz))
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun #define ATH_AN_2_TID(_an, _tidno) ath_node_to_tid(_an, _tidno)
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun #define IS_HT_RATE(rate)   (rate & 0x80)
150*4882a593Smuzhiyun #define IS_CCK_RATE(rate)  ((rate >= 0x18) && (rate <= 0x1e))
151*4882a593Smuzhiyun #define IS_OFDM_RATE(rate) ((rate >= 0x8) && (rate <= 0xf))
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun enum {
154*4882a593Smuzhiyun        WLAN_RC_PHY_OFDM,
155*4882a593Smuzhiyun        WLAN_RC_PHY_CCK,
156*4882a593Smuzhiyun };
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun struct ath_txq {
159*4882a593Smuzhiyun 	int mac80211_qnum; /* mac80211 queue number, -1 means not mac80211 Q */
160*4882a593Smuzhiyun 	u32 axq_qnum; /* ath9k hardware queue number */
161*4882a593Smuzhiyun 	void *axq_link;
162*4882a593Smuzhiyun 	struct list_head axq_q;
163*4882a593Smuzhiyun 	spinlock_t axq_lock;
164*4882a593Smuzhiyun 	u32 axq_depth;
165*4882a593Smuzhiyun 	u32 axq_ampdu_depth;
166*4882a593Smuzhiyun 	bool axq_tx_inprogress;
167*4882a593Smuzhiyun 	struct list_head txq_fifo[ATH_TXFIFO_DEPTH];
168*4882a593Smuzhiyun 	u8 txq_headidx;
169*4882a593Smuzhiyun 	u8 txq_tailidx;
170*4882a593Smuzhiyun 	int pending_frames;
171*4882a593Smuzhiyun 	struct sk_buff_head complete_q;
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun struct ath_frame_info {
175*4882a593Smuzhiyun 	struct ath_buf *bf;
176*4882a593Smuzhiyun 	u16 framelen;
177*4882a593Smuzhiyun 	s8 txq;
178*4882a593Smuzhiyun 	u8 keyix;
179*4882a593Smuzhiyun 	u8 rtscts_rate;
180*4882a593Smuzhiyun 	u8 retries : 6;
181*4882a593Smuzhiyun 	u8 dyn_smps : 1;
182*4882a593Smuzhiyun 	u8 baw_tracked : 1;
183*4882a593Smuzhiyun 	u8 tx_power;
184*4882a593Smuzhiyun 	enum ath9k_key_type keytype:2;
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun struct ath_rxbuf {
188*4882a593Smuzhiyun 	struct list_head list;
189*4882a593Smuzhiyun 	struct sk_buff *bf_mpdu;
190*4882a593Smuzhiyun 	void *bf_desc;
191*4882a593Smuzhiyun 	dma_addr_t bf_daddr;
192*4882a593Smuzhiyun 	dma_addr_t bf_buf_addr;
193*4882a593Smuzhiyun };
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /**
196*4882a593Smuzhiyun  * enum buffer_type - Buffer type flags
197*4882a593Smuzhiyun  *
198*4882a593Smuzhiyun  * @BUF_AMPDU: This buffer is an ampdu, as part of an aggregate (during TX)
199*4882a593Smuzhiyun  * @BUF_AGGR: Indicates whether the buffer can be aggregated
200*4882a593Smuzhiyun  *	(used in aggregation scheduling)
201*4882a593Smuzhiyun  */
202*4882a593Smuzhiyun enum buffer_type {
203*4882a593Smuzhiyun 	BUF_AMPDU		= BIT(0),
204*4882a593Smuzhiyun 	BUF_AGGR		= BIT(1),
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun #define bf_isampdu(bf)		(bf->bf_state.bf_type & BUF_AMPDU)
208*4882a593Smuzhiyun #define bf_isaggr(bf)		(bf->bf_state.bf_type & BUF_AGGR)
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun struct ath_buf_state {
211*4882a593Smuzhiyun 	u8 bf_type;
212*4882a593Smuzhiyun 	u8 bfs_paprd;
213*4882a593Smuzhiyun 	u8 ndelim;
214*4882a593Smuzhiyun 	bool stale;
215*4882a593Smuzhiyun 	u16 seqno;
216*4882a593Smuzhiyun 	unsigned long bfs_paprd_timestamp;
217*4882a593Smuzhiyun };
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun struct ath_buf {
220*4882a593Smuzhiyun 	struct list_head list;
221*4882a593Smuzhiyun 	struct ath_buf *bf_lastbf;	/* last buf of this unit (a frame or
222*4882a593Smuzhiyun 					   an aggregate) */
223*4882a593Smuzhiyun 	struct ath_buf *bf_next;	/* next subframe in the aggregate */
224*4882a593Smuzhiyun 	struct sk_buff *bf_mpdu;	/* enclosing frame structure */
225*4882a593Smuzhiyun 	void *bf_desc;			/* virtual addr of desc */
226*4882a593Smuzhiyun 	dma_addr_t bf_daddr;		/* physical addr of desc */
227*4882a593Smuzhiyun 	dma_addr_t bf_buf_addr;	/* physical addr of data buffer, for DMA */
228*4882a593Smuzhiyun 	struct ieee80211_tx_rate rates[4];
229*4882a593Smuzhiyun 	struct ath_buf_state bf_state;
230*4882a593Smuzhiyun };
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun struct ath_atx_tid {
233*4882a593Smuzhiyun 	struct list_head list;
234*4882a593Smuzhiyun 	struct sk_buff_head retry_q;
235*4882a593Smuzhiyun 	struct ath_node *an;
236*4882a593Smuzhiyun 	struct ath_txq *txq;
237*4882a593Smuzhiyun 	unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];
238*4882a593Smuzhiyun 	u16 seq_start;
239*4882a593Smuzhiyun 	u16 seq_next;
240*4882a593Smuzhiyun 	u16 baw_size;
241*4882a593Smuzhiyun 	u8 tidno;
242*4882a593Smuzhiyun 	int baw_head;   /* first un-acked tx buffer */
243*4882a593Smuzhiyun 	int baw_tail;   /* next unused tx buffer slot */
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	s8 bar_index;
246*4882a593Smuzhiyun 	bool active;
247*4882a593Smuzhiyun 	bool clear_ps_filter;
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun void ath_tx_queue_tid(struct ath_softc *sc, struct ath_atx_tid *tid);
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun struct ath_node {
253*4882a593Smuzhiyun 	struct ath_softc *sc;
254*4882a593Smuzhiyun 	struct ieee80211_sta *sta; /* station struct we're part of */
255*4882a593Smuzhiyun 	struct ieee80211_vif *vif; /* interface with which we're associated */
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun 	u16 maxampdu;
258*4882a593Smuzhiyun 	u8 mpdudensity;
259*4882a593Smuzhiyun 	s8 ps_key;
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 	bool sleeping;
262*4882a593Smuzhiyun 	bool no_ps_filter;
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_STATION_STATISTICS
265*4882a593Smuzhiyun 	struct ath_rx_rate_stats rx_rate_stats;
266*4882a593Smuzhiyun #endif
267*4882a593Smuzhiyun 	u8 key_idx[4];
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 	int ackto;
270*4882a593Smuzhiyun 	struct list_head list;
271*4882a593Smuzhiyun };
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun struct ath_tx_control {
274*4882a593Smuzhiyun 	struct ath_txq *txq;
275*4882a593Smuzhiyun 	struct ath_node *an;
276*4882a593Smuzhiyun 	struct ieee80211_sta *sta;
277*4882a593Smuzhiyun 	u8 paprd;
278*4882a593Smuzhiyun };
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun /**
282*4882a593Smuzhiyun  * @txq_map:  Index is mac80211 queue number.  This is
283*4882a593Smuzhiyun  *  not necessarily the same as the hardware queue number
284*4882a593Smuzhiyun  *  (axq_qnum).
285*4882a593Smuzhiyun  */
286*4882a593Smuzhiyun struct ath_tx {
287*4882a593Smuzhiyun 	u32 txqsetup;
288*4882a593Smuzhiyun 	spinlock_t txbuflock;
289*4882a593Smuzhiyun 	struct list_head txbuf;
290*4882a593Smuzhiyun 	struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
291*4882a593Smuzhiyun 	struct ath_descdma txdma;
292*4882a593Smuzhiyun 	struct ath_txq *txq_map[IEEE80211_NUM_ACS];
293*4882a593Smuzhiyun 	struct ath_txq *uapsdq;
294*4882a593Smuzhiyun 	u16 max_aggr_framelen[IEEE80211_NUM_ACS][4][32];
295*4882a593Smuzhiyun };
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun struct ath_rx_edma {
298*4882a593Smuzhiyun 	struct sk_buff_head rx_fifo;
299*4882a593Smuzhiyun 	u32 rx_fifo_hwsize;
300*4882a593Smuzhiyun };
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun struct ath_rx {
303*4882a593Smuzhiyun 	u8 defant;
304*4882a593Smuzhiyun 	u8 rxotherant;
305*4882a593Smuzhiyun 	bool discard_next;
306*4882a593Smuzhiyun 	u32 *rxlink;
307*4882a593Smuzhiyun 	u32 num_pkts;
308*4882a593Smuzhiyun 	struct list_head rxbuf;
309*4882a593Smuzhiyun 	struct ath_descdma rxdma;
310*4882a593Smuzhiyun 	struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	struct ath_rxbuf *buf_hold;
313*4882a593Smuzhiyun 	struct sk_buff *frag;
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	u32 ampdu_ref;
316*4882a593Smuzhiyun };
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun /*******************/
319*4882a593Smuzhiyun /* Channel Context */
320*4882a593Smuzhiyun /*******************/
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun struct ath_acq {
323*4882a593Smuzhiyun 	struct list_head acq_new;
324*4882a593Smuzhiyun 	struct list_head acq_old;
325*4882a593Smuzhiyun 	spinlock_t lock;
326*4882a593Smuzhiyun };
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun struct ath_chanctx {
329*4882a593Smuzhiyun 	struct cfg80211_chan_def chandef;
330*4882a593Smuzhiyun 	struct list_head vifs;
331*4882a593Smuzhiyun 	struct ath_acq acq[IEEE80211_NUM_ACS];
332*4882a593Smuzhiyun 	int hw_queue_base;
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	/* do not dereference, use for comparison only */
335*4882a593Smuzhiyun 	struct ieee80211_vif *primary_sta;
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	struct ath_beacon_config beacon;
338*4882a593Smuzhiyun 	struct ath9k_hw_cal_data caldata;
339*4882a593Smuzhiyun 	struct timespec64 tsf_ts;
340*4882a593Smuzhiyun 	u64 tsf_val;
341*4882a593Smuzhiyun 	u32 last_beacon;
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	int flush_timeout;
344*4882a593Smuzhiyun 	u16 txpower;
345*4882a593Smuzhiyun 	u16 cur_txpower;
346*4882a593Smuzhiyun 	bool offchannel;
347*4882a593Smuzhiyun 	bool stopped;
348*4882a593Smuzhiyun 	bool active;
349*4882a593Smuzhiyun 	bool assigned;
350*4882a593Smuzhiyun 	bool switch_after_beacon;
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun 	short nvifs;
353*4882a593Smuzhiyun 	short nvifs_assigned;
354*4882a593Smuzhiyun 	unsigned int rxfilter;
355*4882a593Smuzhiyun };
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun enum ath_chanctx_event {
358*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_BEACON_PREPARE,
359*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_BEACON_SENT,
360*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_TSF_TIMER,
361*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_BEACON_RECEIVED,
362*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_AUTHORIZED,
363*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_SWITCH,
364*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_ASSIGN,
365*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_UNASSIGN,
366*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_CHANGE,
367*4882a593Smuzhiyun 	ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL,
368*4882a593Smuzhiyun };
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun enum ath_chanctx_state {
371*4882a593Smuzhiyun 	ATH_CHANCTX_STATE_IDLE,
372*4882a593Smuzhiyun 	ATH_CHANCTX_STATE_WAIT_FOR_BEACON,
373*4882a593Smuzhiyun 	ATH_CHANCTX_STATE_WAIT_FOR_TIMER,
374*4882a593Smuzhiyun 	ATH_CHANCTX_STATE_SWITCH,
375*4882a593Smuzhiyun 	ATH_CHANCTX_STATE_FORCE_ACTIVE,
376*4882a593Smuzhiyun };
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun struct ath_chanctx_sched {
379*4882a593Smuzhiyun 	bool beacon_pending;
380*4882a593Smuzhiyun 	bool beacon_adjust;
381*4882a593Smuzhiyun 	bool offchannel_pending;
382*4882a593Smuzhiyun 	bool wait_switch;
383*4882a593Smuzhiyun 	bool force_noa_update;
384*4882a593Smuzhiyun 	bool extend_absence;
385*4882a593Smuzhiyun 	bool mgd_prepare_tx;
386*4882a593Smuzhiyun 	enum ath_chanctx_state state;
387*4882a593Smuzhiyun 	u8 beacon_miss;
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	u32 next_tbtt;
390*4882a593Smuzhiyun 	u32 switch_start_time;
391*4882a593Smuzhiyun 	unsigned int offchannel_duration;
392*4882a593Smuzhiyun 	unsigned int channel_switch_time;
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun 	/* backup, in case the hardware timer fails */
395*4882a593Smuzhiyun 	struct timer_list timer;
396*4882a593Smuzhiyun };
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun enum ath_offchannel_state {
399*4882a593Smuzhiyun 	ATH_OFFCHANNEL_IDLE,
400*4882a593Smuzhiyun 	ATH_OFFCHANNEL_PROBE_SEND,
401*4882a593Smuzhiyun 	ATH_OFFCHANNEL_PROBE_WAIT,
402*4882a593Smuzhiyun 	ATH_OFFCHANNEL_SUSPEND,
403*4882a593Smuzhiyun 	ATH_OFFCHANNEL_ROC_START,
404*4882a593Smuzhiyun 	ATH_OFFCHANNEL_ROC_WAIT,
405*4882a593Smuzhiyun 	ATH_OFFCHANNEL_ROC_DONE,
406*4882a593Smuzhiyun };
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun enum ath_roc_complete_reason {
409*4882a593Smuzhiyun 	ATH_ROC_COMPLETE_EXPIRE,
410*4882a593Smuzhiyun 	ATH_ROC_COMPLETE_ABORT,
411*4882a593Smuzhiyun 	ATH_ROC_COMPLETE_CANCEL,
412*4882a593Smuzhiyun };
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun struct ath_offchannel {
415*4882a593Smuzhiyun 	struct ath_chanctx chan;
416*4882a593Smuzhiyun 	struct timer_list timer;
417*4882a593Smuzhiyun 	struct cfg80211_scan_request *scan_req;
418*4882a593Smuzhiyun 	struct ieee80211_vif *scan_vif;
419*4882a593Smuzhiyun 	int scan_idx;
420*4882a593Smuzhiyun 	enum ath_offchannel_state state;
421*4882a593Smuzhiyun 	struct ieee80211_channel *roc_chan;
422*4882a593Smuzhiyun 	struct ieee80211_vif *roc_vif;
423*4882a593Smuzhiyun 	int roc_duration;
424*4882a593Smuzhiyun 	int duration;
425*4882a593Smuzhiyun };
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun static inline struct ath_atx_tid *
ath_node_to_tid(struct ath_node * an,u8 tidno)428*4882a593Smuzhiyun ath_node_to_tid(struct ath_node *an, u8 tidno)
429*4882a593Smuzhiyun {
430*4882a593Smuzhiyun 	struct ieee80211_sta *sta = an->sta;
431*4882a593Smuzhiyun 	struct ieee80211_vif *vif = an->vif;
432*4882a593Smuzhiyun 	struct ieee80211_txq *txq;
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	BUG_ON(!vif);
435*4882a593Smuzhiyun 	if (sta)
436*4882a593Smuzhiyun 		txq = sta->txq[tidno % ARRAY_SIZE(sta->txq)];
437*4882a593Smuzhiyun 	else
438*4882a593Smuzhiyun 		txq = vif->txq;
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	return (struct ath_atx_tid *) txq->drv_priv;
441*4882a593Smuzhiyun }
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun #define case_rtn_string(val) case val: return #val
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun #define ath_for_each_chanctx(_sc, _ctx)                             \
446*4882a593Smuzhiyun 	for (ctx = &sc->chanctx[0];                                 \
447*4882a593Smuzhiyun 	     ctx <= &sc->chanctx[ARRAY_SIZE(sc->chanctx) - 1];      \
448*4882a593Smuzhiyun 	     ctx++)
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun void ath_chanctx_init(struct ath_softc *sc);
451*4882a593Smuzhiyun void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
452*4882a593Smuzhiyun 			     struct cfg80211_chan_def *chandef);
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun static inline struct ath_chanctx *
ath_chanctx_get(struct ieee80211_chanctx_conf * ctx)457*4882a593Smuzhiyun ath_chanctx_get(struct ieee80211_chanctx_conf *ctx)
458*4882a593Smuzhiyun {
459*4882a593Smuzhiyun 	struct ath_chanctx **ptr = (void *) ctx->drv_priv;
460*4882a593Smuzhiyun 	return *ptr;
461*4882a593Smuzhiyun }
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun bool ath9k_is_chanctx_enabled(void);
464*4882a593Smuzhiyun void ath9k_fill_chanctx_ops(void);
465*4882a593Smuzhiyun void ath9k_init_channel_context(struct ath_softc *sc);
466*4882a593Smuzhiyun void ath9k_offchannel_init(struct ath_softc *sc);
467*4882a593Smuzhiyun void ath9k_deinit_channel_context(struct ath_softc *sc);
468*4882a593Smuzhiyun int ath9k_init_p2p(struct ath_softc *sc);
469*4882a593Smuzhiyun void ath9k_deinit_p2p(struct ath_softc *sc);
470*4882a593Smuzhiyun void ath9k_p2p_remove_vif(struct ath_softc *sc,
471*4882a593Smuzhiyun 			  struct ieee80211_vif *vif);
472*4882a593Smuzhiyun void ath9k_p2p_beacon_sync(struct ath_softc *sc);
473*4882a593Smuzhiyun void ath9k_p2p_bss_info_changed(struct ath_softc *sc,
474*4882a593Smuzhiyun 				struct ieee80211_vif *vif);
475*4882a593Smuzhiyun void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp,
476*4882a593Smuzhiyun 			  struct sk_buff *skb);
477*4882a593Smuzhiyun void ath9k_p2p_ps_timer(void *priv);
478*4882a593Smuzhiyun void ath9k_chanctx_wake_queues(struct ath_softc *sc, struct ath_chanctx *ctx);
479*4882a593Smuzhiyun void ath9k_chanctx_stop_queues(struct ath_softc *sc, struct ath_chanctx *ctx);
480*4882a593Smuzhiyun void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx);
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun void ath_chanctx_beacon_recv_ev(struct ath_softc *sc,
483*4882a593Smuzhiyun 				enum ath_chanctx_event ev);
484*4882a593Smuzhiyun void ath_chanctx_beacon_sent_ev(struct ath_softc *sc,
485*4882a593Smuzhiyun 				enum ath_chanctx_event ev);
486*4882a593Smuzhiyun void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
487*4882a593Smuzhiyun 		       enum ath_chanctx_event ev);
488*4882a593Smuzhiyun void ath_chanctx_set_next(struct ath_softc *sc, bool force);
489*4882a593Smuzhiyun void ath_offchannel_next(struct ath_softc *sc);
490*4882a593Smuzhiyun void ath_scan_complete(struct ath_softc *sc, bool abort);
491*4882a593Smuzhiyun void ath_roc_complete(struct ath_softc *sc,
492*4882a593Smuzhiyun 		      enum ath_roc_complete_reason reason);
493*4882a593Smuzhiyun struct ath_chanctx* ath_is_go_chanctx_present(struct ath_softc *sc);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun #else
496*4882a593Smuzhiyun 
ath9k_is_chanctx_enabled(void)497*4882a593Smuzhiyun static inline bool ath9k_is_chanctx_enabled(void)
498*4882a593Smuzhiyun {
499*4882a593Smuzhiyun 	return false;
500*4882a593Smuzhiyun }
ath9k_fill_chanctx_ops(void)501*4882a593Smuzhiyun static inline void ath9k_fill_chanctx_ops(void)
502*4882a593Smuzhiyun {
503*4882a593Smuzhiyun }
ath9k_init_channel_context(struct ath_softc * sc)504*4882a593Smuzhiyun static inline void ath9k_init_channel_context(struct ath_softc *sc)
505*4882a593Smuzhiyun {
506*4882a593Smuzhiyun }
ath9k_offchannel_init(struct ath_softc * sc)507*4882a593Smuzhiyun static inline void ath9k_offchannel_init(struct ath_softc *sc)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun }
ath9k_deinit_channel_context(struct ath_softc * sc)510*4882a593Smuzhiyun static inline void ath9k_deinit_channel_context(struct ath_softc *sc)
511*4882a593Smuzhiyun {
512*4882a593Smuzhiyun }
ath_chanctx_beacon_recv_ev(struct ath_softc * sc,enum ath_chanctx_event ev)513*4882a593Smuzhiyun static inline void ath_chanctx_beacon_recv_ev(struct ath_softc *sc,
514*4882a593Smuzhiyun 					      enum ath_chanctx_event ev)
515*4882a593Smuzhiyun {
516*4882a593Smuzhiyun }
ath_chanctx_beacon_sent_ev(struct ath_softc * sc,enum ath_chanctx_event ev)517*4882a593Smuzhiyun static inline void ath_chanctx_beacon_sent_ev(struct ath_softc *sc,
518*4882a593Smuzhiyun 					      enum ath_chanctx_event ev)
519*4882a593Smuzhiyun {
520*4882a593Smuzhiyun }
ath_chanctx_event(struct ath_softc * sc,struct ieee80211_vif * vif,enum ath_chanctx_event ev)521*4882a593Smuzhiyun static inline void ath_chanctx_event(struct ath_softc *sc,
522*4882a593Smuzhiyun 				     struct ieee80211_vif *vif,
523*4882a593Smuzhiyun 				     enum ath_chanctx_event ev)
524*4882a593Smuzhiyun {
525*4882a593Smuzhiyun }
ath9k_init_p2p(struct ath_softc * sc)526*4882a593Smuzhiyun static inline int ath9k_init_p2p(struct ath_softc *sc)
527*4882a593Smuzhiyun {
528*4882a593Smuzhiyun 	return 0;
529*4882a593Smuzhiyun }
ath9k_deinit_p2p(struct ath_softc * sc)530*4882a593Smuzhiyun static inline void ath9k_deinit_p2p(struct ath_softc *sc)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun }
ath9k_p2p_remove_vif(struct ath_softc * sc,struct ieee80211_vif * vif)533*4882a593Smuzhiyun static inline void ath9k_p2p_remove_vif(struct ath_softc *sc,
534*4882a593Smuzhiyun 					struct ieee80211_vif *vif)
535*4882a593Smuzhiyun {
536*4882a593Smuzhiyun }
ath9k_p2p_beacon_sync(struct ath_softc * sc)537*4882a593Smuzhiyun static inline void ath9k_p2p_beacon_sync(struct ath_softc *sc)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun }
ath9k_p2p_bss_info_changed(struct ath_softc * sc,struct ieee80211_vif * vif)540*4882a593Smuzhiyun static inline void ath9k_p2p_bss_info_changed(struct ath_softc *sc,
541*4882a593Smuzhiyun 					      struct ieee80211_vif *vif)
542*4882a593Smuzhiyun {
543*4882a593Smuzhiyun }
ath9k_beacon_add_noa(struct ath_softc * sc,struct ath_vif * avp,struct sk_buff * skb)544*4882a593Smuzhiyun static inline void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp,
545*4882a593Smuzhiyun 					struct sk_buff *skb)
546*4882a593Smuzhiyun {
547*4882a593Smuzhiyun }
ath9k_p2p_ps_timer(struct ath_softc * sc)548*4882a593Smuzhiyun static inline void ath9k_p2p_ps_timer(struct ath_softc *sc)
549*4882a593Smuzhiyun {
550*4882a593Smuzhiyun }
ath9k_chanctx_wake_queues(struct ath_softc * sc,struct ath_chanctx * ctx)551*4882a593Smuzhiyun static inline void ath9k_chanctx_wake_queues(struct ath_softc *sc,
552*4882a593Smuzhiyun 					     struct ath_chanctx *ctx)
553*4882a593Smuzhiyun {
554*4882a593Smuzhiyun }
ath9k_chanctx_stop_queues(struct ath_softc * sc,struct ath_chanctx * ctx)555*4882a593Smuzhiyun static inline void ath9k_chanctx_stop_queues(struct ath_softc *sc,
556*4882a593Smuzhiyun 					     struct ath_chanctx *ctx)
557*4882a593Smuzhiyun {
558*4882a593Smuzhiyun }
ath_chanctx_check_active(struct ath_softc * sc,struct ath_chanctx * ctx)559*4882a593Smuzhiyun static inline void ath_chanctx_check_active(struct ath_softc *sc,
560*4882a593Smuzhiyun 					    struct ath_chanctx *ctx)
561*4882a593Smuzhiyun {
562*4882a593Smuzhiyun }
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
565*4882a593Smuzhiyun 
ath_txq_lock(struct ath_softc * sc,struct ath_txq * txq)566*4882a593Smuzhiyun static inline void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq)
567*4882a593Smuzhiyun {
568*4882a593Smuzhiyun 	spin_lock_bh(&txq->axq_lock);
569*4882a593Smuzhiyun }
ath_txq_unlock(struct ath_softc * sc,struct ath_txq * txq)570*4882a593Smuzhiyun static inline void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq)
571*4882a593Smuzhiyun {
572*4882a593Smuzhiyun 	spin_unlock_bh(&txq->axq_lock);
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun void ath_startrecv(struct ath_softc *sc);
576*4882a593Smuzhiyun bool ath_stoprecv(struct ath_softc *sc);
577*4882a593Smuzhiyun u32 ath_calcrxfilter(struct ath_softc *sc);
578*4882a593Smuzhiyun int ath_rx_init(struct ath_softc *sc, int nbufs);
579*4882a593Smuzhiyun void ath_rx_cleanup(struct ath_softc *sc);
580*4882a593Smuzhiyun int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp);
581*4882a593Smuzhiyun struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
582*4882a593Smuzhiyun void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq);
583*4882a593Smuzhiyun void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
584*4882a593Smuzhiyun bool ath_drain_all_txq(struct ath_softc *sc);
585*4882a593Smuzhiyun void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq);
586*4882a593Smuzhiyun void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an);
587*4882a593Smuzhiyun void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an);
588*4882a593Smuzhiyun void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
589*4882a593Smuzhiyun void ath_txq_schedule_all(struct ath_softc *sc);
590*4882a593Smuzhiyun int ath_tx_init(struct ath_softc *sc, int nbufs);
591*4882a593Smuzhiyun int ath_txq_update(struct ath_softc *sc, int qnum,
592*4882a593Smuzhiyun 		   struct ath9k_tx_queue_info *q);
593*4882a593Smuzhiyun u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, int pktlen,
594*4882a593Smuzhiyun 		     int width, int half_gi, bool shortPreamble);
595*4882a593Smuzhiyun void ath_update_max_aggr_framelen(struct ath_softc *sc, int queue, int txop);
596*4882a593Smuzhiyun void ath_assign_seq(struct ath_common *common, struct sk_buff *skb);
597*4882a593Smuzhiyun int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
598*4882a593Smuzhiyun 		 struct ath_tx_control *txctl);
599*4882a593Smuzhiyun void ath_tx_cabq(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
600*4882a593Smuzhiyun 		 struct sk_buff *skb);
601*4882a593Smuzhiyun void ath_tx_tasklet(struct ath_softc *sc);
602*4882a593Smuzhiyun void ath_tx_edma_tasklet(struct ath_softc *sc);
603*4882a593Smuzhiyun int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
604*4882a593Smuzhiyun 		      u16 tid, u16 *ssn);
605*4882a593Smuzhiyun void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
608*4882a593Smuzhiyun void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
609*4882a593Smuzhiyun 		       struct ath_node *an);
610*4882a593Smuzhiyun void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
611*4882a593Smuzhiyun 				   struct ieee80211_sta *sta,
612*4882a593Smuzhiyun 				   u16 tids, int nframes,
613*4882a593Smuzhiyun 				   enum ieee80211_frame_release_type reason,
614*4882a593Smuzhiyun 				   bool more_data);
615*4882a593Smuzhiyun void ath9k_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *queue);
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun /********/
618*4882a593Smuzhiyun /* VIFs */
619*4882a593Smuzhiyun /********/
620*4882a593Smuzhiyun 
621*4882a593Smuzhiyun #define P2P_DEFAULT_CTWIN 10
622*4882a593Smuzhiyun 
623*4882a593Smuzhiyun struct ath_vif {
624*4882a593Smuzhiyun 	struct list_head list;
625*4882a593Smuzhiyun 
626*4882a593Smuzhiyun 	u16 seq_no;
627*4882a593Smuzhiyun 
628*4882a593Smuzhiyun 	/* BSS info */
629*4882a593Smuzhiyun 	u8 bssid[ETH_ALEN] __aligned(2);
630*4882a593Smuzhiyun 	u16 aid;
631*4882a593Smuzhiyun 	bool assoc;
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun 	struct ieee80211_vif *vif;
634*4882a593Smuzhiyun 	struct ath_node mcast_node;
635*4882a593Smuzhiyun 	int av_bslot;
636*4882a593Smuzhiyun 	__le64 tsf_adjust; /* TSF adjustment for staggered beacons */
637*4882a593Smuzhiyun 	struct ath_buf *av_bcbuf;
638*4882a593Smuzhiyun 	struct ath_chanctx *chanctx;
639*4882a593Smuzhiyun 
640*4882a593Smuzhiyun 	/* P2P Client */
641*4882a593Smuzhiyun 	struct ieee80211_noa_data noa;
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun 	/* P2P GO */
644*4882a593Smuzhiyun 	u8 noa_index;
645*4882a593Smuzhiyun 	u32 offchannel_start;
646*4882a593Smuzhiyun 	u32 offchannel_duration;
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun 	/* These are used for both periodic and one-shot */
649*4882a593Smuzhiyun 	u32 noa_start;
650*4882a593Smuzhiyun 	u32 noa_duration;
651*4882a593Smuzhiyun 	bool periodic_noa;
652*4882a593Smuzhiyun 	bool oneshot_noa;
653*4882a593Smuzhiyun };
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun struct ath9k_vif_iter_data {
656*4882a593Smuzhiyun 	u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */
657*4882a593Smuzhiyun 	u8 mask[ETH_ALEN]; /* bssid mask */
658*4882a593Smuzhiyun 	bool has_hw_macaddr;
659*4882a593Smuzhiyun 	u8 slottime;
660*4882a593Smuzhiyun 	bool beacons;
661*4882a593Smuzhiyun 
662*4882a593Smuzhiyun 	int naps;      /* number of AP vifs */
663*4882a593Smuzhiyun 	int nmeshes;   /* number of mesh vifs */
664*4882a593Smuzhiyun 	int nstations; /* number of station vifs */
665*4882a593Smuzhiyun 	int nwds;      /* number of WDS vifs */
666*4882a593Smuzhiyun 	int nadhocs;   /* number of adhoc vifs */
667*4882a593Smuzhiyun 	int nocbs;     /* number of OCB vifs */
668*4882a593Smuzhiyun 	int nbcnvifs;  /* number of beaconing vifs */
669*4882a593Smuzhiyun 	struct ieee80211_vif *primary_beacon_vif;
670*4882a593Smuzhiyun 	struct ieee80211_vif *primary_sta;
671*4882a593Smuzhiyun };
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun void ath9k_calculate_iter_data(struct ath_softc *sc,
674*4882a593Smuzhiyun 			       struct ath_chanctx *ctx,
675*4882a593Smuzhiyun 			       struct ath9k_vif_iter_data *iter_data);
676*4882a593Smuzhiyun void ath9k_calculate_summary_state(struct ath_softc *sc,
677*4882a593Smuzhiyun 				   struct ath_chanctx *ctx);
678*4882a593Smuzhiyun void ath9k_set_txpower(struct ath_softc *sc, struct ieee80211_vif *vif);
679*4882a593Smuzhiyun 
680*4882a593Smuzhiyun /*******************/
681*4882a593Smuzhiyun /* Beacon Handling */
682*4882a593Smuzhiyun /*******************/
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun /*
685*4882a593Smuzhiyun  * Regardless of the number of beacons we stagger, (i.e. regardless of the
686*4882a593Smuzhiyun  * number of BSSIDs) if a given beacon does not go out even after waiting this
687*4882a593Smuzhiyun  * number of beacon intervals, the game's up.
688*4882a593Smuzhiyun  */
689*4882a593Smuzhiyun #define BSTUCK_THRESH           	9
690*4882a593Smuzhiyun #define	ATH_BCBUF               	8
691*4882a593Smuzhiyun #define ATH_DEFAULT_BINTVAL     	100 /* TU */
692*4882a593Smuzhiyun #define ATH_DEFAULT_BMISS_LIMIT 	10
693*4882a593Smuzhiyun 
694*4882a593Smuzhiyun #define TSF_TO_TU(_h,_l) \
695*4882a593Smuzhiyun 	((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun struct ath_beacon {
698*4882a593Smuzhiyun 	enum {
699*4882a593Smuzhiyun 		OK,		/* no change needed */
700*4882a593Smuzhiyun 		UPDATE,		/* update pending */
701*4882a593Smuzhiyun 		COMMIT		/* beacon sent, commit change */
702*4882a593Smuzhiyun 	} updateslot;		/* slot time update fsm */
703*4882a593Smuzhiyun 
704*4882a593Smuzhiyun 	u32 beaconq;
705*4882a593Smuzhiyun 	u32 bmisscnt;
706*4882a593Smuzhiyun 	struct ieee80211_vif *bslot[ATH_BCBUF];
707*4882a593Smuzhiyun 	int slottime;
708*4882a593Smuzhiyun 	int slotupdate;
709*4882a593Smuzhiyun 	struct ath_descdma bdma;
710*4882a593Smuzhiyun 	struct ath_txq *cabq;
711*4882a593Smuzhiyun 	struct list_head bbuf;
712*4882a593Smuzhiyun 
713*4882a593Smuzhiyun 	bool tx_processed;
714*4882a593Smuzhiyun 	bool tx_last;
715*4882a593Smuzhiyun };
716*4882a593Smuzhiyun 
717*4882a593Smuzhiyun void ath9k_beacon_tasklet(struct tasklet_struct *t);
718*4882a593Smuzhiyun void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *main_vif,
719*4882a593Smuzhiyun 			 bool beacons);
720*4882a593Smuzhiyun void ath9k_beacon_assign_slot(struct ath_softc *sc, struct ieee80211_vif *vif);
721*4882a593Smuzhiyun void ath9k_beacon_remove_slot(struct ath_softc *sc, struct ieee80211_vif *vif);
722*4882a593Smuzhiyun void ath9k_beacon_ensure_primary_slot(struct ath_softc *sc);
723*4882a593Smuzhiyun void ath9k_set_beacon(struct ath_softc *sc);
724*4882a593Smuzhiyun bool ath9k_csa_is_finished(struct ath_softc *sc, struct ieee80211_vif *vif);
725*4882a593Smuzhiyun void ath9k_csa_update(struct ath_softc *sc);
726*4882a593Smuzhiyun 
727*4882a593Smuzhiyun /*******************/
728*4882a593Smuzhiyun /* Link Monitoring */
729*4882a593Smuzhiyun /*******************/
730*4882a593Smuzhiyun 
731*4882a593Smuzhiyun #define ATH_STA_SHORT_CALINTERVAL 1000    /* 1 second */
732*4882a593Smuzhiyun #define ATH_AP_SHORT_CALINTERVAL  100     /* 100 ms */
733*4882a593Smuzhiyun #define ATH_ANI_POLLINTERVAL_OLD  100     /* 100 ms */
734*4882a593Smuzhiyun #define ATH_ANI_POLLINTERVAL_NEW  1000    /* 1000 ms */
735*4882a593Smuzhiyun #define ATH_LONG_CALINTERVAL_INT  1000    /* 1000 ms */
736*4882a593Smuzhiyun #define ATH_LONG_CALINTERVAL      30000   /* 30 seconds */
737*4882a593Smuzhiyun #define ATH_RESTART_CALINTERVAL   1200000 /* 20 minutes */
738*4882a593Smuzhiyun #define ATH_ANI_MAX_SKIP_COUNT    10
739*4882a593Smuzhiyun #define ATH_PAPRD_TIMEOUT         100 /* msecs */
740*4882a593Smuzhiyun #define ATH_PLL_WORK_INTERVAL     100
741*4882a593Smuzhiyun 
742*4882a593Smuzhiyun void ath_hw_check_work(struct work_struct *work);
743*4882a593Smuzhiyun void ath_reset_work(struct work_struct *work);
744*4882a593Smuzhiyun bool ath_hw_check(struct ath_softc *sc);
745*4882a593Smuzhiyun void ath_hw_pll_work(struct work_struct *work);
746*4882a593Smuzhiyun void ath_paprd_calibrate(struct work_struct *work);
747*4882a593Smuzhiyun void ath_ani_calibrate(struct timer_list *t);
748*4882a593Smuzhiyun void ath_start_ani(struct ath_softc *sc);
749*4882a593Smuzhiyun void ath_stop_ani(struct ath_softc *sc);
750*4882a593Smuzhiyun void ath_check_ani(struct ath_softc *sc);
751*4882a593Smuzhiyun int ath_update_survey_stats(struct ath_softc *sc);
752*4882a593Smuzhiyun void ath_update_survey_nf(struct ath_softc *sc, int channel);
753*4882a593Smuzhiyun void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
754*4882a593Smuzhiyun void ath_ps_full_sleep(struct timer_list *t);
755*4882a593Smuzhiyun void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop,
756*4882a593Smuzhiyun 		   bool sw_pending, bool timeout_override);
757*4882a593Smuzhiyun 
758*4882a593Smuzhiyun /**********/
759*4882a593Smuzhiyun /* BTCOEX */
760*4882a593Smuzhiyun /**********/
761*4882a593Smuzhiyun 
762*4882a593Smuzhiyun #define ATH_DUMP_BTCOEX(_s, _val)				\
763*4882a593Smuzhiyun 	do {							\
764*4882a593Smuzhiyun 		len += scnprintf(buf + len, size - len,		\
765*4882a593Smuzhiyun 				 "%20s : %10d\n", _s, (_val));	\
766*4882a593Smuzhiyun 	} while (0)
767*4882a593Smuzhiyun 
768*4882a593Smuzhiyun enum bt_op_flags {
769*4882a593Smuzhiyun 	BT_OP_PRIORITY_DETECTED,
770*4882a593Smuzhiyun 	BT_OP_SCAN,
771*4882a593Smuzhiyun };
772*4882a593Smuzhiyun 
773*4882a593Smuzhiyun struct ath_btcoex {
774*4882a593Smuzhiyun 	spinlock_t btcoex_lock;
775*4882a593Smuzhiyun 	struct timer_list period_timer; /* Timer for BT period */
776*4882a593Smuzhiyun 	struct timer_list no_stomp_timer;
777*4882a593Smuzhiyun 	u32 bt_priority_cnt;
778*4882a593Smuzhiyun 	unsigned long bt_priority_time;
779*4882a593Smuzhiyun 	unsigned long op_flags;
780*4882a593Smuzhiyun 	int bt_stomp_type; /* Types of BT stomping */
781*4882a593Smuzhiyun 	u32 btcoex_no_stomp; /* in msec */
782*4882a593Smuzhiyun 	u32 btcoex_period; /* in msec */
783*4882a593Smuzhiyun 	u32 btscan_no_stomp; /* in msec */
784*4882a593Smuzhiyun 	u32 duty_cycle;
785*4882a593Smuzhiyun 	u32 bt_wait_time;
786*4882a593Smuzhiyun 	int rssi_count;
787*4882a593Smuzhiyun 	struct ath_mci_profile mci;
788*4882a593Smuzhiyun 	u8 stomp_audio;
789*4882a593Smuzhiyun };
790*4882a593Smuzhiyun 
791*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
792*4882a593Smuzhiyun int ath9k_init_btcoex(struct ath_softc *sc);
793*4882a593Smuzhiyun void ath9k_deinit_btcoex(struct ath_softc *sc);
794*4882a593Smuzhiyun void ath9k_start_btcoex(struct ath_softc *sc);
795*4882a593Smuzhiyun void ath9k_stop_btcoex(struct ath_softc *sc);
796*4882a593Smuzhiyun void ath9k_btcoex_timer_resume(struct ath_softc *sc);
797*4882a593Smuzhiyun void ath9k_btcoex_timer_pause(struct ath_softc *sc);
798*4882a593Smuzhiyun void ath9k_btcoex_handle_interrupt(struct ath_softc *sc, u32 status);
799*4882a593Smuzhiyun u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc, u32 max_4ms_framelen);
800*4882a593Smuzhiyun void ath9k_btcoex_stop_gen_timer(struct ath_softc *sc);
801*4882a593Smuzhiyun int ath9k_dump_btcoex(struct ath_softc *sc, u8 *buf, u32 size);
802*4882a593Smuzhiyun #else
ath9k_init_btcoex(struct ath_softc * sc)803*4882a593Smuzhiyun static inline int ath9k_init_btcoex(struct ath_softc *sc)
804*4882a593Smuzhiyun {
805*4882a593Smuzhiyun 	return 0;
806*4882a593Smuzhiyun }
ath9k_deinit_btcoex(struct ath_softc * sc)807*4882a593Smuzhiyun static inline void ath9k_deinit_btcoex(struct ath_softc *sc)
808*4882a593Smuzhiyun {
809*4882a593Smuzhiyun }
ath9k_start_btcoex(struct ath_softc * sc)810*4882a593Smuzhiyun static inline void ath9k_start_btcoex(struct ath_softc *sc)
811*4882a593Smuzhiyun {
812*4882a593Smuzhiyun }
ath9k_stop_btcoex(struct ath_softc * sc)813*4882a593Smuzhiyun static inline void ath9k_stop_btcoex(struct ath_softc *sc)
814*4882a593Smuzhiyun {
815*4882a593Smuzhiyun }
ath9k_btcoex_handle_interrupt(struct ath_softc * sc,u32 status)816*4882a593Smuzhiyun static inline void ath9k_btcoex_handle_interrupt(struct ath_softc *sc,
817*4882a593Smuzhiyun 						 u32 status)
818*4882a593Smuzhiyun {
819*4882a593Smuzhiyun }
ath9k_btcoex_aggr_limit(struct ath_softc * sc,u32 max_4ms_framelen)820*4882a593Smuzhiyun static inline u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc,
821*4882a593Smuzhiyun 					  u32 max_4ms_framelen)
822*4882a593Smuzhiyun {
823*4882a593Smuzhiyun 	return 0;
824*4882a593Smuzhiyun }
ath9k_btcoex_stop_gen_timer(struct ath_softc * sc)825*4882a593Smuzhiyun static inline void ath9k_btcoex_stop_gen_timer(struct ath_softc *sc)
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun }
ath9k_dump_btcoex(struct ath_softc * sc,u8 * buf,u32 size)828*4882a593Smuzhiyun static inline int ath9k_dump_btcoex(struct ath_softc *sc, u8 *buf, u32 size)
829*4882a593Smuzhiyun {
830*4882a593Smuzhiyun 	return 0;
831*4882a593Smuzhiyun }
832*4882a593Smuzhiyun #endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
833*4882a593Smuzhiyun 
834*4882a593Smuzhiyun /********************/
835*4882a593Smuzhiyun /*   LED Control    */
836*4882a593Smuzhiyun /********************/
837*4882a593Smuzhiyun 
838*4882a593Smuzhiyun #define ATH_LED_PIN_DEF 		1
839*4882a593Smuzhiyun #define ATH_LED_PIN_9287		8
840*4882a593Smuzhiyun #define ATH_LED_PIN_9300		10
841*4882a593Smuzhiyun #define ATH_LED_PIN_9485		6
842*4882a593Smuzhiyun #define ATH_LED_PIN_9462		4
843*4882a593Smuzhiyun 
844*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_LEDS
845*4882a593Smuzhiyun void ath_init_leds(struct ath_softc *sc);
846*4882a593Smuzhiyun void ath_deinit_leds(struct ath_softc *sc);
847*4882a593Smuzhiyun #else
ath_init_leds(struct ath_softc * sc)848*4882a593Smuzhiyun static inline void ath_init_leds(struct ath_softc *sc)
849*4882a593Smuzhiyun {
850*4882a593Smuzhiyun }
851*4882a593Smuzhiyun 
ath_deinit_leds(struct ath_softc * sc)852*4882a593Smuzhiyun static inline void ath_deinit_leds(struct ath_softc *sc)
853*4882a593Smuzhiyun {
854*4882a593Smuzhiyun }
855*4882a593Smuzhiyun #endif
856*4882a593Smuzhiyun 
857*4882a593Smuzhiyun /************************/
858*4882a593Smuzhiyun /* Wake on Wireless LAN */
859*4882a593Smuzhiyun /************************/
860*4882a593Smuzhiyun 
861*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_WOW
862*4882a593Smuzhiyun void ath9k_init_wow(struct ieee80211_hw *hw);
863*4882a593Smuzhiyun void ath9k_deinit_wow(struct ieee80211_hw *hw);
864*4882a593Smuzhiyun int ath9k_suspend(struct ieee80211_hw *hw,
865*4882a593Smuzhiyun 		  struct cfg80211_wowlan *wowlan);
866*4882a593Smuzhiyun int ath9k_resume(struct ieee80211_hw *hw);
867*4882a593Smuzhiyun void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled);
868*4882a593Smuzhiyun #else
ath9k_init_wow(struct ieee80211_hw * hw)869*4882a593Smuzhiyun static inline void ath9k_init_wow(struct ieee80211_hw *hw)
870*4882a593Smuzhiyun {
871*4882a593Smuzhiyun }
ath9k_deinit_wow(struct ieee80211_hw * hw)872*4882a593Smuzhiyun static inline void ath9k_deinit_wow(struct ieee80211_hw *hw)
873*4882a593Smuzhiyun {
874*4882a593Smuzhiyun }
ath9k_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)875*4882a593Smuzhiyun static inline int ath9k_suspend(struct ieee80211_hw *hw,
876*4882a593Smuzhiyun 				struct cfg80211_wowlan *wowlan)
877*4882a593Smuzhiyun {
878*4882a593Smuzhiyun 	return 0;
879*4882a593Smuzhiyun }
ath9k_resume(struct ieee80211_hw * hw)880*4882a593Smuzhiyun static inline int ath9k_resume(struct ieee80211_hw *hw)
881*4882a593Smuzhiyun {
882*4882a593Smuzhiyun 	return 0;
883*4882a593Smuzhiyun }
ath9k_set_wakeup(struct ieee80211_hw * hw,bool enabled)884*4882a593Smuzhiyun static inline void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
885*4882a593Smuzhiyun {
886*4882a593Smuzhiyun }
887*4882a593Smuzhiyun #endif /* CONFIG_ATH9K_WOW */
888*4882a593Smuzhiyun 
889*4882a593Smuzhiyun /*******************************/
890*4882a593Smuzhiyun /* Antenna diversity/combining */
891*4882a593Smuzhiyun /*******************************/
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun #define ATH_ANT_RX_CURRENT_SHIFT 4
894*4882a593Smuzhiyun #define ATH_ANT_RX_MAIN_SHIFT 2
895*4882a593Smuzhiyun #define ATH_ANT_RX_MASK 0x3
896*4882a593Smuzhiyun 
897*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_SHORT_SCAN_INTR 50
898*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT 0x100
899*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_MAX_PKTCOUNT 0x200
900*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_INIT_COUNT 95
901*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_MAX_COUNT 100
902*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO 30
903*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2 20
904*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI 50
905*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI 50
906*4882a593Smuzhiyun 
907*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_LNA1_DELTA_HI -4
908*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_LNA1_DELTA_MID -2
909*4882a593Smuzhiyun #define ATH_ANT_DIV_COMB_LNA1_DELTA_LOW 2
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun struct ath_ant_comb {
912*4882a593Smuzhiyun 	u16 count;
913*4882a593Smuzhiyun 	u16 total_pkt_count;
914*4882a593Smuzhiyun 	bool scan;
915*4882a593Smuzhiyun 	bool scan_not_start;
916*4882a593Smuzhiyun 	int main_total_rssi;
917*4882a593Smuzhiyun 	int alt_total_rssi;
918*4882a593Smuzhiyun 	int alt_recv_cnt;
919*4882a593Smuzhiyun 	int main_recv_cnt;
920*4882a593Smuzhiyun 	int rssi_lna1;
921*4882a593Smuzhiyun 	int rssi_lna2;
922*4882a593Smuzhiyun 	int rssi_add;
923*4882a593Smuzhiyun 	int rssi_sub;
924*4882a593Smuzhiyun 	int rssi_first;
925*4882a593Smuzhiyun 	int rssi_second;
926*4882a593Smuzhiyun 	int rssi_third;
927*4882a593Smuzhiyun 	int ant_ratio;
928*4882a593Smuzhiyun 	int ant_ratio2;
929*4882a593Smuzhiyun 	bool alt_good;
930*4882a593Smuzhiyun 	int quick_scan_cnt;
931*4882a593Smuzhiyun 	enum ath9k_ant_div_comb_lna_conf main_conf;
932*4882a593Smuzhiyun 	enum ath9k_ant_div_comb_lna_conf first_quick_scan_conf;
933*4882a593Smuzhiyun 	enum ath9k_ant_div_comb_lna_conf second_quick_scan_conf;
934*4882a593Smuzhiyun 	bool first_ratio;
935*4882a593Smuzhiyun 	bool second_ratio;
936*4882a593Smuzhiyun 	unsigned long scan_start_time;
937*4882a593Smuzhiyun 
938*4882a593Smuzhiyun 	/*
939*4882a593Smuzhiyun 	 * Card-specific config values.
940*4882a593Smuzhiyun 	 */
941*4882a593Smuzhiyun 	int low_rssi_thresh;
942*4882a593Smuzhiyun 	int fast_div_bias;
943*4882a593Smuzhiyun };
944*4882a593Smuzhiyun 
945*4882a593Smuzhiyun void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun /********************/
948*4882a593Smuzhiyun /* Main driver core */
949*4882a593Smuzhiyun /********************/
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun #define ATH9K_PCI_CUS198          0x0001
952*4882a593Smuzhiyun #define ATH9K_PCI_CUS230          0x0002
953*4882a593Smuzhiyun #define ATH9K_PCI_CUS217          0x0004
954*4882a593Smuzhiyun #define ATH9K_PCI_CUS252          0x0008
955*4882a593Smuzhiyun #define ATH9K_PCI_WOW             0x0010
956*4882a593Smuzhiyun #define ATH9K_PCI_BT_ANT_DIV      0x0020
957*4882a593Smuzhiyun #define ATH9K_PCI_D3_L1_WAR       0x0040
958*4882a593Smuzhiyun #define ATH9K_PCI_AR9565_1ANT     0x0080
959*4882a593Smuzhiyun #define ATH9K_PCI_AR9565_2ANT     0x0100
960*4882a593Smuzhiyun #define ATH9K_PCI_NO_PLL_PWRSAVE  0x0200
961*4882a593Smuzhiyun #define ATH9K_PCI_KILLER          0x0400
962*4882a593Smuzhiyun #define ATH9K_PCI_LED_ACT_HI      0x0800
963*4882a593Smuzhiyun 
964*4882a593Smuzhiyun /*
965*4882a593Smuzhiyun  * Default cache line size, in bytes.
966*4882a593Smuzhiyun  * Used when PCI device not fully initialized by bootrom/BIOS
967*4882a593Smuzhiyun */
968*4882a593Smuzhiyun #define DEFAULT_CACHELINE       32
969*4882a593Smuzhiyun #define ATH_CABQ_READY_TIME     80      /* % of beacon interval */
970*4882a593Smuzhiyun #define ATH_TXPOWER_MAX         100     /* .5 dBm units */
971*4882a593Smuzhiyun #define MAX_GTT_CNT             5
972*4882a593Smuzhiyun 
973*4882a593Smuzhiyun /* Powersave flags */
974*4882a593Smuzhiyun #define PS_WAIT_FOR_BEACON        BIT(0)
975*4882a593Smuzhiyun #define PS_WAIT_FOR_CAB           BIT(1)
976*4882a593Smuzhiyun #define PS_WAIT_FOR_PSPOLL_DATA   BIT(2)
977*4882a593Smuzhiyun #define PS_WAIT_FOR_TX_ACK        BIT(3)
978*4882a593Smuzhiyun #define PS_BEACON_SYNC            BIT(4)
979*4882a593Smuzhiyun #define PS_WAIT_FOR_ANI           BIT(5)
980*4882a593Smuzhiyun 
981*4882a593Smuzhiyun #define ATH9K_NUM_CHANCTX  2 /* supports 2 operating channels */
982*4882a593Smuzhiyun 
983*4882a593Smuzhiyun struct ath_softc {
984*4882a593Smuzhiyun 	struct ieee80211_hw *hw;
985*4882a593Smuzhiyun 	struct device *dev;
986*4882a593Smuzhiyun 
987*4882a593Smuzhiyun 	struct survey_info *cur_survey;
988*4882a593Smuzhiyun 	struct survey_info survey[ATH9K_NUM_CHANNELS];
989*4882a593Smuzhiyun 
990*4882a593Smuzhiyun 	spinlock_t intr_lock;
991*4882a593Smuzhiyun 	struct tasklet_struct intr_tq;
992*4882a593Smuzhiyun 	struct tasklet_struct bcon_tasklet;
993*4882a593Smuzhiyun 	struct ath_hw *sc_ah;
994*4882a593Smuzhiyun 	void __iomem *mem;
995*4882a593Smuzhiyun 	int irq;
996*4882a593Smuzhiyun 	spinlock_t sc_serial_rw;
997*4882a593Smuzhiyun 	spinlock_t sc_pm_lock;
998*4882a593Smuzhiyun 	spinlock_t sc_pcu_lock;
999*4882a593Smuzhiyun 	struct mutex mutex;
1000*4882a593Smuzhiyun 	struct work_struct paprd_work;
1001*4882a593Smuzhiyun 	struct work_struct hw_reset_work;
1002*4882a593Smuzhiyun 	struct completion paprd_complete;
1003*4882a593Smuzhiyun 	wait_queue_head_t tx_wait;
1004*4882a593Smuzhiyun 
1005*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
1006*4882a593Smuzhiyun 	struct work_struct chanctx_work;
1007*4882a593Smuzhiyun 	struct ath_gen_timer *p2p_ps_timer;
1008*4882a593Smuzhiyun 	struct ath_vif *p2p_ps_vif;
1009*4882a593Smuzhiyun 	struct ath_chanctx_sched sched;
1010*4882a593Smuzhiyun 	struct ath_offchannel offchannel;
1011*4882a593Smuzhiyun 	struct ath_chanctx *next_chan;
1012*4882a593Smuzhiyun 	struct completion go_beacon;
1013*4882a593Smuzhiyun 	struct timespec64 last_event_time;
1014*4882a593Smuzhiyun #endif
1015*4882a593Smuzhiyun 
1016*4882a593Smuzhiyun 	unsigned long driver_data;
1017*4882a593Smuzhiyun 
1018*4882a593Smuzhiyun 	u8 gtt_cnt;
1019*4882a593Smuzhiyun 	u32 intrstatus;
1020*4882a593Smuzhiyun 	u16 ps_flags; /* PS_* */
1021*4882a593Smuzhiyun 	bool ps_enabled;
1022*4882a593Smuzhiyun 	bool ps_idle;
1023*4882a593Smuzhiyun 	short nbcnvifs;
1024*4882a593Smuzhiyun 	unsigned long ps_usecount;
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun 	struct ath_rx rx;
1027*4882a593Smuzhiyun 	struct ath_tx tx;
1028*4882a593Smuzhiyun 	struct ath_beacon beacon;
1029*4882a593Smuzhiyun 
1030*4882a593Smuzhiyun 	struct cfg80211_chan_def cur_chandef;
1031*4882a593Smuzhiyun 	struct ath_chanctx chanctx[ATH9K_NUM_CHANCTX];
1032*4882a593Smuzhiyun 	struct ath_chanctx *cur_chan;
1033*4882a593Smuzhiyun 	spinlock_t chan_lock;
1034*4882a593Smuzhiyun 
1035*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_LEDS
1036*4882a593Smuzhiyun 	bool led_registered;
1037*4882a593Smuzhiyun 	char led_name[32];
1038*4882a593Smuzhiyun 	struct led_classdev led_cdev;
1039*4882a593Smuzhiyun #endif
1040*4882a593Smuzhiyun 
1041*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_DEBUGFS
1042*4882a593Smuzhiyun 	struct ath9k_debug debug;
1043*4882a593Smuzhiyun #endif
1044*4882a593Smuzhiyun 	struct delayed_work hw_check_work;
1045*4882a593Smuzhiyun 	struct delayed_work hw_pll_work;
1046*4882a593Smuzhiyun 	struct timer_list sleep_timer;
1047*4882a593Smuzhiyun 
1048*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1049*4882a593Smuzhiyun 	struct ath_btcoex btcoex;
1050*4882a593Smuzhiyun 	struct ath_mci_coex mci_coex;
1051*4882a593Smuzhiyun 	struct work_struct mci_work;
1052*4882a593Smuzhiyun #endif
1053*4882a593Smuzhiyun 
1054*4882a593Smuzhiyun 	struct ath_descdma txsdma;
1055*4882a593Smuzhiyun 
1056*4882a593Smuzhiyun 	struct ath_ant_comb ant_comb;
1057*4882a593Smuzhiyun 	u8 ant_tx, ant_rx;
1058*4882a593Smuzhiyun 	struct dfs_pattern_detector *dfs_detector;
1059*4882a593Smuzhiyun 	u64 dfs_prev_pulse_ts;
1060*4882a593Smuzhiyun 	u32 wow_enabled;
1061*4882a593Smuzhiyun 
1062*4882a593Smuzhiyun 	struct ath_spec_scan_priv spec_priv;
1063*4882a593Smuzhiyun 
1064*4882a593Smuzhiyun 	struct ieee80211_vif *tx99_vif;
1065*4882a593Smuzhiyun 	struct sk_buff *tx99_skb;
1066*4882a593Smuzhiyun 	bool tx99_state;
1067*4882a593Smuzhiyun 	s16 tx99_power;
1068*4882a593Smuzhiyun 
1069*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_WOW
1070*4882a593Smuzhiyun 	u32 wow_intr_before_sleep;
1071*4882a593Smuzhiyun 	bool force_wow;
1072*4882a593Smuzhiyun #endif
1073*4882a593Smuzhiyun 
1074*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_HWRNG
1075*4882a593Smuzhiyun 	u32 rng_last;
1076*4882a593Smuzhiyun 	struct task_struct *rng_task;
1077*4882a593Smuzhiyun #endif
1078*4882a593Smuzhiyun };
1079*4882a593Smuzhiyun 
1080*4882a593Smuzhiyun /********/
1081*4882a593Smuzhiyun /* TX99 */
1082*4882a593Smuzhiyun /********/
1083*4882a593Smuzhiyun 
1084*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_TX99
1085*4882a593Smuzhiyun void ath9k_tx99_init_debug(struct ath_softc *sc);
1086*4882a593Smuzhiyun int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
1087*4882a593Smuzhiyun 		    struct ath_tx_control *txctl);
1088*4882a593Smuzhiyun #else
ath9k_tx99_init_debug(struct ath_softc * sc)1089*4882a593Smuzhiyun static inline void ath9k_tx99_init_debug(struct ath_softc *sc)
1090*4882a593Smuzhiyun {
1091*4882a593Smuzhiyun }
ath9k_tx99_send(struct ath_softc * sc,struct sk_buff * skb,struct ath_tx_control * txctl)1092*4882a593Smuzhiyun static inline int ath9k_tx99_send(struct ath_softc *sc,
1093*4882a593Smuzhiyun 				  struct sk_buff *skb,
1094*4882a593Smuzhiyun 				  struct ath_tx_control *txctl)
1095*4882a593Smuzhiyun {
1096*4882a593Smuzhiyun 	return 0;
1097*4882a593Smuzhiyun }
1098*4882a593Smuzhiyun #endif /* CONFIG_ATH9K_TX99 */
1099*4882a593Smuzhiyun 
1100*4882a593Smuzhiyun /***************************/
1101*4882a593Smuzhiyun /* Random Number Generator */
1102*4882a593Smuzhiyun /***************************/
1103*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_HWRNG
1104*4882a593Smuzhiyun void ath9k_rng_start(struct ath_softc *sc);
1105*4882a593Smuzhiyun void ath9k_rng_stop(struct ath_softc *sc);
1106*4882a593Smuzhiyun #else
ath9k_rng_start(struct ath_softc * sc)1107*4882a593Smuzhiyun static inline void ath9k_rng_start(struct ath_softc *sc)
1108*4882a593Smuzhiyun {
1109*4882a593Smuzhiyun }
1110*4882a593Smuzhiyun 
ath9k_rng_stop(struct ath_softc * sc)1111*4882a593Smuzhiyun static inline void ath9k_rng_stop(struct ath_softc *sc)
1112*4882a593Smuzhiyun {
1113*4882a593Smuzhiyun }
1114*4882a593Smuzhiyun #endif
1115*4882a593Smuzhiyun 
ath_read_cachesize(struct ath_common * common,int * csz)1116*4882a593Smuzhiyun static inline void ath_read_cachesize(struct ath_common *common, int *csz)
1117*4882a593Smuzhiyun {
1118*4882a593Smuzhiyun 	common->bus_ops->read_cachesize(common, csz);
1119*4882a593Smuzhiyun }
1120*4882a593Smuzhiyun 
1121*4882a593Smuzhiyun void ath9k_tasklet(struct tasklet_struct *t);
1122*4882a593Smuzhiyun int ath_cabq_update(struct ath_softc *);
1123*4882a593Smuzhiyun u8 ath9k_parse_mpdudensity(u8 mpdudensity);
1124*4882a593Smuzhiyun irqreturn_t ath_isr(int irq, void *dev);
1125*4882a593Smuzhiyun int ath_reset(struct ath_softc *sc, struct ath9k_channel *hchan);
1126*4882a593Smuzhiyun void ath_cancel_work(struct ath_softc *sc);
1127*4882a593Smuzhiyun void ath_restart_work(struct ath_softc *sc);
1128*4882a593Smuzhiyun int ath9k_init_device(u16 devid, struct ath_softc *sc,
1129*4882a593Smuzhiyun 		    const struct ath_bus_ops *bus_ops);
1130*4882a593Smuzhiyun void ath9k_deinit_device(struct ath_softc *sc);
1131*4882a593Smuzhiyun void ath9k_reload_chainmask_settings(struct ath_softc *sc);
1132*4882a593Smuzhiyun u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate);
1133*4882a593Smuzhiyun void ath_start_rfkill_poll(struct ath_softc *sc);
1134*4882a593Smuzhiyun void ath9k_rfkill_poll_state(struct ieee80211_hw *hw);
1135*4882a593Smuzhiyun void ath9k_ps_wakeup(struct ath_softc *sc);
1136*4882a593Smuzhiyun void ath9k_ps_restore(struct ath_softc *sc);
1137*4882a593Smuzhiyun 
1138*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_PCI
1139*4882a593Smuzhiyun int ath_pci_init(void);
1140*4882a593Smuzhiyun void ath_pci_exit(void);
1141*4882a593Smuzhiyun #else
ath_pci_init(void)1142*4882a593Smuzhiyun static inline int ath_pci_init(void) { return 0; };
ath_pci_exit(void)1143*4882a593Smuzhiyun static inline void ath_pci_exit(void) {};
1144*4882a593Smuzhiyun #endif
1145*4882a593Smuzhiyun 
1146*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_AHB
1147*4882a593Smuzhiyun int ath_ahb_init(void);
1148*4882a593Smuzhiyun void ath_ahb_exit(void);
1149*4882a593Smuzhiyun #else
ath_ahb_init(void)1150*4882a593Smuzhiyun static inline int ath_ahb_init(void) { return 0; };
ath_ahb_exit(void)1151*4882a593Smuzhiyun static inline void ath_ahb_exit(void) {};
1152*4882a593Smuzhiyun #endif
1153*4882a593Smuzhiyun 
1154*4882a593Smuzhiyun #endif /* ATH9K_H */
1155