xref: /illumos-gate/usr/src/uts/common/io/arn/arn_core.h (revision a3ccee74)
1dd1de374Slin wang - Sun Microsystems - Beijing China /*
2c0c93480Slin wang - Sun Microsystems - Beijing China  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
3dd1de374Slin wang - Sun Microsystems - Beijing China  * Use is subject to license terms.
4dd1de374Slin wang - Sun Microsystems - Beijing China  */
5dd1de374Slin wang - Sun Microsystems - Beijing China 
6dd1de374Slin wang - Sun Microsystems - Beijing China /*
7dd1de374Slin wang - Sun Microsystems - Beijing China  * Copyright (c) 2008 Atheros Communications Inc.
8dd1de374Slin wang - Sun Microsystems - Beijing China  *
9dd1de374Slin wang - Sun Microsystems - Beijing China  * Permission to use, copy, modify, and/or distribute this software for any
10dd1de374Slin wang - Sun Microsystems - Beijing China  * purpose with or without fee is hereby granted, provided that the above
11dd1de374Slin wang - Sun Microsystems - Beijing China  * copyright notice and this permission notice appear in all copies.
12dd1de374Slin wang - Sun Microsystems - Beijing China  *
13dd1de374Slin wang - Sun Microsystems - Beijing China  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14dd1de374Slin wang - Sun Microsystems - Beijing China  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15dd1de374Slin wang - Sun Microsystems - Beijing China  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16dd1de374Slin wang - Sun Microsystems - Beijing China  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17dd1de374Slin wang - Sun Microsystems - Beijing China  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18dd1de374Slin wang - Sun Microsystems - Beijing China  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19dd1de374Slin wang - Sun Microsystems - Beijing China  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20dd1de374Slin wang - Sun Microsystems - Beijing China  */
21dd1de374Slin wang - Sun Microsystems - Beijing China 
22dd1de374Slin wang - Sun Microsystems - Beijing China #ifndef _ARN_CORE_H
23dd1de374Slin wang - Sun Microsystems - Beijing China #define	_ARN_CORE_H
24dd1de374Slin wang - Sun Microsystems - Beijing China 
25dd1de374Slin wang - Sun Microsystems - Beijing China #ifdef __cplusplus
26dd1de374Slin wang - Sun Microsystems - Beijing China extern "C" {
27dd1de374Slin wang - Sun Microsystems - Beijing China #endif
28dd1de374Slin wang - Sun Microsystems - Beijing China 
29dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/note.h>
30dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/list.h>
31dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/net80211.h>
32dd1de374Slin wang - Sun Microsystems - Beijing China 
33dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_ath9k.h"
34dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_rc.h"
35dd1de374Slin wang - Sun Microsystems - Beijing China 
36dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_node;
37dd1de374Slin wang - Sun Microsystems - Beijing China 
38dd1de374Slin wang - Sun Microsystems - Beijing China /*
39dd1de374Slin wang - Sun Microsystems - Beijing China  * Node type of wifi device
40dd1de374Slin wang - Sun Microsystems - Beijing China  */
41dd1de374Slin wang - Sun Microsystems - Beijing China #ifndef DDI_NT_NET_WIFI
42dd1de374Slin wang - Sun Microsystems - Beijing China #define	DDI_NT_NET_WIFI	"ddi_network:wifi"
43dd1de374Slin wang - Sun Microsystems - Beijing China #endif
44dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_NODENAME	"arn"
45dd1de374Slin wang - Sun Microsystems - Beijing China 
46dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_LOCK(_sc)		mutex_enter(&(_sc)->sc_genlock)
47dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_UNLOCK(_sc)	mutex_exit(&(_sc)->sc_genlock)
48dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_LOCK_ASSERT(_sc)	ASSERT(mutex_owned(&(_sc)->sc_genlock))
49dd1de374Slin wang - Sun Microsystems - Beijing China 
50dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARRAY_SIZE(x)	(sizeof (x) / sizeof (x[0]))
51dd1de374Slin wang - Sun Microsystems - Beijing China 
52dd1de374Slin wang - Sun Microsystems - Beijing China #define	DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
53dd1de374Slin wang - Sun Microsystems - Beijing China 
54dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_MIN(a, b)	((a) < (b) ? (a) : (b))
55dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_MAX(a, b)	((a) > (b) ? (a) : (b))
56dd1de374Slin wang - Sun Microsystems - Beijing China 
57dd1de374Slin wang - Sun Microsystems - Beijing China #define	abs(x)		((x) >= 0 ? (x) : -(x))
58dd1de374Slin wang - Sun Microsystems - Beijing China 
59dd1de374Slin wang - Sun Microsystems - Beijing China enum ath9k_key_len {
60dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH9K_LEN_WEP40 = 5,
61dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH9K_LEN_WEP104 = 13,
62dd1de374Slin wang - Sun Microsystems - Beijing China };
63dd1de374Slin wang - Sun Microsystems - Beijing China 
64dd1de374Slin wang - Sun Microsystems - Beijing China /*
65dd1de374Slin wang - Sun Microsystems - Beijing China  * Sync a DMA area described by a dma_area_t
66dd1de374Slin wang - Sun Microsystems - Beijing China  */
67dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_DMA_SYNC(area, flag)    ((void) ddi_dma_sync((area).dma_hdl,    \
68dd1de374Slin wang - Sun Microsystems - Beijing China 				(area).offset, (area).alength, (flag)))
69dd1de374Slin wang - Sun Microsystems - Beijing China 
70dd1de374Slin wang - Sun Microsystems - Beijing China #define	list_empty(a) ((a)->list_head.list_next == &(a)->list_head)
71c0c93480Slin wang - Sun Microsystems - Beijing China #define	list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset))
72c0c93480Slin wang - Sun Microsystems - Beijing China #define	list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
73c0c93480Slin wang - Sun Microsystems - Beijing China #define	list_entry(ptr, type, member)	\
74c0c93480Slin wang - Sun Microsystems - Beijing China 	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
75c0c93480Slin wang - Sun Microsystems - Beijing China #define	list_is_last(node, list)	\
76c0c93480Slin wang - Sun Microsystems - Beijing China 	((node)->list_next == &(list)->list_head)
77c0c93480Slin wang - Sun Microsystems - Beijing China 
78c0c93480Slin wang - Sun Microsystems - Beijing China #define	list_for_each_entry_safe(object, temp, list_t)	\
79c0c93480Slin wang - Sun Microsystems - Beijing China 	for (object = list_head(list_t),	\
80c0c93480Slin wang - Sun Microsystems - Beijing China 	temp = list_object((list_t), ((list_d2l(list_t, object))->list_next));\
81c0c93480Slin wang - Sun Microsystems - Beijing China 	((list_d2l(list_t, temp))->list_next) != &((list_t)->list_head);\
82c0c93480Slin wang - Sun Microsystems - Beijing China 	object = temp,	\
83c0c93480Slin wang - Sun Microsystems - Beijing China 	temp = list_object((list_t), (list_d2l(list_t, temp))->list_next))
84c0c93480Slin wang - Sun Microsystems - Beijing China 
85c0c93480Slin wang - Sun Microsystems - Beijing China /*
86c0c93480Slin wang - Sun Microsystems - Beijing China  *  Insert src list after dst list. reinitialize src list thereafter.
87c0c93480Slin wang - Sun Microsystems - Beijing China  */
88c0c93480Slin wang - Sun Microsystems - Beijing China static __inline__ void
89c0c93480Slin wang - Sun Microsystems - Beijing China /* LINTED E_STATIC_UNUSED */
list_splice_tail_init(list_t * dst,list_t * src)90c0c93480Slin wang - Sun Microsystems - Beijing China list_splice_tail_init(list_t *dst, list_t *src)
91c0c93480Slin wang - Sun Microsystems - Beijing China {
92c0c93480Slin wang - Sun Microsystems - Beijing China 	list_node_t *dstnode = &dst->list_head;
93c0c93480Slin wang - Sun Microsystems - Beijing China 	list_node_t *srcnode = &src->list_head;
94c0c93480Slin wang - Sun Microsystems - Beijing China 
95c0c93480Slin wang - Sun Microsystems - Beijing China 	ASSERT(dst->list_size == src->list_size);
96c0c93480Slin wang - Sun Microsystems - Beijing China 	ASSERT(dst->list_offset == src->list_offset);
97c0c93480Slin wang - Sun Microsystems - Beijing China 
98c0c93480Slin wang - Sun Microsystems - Beijing China 	if (list_empty(src))
99c0c93480Slin wang - Sun Microsystems - Beijing China 		return;
100c0c93480Slin wang - Sun Microsystems - Beijing China 
101c0c93480Slin wang - Sun Microsystems - Beijing China 	dstnode->list_prev->list_next = srcnode->list_next;
102c0c93480Slin wang - Sun Microsystems - Beijing China 	srcnode->list_next->list_prev = dstnode->list_prev;
103c0c93480Slin wang - Sun Microsystems - Beijing China 	dstnode->list_prev = srcnode->list_prev;
104c0c93480Slin wang - Sun Microsystems - Beijing China 	srcnode->list_prev->list_next = dstnode;
105c0c93480Slin wang - Sun Microsystems - Beijing China 
106c0c93480Slin wang - Sun Microsystems - Beijing China 	/* reinitialize src list */
107c0c93480Slin wang - Sun Microsystems - Beijing China 	srcnode->list_next = srcnode->list_prev = srcnode;
108c0c93480Slin wang - Sun Microsystems - Beijing China }
109dd1de374Slin wang - Sun Microsystems - Beijing China 
110dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_LE_READ_16(p)						\
111dd1de374Slin wang - Sun Microsystems - Beijing China 	((uint16_t)							\
112dd1de374Slin wang - Sun Microsystems - Beijing China 	((((uint8_t *)(p))[0]) | (((uint8_t *)(p))[1] <<  8)))
113dd1de374Slin wang - Sun Microsystems - Beijing China 
114dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_LE_READ_32(p)						\
115dd1de374Slin wang - Sun Microsystems - Beijing China 	((uint32_t)							\
116dd1de374Slin wang - Sun Microsystems - Beijing China 	((((uint8_t *)(p))[0]) | (((uint8_t *)(p))[1] <<  8) |		\
117dd1de374Slin wang - Sun Microsystems - Beijing China 	(((uint8_t *)(p))[2] << 16) | (((uint8_t *)(p))[3] << 24)))
118dd1de374Slin wang - Sun Microsystems - Beijing China 
119dd1de374Slin wang - Sun Microsystems - Beijing China #define	swab16(value)  \
120dd1de374Slin wang - Sun Microsystems - Beijing China 	((((value) & 0xff) << 8) | ((value) >> 8))
121dd1de374Slin wang - Sun Microsystems - Beijing China 
122dd1de374Slin wang - Sun Microsystems - Beijing China #define	swab32(value)	\
123dd1de374Slin wang - Sun Microsystems - Beijing China 	(((uint32_t)swab16((uint16_t)((value) & 0xffff)) << 16) | \
124dd1de374Slin wang - Sun Microsystems - Beijing China 	(uint32_t)swab16((uint16_t)((value) >> 16)))
125dd1de374Slin wang - Sun Microsystems - Beijing China 
126dd1de374Slin wang - Sun Microsystems - Beijing China #define	swab64(value)	\
127dd1de374Slin wang - Sun Microsystems - Beijing China 	(((uint64_t)swab32((uint32_t)((value) & 0xffffffff)) \
128dd1de374Slin wang - Sun Microsystems - Beijing China 	    << 32) | \
129dd1de374Slin wang - Sun Microsystems - Beijing China 	(uint64_t)swab32((uint32_t)((value) >> 32)))
130dd1de374Slin wang - Sun Microsystems - Beijing China 
131dd1de374Slin wang - Sun Microsystems - Beijing China /* Bit map related macros. */
132dd1de374Slin wang - Sun Microsystems - Beijing China #define	set_bit(i, a)		((a)[(i)/NBBY] |= (1 << ((i)%NBBY)))
133dd1de374Slin wang - Sun Microsystems - Beijing China #define	clr_bit(i, a)		((a)[(i)/NBBY] &= ~(1 << ((i)%NBBY)))
134dd1de374Slin wang - Sun Microsystems - Beijing China #define	is_set(i, a)		((a)[(i)/NBBY] & (1 << ((i)%NBBY)))
135dd1de374Slin wang - Sun Microsystems - Beijing China #define	is_clr(i, a)		(!((a)[(i)/NBBY] & (1 << ((i)%NBBY))))
136dd1de374Slin wang - Sun Microsystems - Beijing China 
137dd1de374Slin wang - Sun Microsystems - Beijing China /* Macro to expand scalars to 64-bit objects */
138dd1de374Slin wang - Sun Microsystems - Beijing China 
139dd1de374Slin wang - Sun Microsystems - Beijing China #define	ito64(x) (sizeof (x) == 8) ?			\
140dd1de374Slin wang - Sun Microsystems - Beijing China 	(((unsigned long long int)(x)) & (0xff)) :	\
141dd1de374Slin wang - Sun Microsystems - Beijing China 	(sizeof (x) == 16) ?				\
142dd1de374Slin wang - Sun Microsystems - Beijing China 	(((unsigned long long int)(x)) & 0xffff) :	\
143dd1de374Slin wang - Sun Microsystems - Beijing China 	((sizeof (x) == 32) ?				\
144dd1de374Slin wang - Sun Microsystems - Beijing China 	(((unsigned long long int)(x)) & 0xffffffff) :	\
145dd1de374Slin wang - Sun Microsystems - Beijing China 	(unsigned long long int)(x))
146dd1de374Slin wang - Sun Microsystems - Beijing China 
147dd1de374Slin wang - Sun Microsystems - Beijing China /* increment with wrap-around */
148dd1de374Slin wang - Sun Microsystems - Beijing China #define	INCR(_l, _sz)	do {			\
149dd1de374Slin wang - Sun Microsystems - Beijing China 		(_l)++;				\
150dd1de374Slin wang - Sun Microsystems - Beijing China 		(_l) &= ((_sz) - 1);		\
151dd1de374Slin wang - Sun Microsystems - Beijing China 	} while (0)
152dd1de374Slin wang - Sun Microsystems - Beijing China 
153dd1de374Slin wang - Sun Microsystems - Beijing China /* decrement with wrap-around */
154dd1de374Slin wang - Sun Microsystems - Beijing China #define	DECR(_l, _sz)  do {			\
155dd1de374Slin wang - Sun Microsystems - Beijing China 		(_l)--;				\
156dd1de374Slin wang - Sun Microsystems - Beijing China 		(_l) &= ((_sz) - 1);		\
157dd1de374Slin wang - Sun Microsystems - Beijing China 	} while (0)
158dd1de374Slin wang - Sun Microsystems - Beijing China 
159dd1de374Slin wang - Sun Microsystems - Beijing China #define	A_MAX(a, b)	((a) > (b) ? (a) : (b))
160dd1de374Slin wang - Sun Microsystems - Beijing China 
161dd1de374Slin wang - Sun Microsystems - Beijing China #define	TSF_TO_TU(_h, _l)	\
162dd1de374Slin wang - Sun Microsystems - Beijing China 	((((uint32_t)(_h)) << 22) | (((uint32_t)(_l)) >> 10))
163dd1de374Slin wang - Sun Microsystems - Beijing China 
164dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_TXQ_SETUP(sc, i)	((sc)->sc_txqsetup & (1<<i))
165dd1de374Slin wang - Sun Microsystems - Beijing China 
166c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_CHAN_HTA(_c) \
167c0c93480Slin wang - Sun Microsystems - Beijing China 	(IEEE80211_IS_CHAN_5GHZ(_c) && \
168c0c93480Slin wang - Sun Microsystems - Beijing China 	((_c)->ich_flags & IEEE80211_CHAN_HT))
169c0c93480Slin wang - Sun Microsystems - Beijing China 
170c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_CHAN_HTG(_c) \
171c0c93480Slin wang - Sun Microsystems - Beijing China 	(IEEE80211_IS_CHAN_2GHZ(_c) && \
172c0c93480Slin wang - Sun Microsystems - Beijing China 	((_c)->ich_flags & IEEE80211_CHAN_HT))
173c0c93480Slin wang - Sun Microsystems - Beijing China 
174c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_DATA(_wh) \
175c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == \
176c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC0_TYPE_DATA)
177c0c93480Slin wang - Sun Microsystems - Beijing China 
178c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_DATA_QOS(_wh) \
179c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[0] & (IEEE80211_FC0_TYPE_MASK | \
180c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC0_SUBTYPE_QOS)) == \
181c0c93480Slin wang - Sun Microsystems - Beijing China 	(IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
182c0c93480Slin wang - Sun Microsystems - Beijing China 
183c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_MGMT(_wh) \
184c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == \
185c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC0_TYPE_MGT)
186c0c93480Slin wang - Sun Microsystems - Beijing China 
187c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_CTL(_wh) \
188c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == \
189c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC0_TYPE_CTL)
190c0c93480Slin wang - Sun Microsystems - Beijing China 
191c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_PSPOLL(_wh) \
192c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == \
193c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC0_SUBTYPE_PS_POLL)
194c0c93480Slin wang - Sun Microsystems - Beijing China 
195c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_IS_BACK_REQ(_wh) \
196c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == \
197c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC0_SUBTYPE_BAR)
198c0c93480Slin wang - Sun Microsystems - Beijing China 
199c0c93480Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_HAS_MOREFRAGS(_wh) \
200c0c93480Slin wang - Sun Microsystems - Beijing China 	(((_wh)->i_fc[1] & IEEE80211_FC1_MORE_FRAG) == \
201c0c93480Slin wang - Sun Microsystems - Beijing China 	IEEE80211_FC1_MORE_FRAG)
202dd1de374Slin wang - Sun Microsystems - Beijing China 
203dd1de374Slin wang - Sun Microsystems - Beijing China /* Debugging */
204dd1de374Slin wang - Sun Microsystems - Beijing China enum ARN_DEBUG {
205dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_HW		= 0x00000001,
206dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_REG_IO		= 0x00000002,
207dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_QUEUE		= 0x00000004,
208dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_EEPROM		= 0x00000008,
209dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_XMIT		= 0x00000010,
210dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_RECV		= 0x00000020,
211dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_CALIBRATE	= 0x00000040,
212dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_CHANNEL		= 0x00000080,
213dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_INTERRUPT	= 0x00000100,
214dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_REGULATORY	= 0x00000200,
215dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_ANI		= 0x00000400,
216dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_POWER_MGMT	= 0x00000800,
217dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_KEYCACHE	= 0x00001000,
218dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_BEACON		= 0x00002000,
219dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_RATE		= 0x00004000,
220dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_INIT		= 0x00008000,
221dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_ATTACH		= 0x00010000,
222dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_DEATCH		= 0x00020000,
223dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_AGGR		= 0x00040000,
224dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_RESET		= 0x00080000,
225dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_FATAL		= 0x00100000,
226dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_ANY		= 0x00200000,
227dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG_ALL		= 0x00FFFFFF,
228dd1de374Slin wang - Sun Microsystems - Beijing China };
229dd1de374Slin wang - Sun Microsystems - Beijing China 
230dd1de374Slin wang - Sun Microsystems - Beijing China /* Debug and log functions */
231dd1de374Slin wang - Sun Microsystems - Beijing China void arn_dbg(uint32_t dbg_flags, const int8_t *fmt, ...); /* debug function */
232dd1de374Slin wang - Sun Microsystems - Beijing China void arn_log(const int8_t *fmt, ...); /* event log function */
233dd1de374Slin wang - Sun Microsystems - Beijing China void arn_problem(const int8_t *fmt, ...); /* run-time problem function */
234dd1de374Slin wang - Sun Microsystems - Beijing China 
235dd1de374Slin wang - Sun Microsystems - Beijing China #ifdef DEBUG
236dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_DDB(command)	do {				\
237dd1de374Slin wang - Sun Microsystems - Beijing China 					{ command; }		\
238dd1de374Slin wang - Sun Microsystems - Beijing China 					_NOTE(CONSTANTCONDITION)\
239dd1de374Slin wang - Sun Microsystems - Beijing China 				} while (0)
240dd1de374Slin wang - Sun Microsystems - Beijing China #else
241dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_DDB(command)
242dd1de374Slin wang - Sun Microsystems - Beijing China #endif /* DEBUG */
243dd1de374Slin wang - Sun Microsystems - Beijing China 
244dd1de374Slin wang - Sun Microsystems - Beijing China #define	ARN_DBG(args)		ARN_DDB(arn_dbg args)
245dd1de374Slin wang - Sun Microsystems - Beijing China 
246dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_stats {
247dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_hardware;	/* fatal hardware error interrupts */
248dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rxorn;	/* rx overrun interrupts */
249dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rxeol;	/* rx eol interrupts */
250dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_txurn;	/* tx underrun interrupts */
251dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_mgmt;	/* management frames transmitted */
252dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_discard;	/* frames discarded prior to assoc */
253dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_invalid; /* frames discarded 'cuz device gone */
254dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_qstop;	/* tx queue stopped 'cuz full */
255dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_nobuf;	/* tx failed 'cuz no tx buffer (data) */
256dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_nobufmgt; /* tx failed 'cuz no tx buffer(mgmt) */
257dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_xretries; /* tx failed 'cuz too many retries */
258dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_fifoerr;	/* tx failed 'cuz FIFO underrun */
259dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_filtered; /* tx failed 'cuz xmit filtered */
260dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_shortretry; /* tx on-chip retries (short) */
261dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_longretry; /* tx on-chip retries (long) */
262dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_noack;	/* tx frames with no ack marked */
263dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_rts;	/* tx frames with rts enabled */
264dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_shortpre; /* tx frames with short preamble */
265dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_altrate;	/* tx frames with alternate rate */
266dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_tx_protect;	/* tx frames with protection */
267dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t		ast_tx_rssi;	/* tx rssi of last ack */
268dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t		ast_tx_rssidelta; /* tx rssi delta */
269dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rx_crcerr;	/* rx failed 'cuz of bad CRC */
270dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rx_fifoerr;	/* rx failed 'cuz of FIFO overrun */
271dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rx_badcrypt; /* rx failed 'cuz decryption */
272dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rx_phyerr;	/* rx PHY error summary count */
273dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rx_phy[32];	/* rx PHY error per-code counts */
274dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rx_tooshort; /* rx discarded 'cuz frame too short */
275dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_per_cal;	/* periodic calibration calls */
276dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_per_calfail; /* periodic calibration failed */
277dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_per_rfgain;	/* periodic calibration rfgain reset */
278dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rate_calls;	/* rate control checks */
279dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rate_raise;	/* rate control raised xmit rate */
280dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	ast_rate_drop;	/* rate control dropped xmit rate */
281dd1de374Slin wang - Sun Microsystems - Beijing China };
282dd1de374Slin wang - Sun Microsystems - Beijing China 
283dd1de374Slin wang - Sun Microsystems - Beijing China struct dma_area {
284dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_acc_handle_t	acc_hdl;	/* handle for memory */
285dd1de374Slin wang - Sun Microsystems - Beijing China 	caddr_t			mem_va;		/* CPU VA of memory */
286dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t		nslots;		/* number of slots */
287dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t		size;		/* size per slot */
288dd1de374Slin wang - Sun Microsystems - Beijing China 	size_t			alength;	/* allocated size */
289dd1de374Slin wang - Sun Microsystems - Beijing China 						/* >= product of above */
290dd1de374Slin wang - Sun Microsystems - Beijing China 
291dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_dma_handle_t	dma_hdl;	/* DMA handle */
292dd1de374Slin wang - Sun Microsystems - Beijing China 	offset_t		offset;		/* relative to handle */
293dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_dma_cookie_t	cookie;		/* associated cookie */
294dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t		ncookies;	/* must be 1 */
295dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t		token;		/* arbitrary identifier */
296dd1de374Slin wang - Sun Microsystems - Beijing China };
297dd1de374Slin wang - Sun Microsystems - Beijing China typedef struct dma_area dma_area_t;
298dd1de374Slin wang - Sun Microsystems - Beijing China 
299dd1de374Slin wang - Sun Microsystems - Beijing China /* Load-time Configuration */
300dd1de374Slin wang - Sun Microsystems - Beijing China 
301dd1de374Slin wang - Sun Microsystems - Beijing China /*
302dd1de374Slin wang - Sun Microsystems - Beijing China  * Per-instance load-time (note: NOT run-time)
303dd1de374Slin wang - Sun Microsystems - Beijing China  * configurations for Atheros Device
304dd1de374Slin wang - Sun Microsystems - Beijing China  */
305dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_config {
306dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t ath_aggr_prot;
307dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t txpowlimit;
308dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t txpowlimit_override;
309dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t cabqReadytime; /* Cabq Readytime % */
310dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t swBeaconProcess; /* Process received beacons in SW (vs HW) */
311dd1de374Slin wang - Sun Microsystems - Beijing China };
312dd1de374Slin wang - Sun Microsystems - Beijing China 
313dd1de374Slin wang - Sun Microsystems - Beijing China /* Descriptor Management */
314dd1de374Slin wang - Sun Microsystems - Beijing China 
315dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TXBUF_RESET(_bf) do {		\
316dd1de374Slin wang - Sun Microsystems - Beijing China 		(_bf)->bf_status = 0;		\
317dd1de374Slin wang - Sun Microsystems - Beijing China 		(_bf)->bf_lastbf = NULL;	\
318dd1de374Slin wang - Sun Microsystems - Beijing China 		(_bf)->bf_lastfrm = NULL;	\
319dd1de374Slin wang - Sun Microsystems - Beijing China 		(_bf)->bf_next = NULL;		\
320*a3ccee74Slin wang - Sun Microsystems - Beijing China 		(void) memset(&((_bf)->bf_state), 0,	\
321dd1de374Slin wang - Sun Microsystems - Beijing China 		sizeof (struct ath_buf_state));	\
322*a3ccee74Slin wang - Sun Microsystems - Beijing China 		(void) memset(&((_bf)->tx_info_priv), 0,	\
323c0c93480Slin wang - Sun Microsystems - Beijing China 		sizeof (struct ath_tx_info_priv));	\
324*a3ccee74Slin wang - Sun Microsystems - Beijing China 		_NOTE(CONSTCOND) \
325dd1de374Slin wang - Sun Microsystems - Beijing China 	} while (0)
326dd1de374Slin wang - Sun Microsystems - Beijing China 
327dd1de374Slin wang - Sun Microsystems - Beijing China enum buffer_type {
328dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_DATA		= BIT(0),
329dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_AGGR		= BIT(1),
330dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_AMPDU		= BIT(2),
331dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_HT			= BIT(3),
332dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_RETRY		= BIT(4),
333dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_XRETRY		= BIT(5),
334dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_SHORT_PREAMBLE	= BIT(6),
335dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_BAR			= BIT(7),
336dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_PSPOLL		= BIT(8),
337dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_AGGR_BURST		= BIT(9),
338dd1de374Slin wang - Sun Microsystems - Beijing China 	BUF_CALC_AIRTIME	= BIT(10),
339dd1de374Slin wang - Sun Microsystems - Beijing China };
340dd1de374Slin wang - Sun Microsystems - Beijing China 
341dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_buf_state {
342dd1de374Slin wang - Sun Microsystems - Beijing China 	int bfs_nframes;	/* # frames in aggregate */
343dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t bfs_al;	/* length of aggregate */
344dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t bfs_frmlen;	/* length of frame */
345dd1de374Slin wang - Sun Microsystems - Beijing China 	int bfs_seqno;		/* sequence number */
346dd1de374Slin wang - Sun Microsystems - Beijing China 	int bfs_tidno;		/* tid of this frame */
347dd1de374Slin wang - Sun Microsystems - Beijing China 	int bfs_retries;	/* current retries */
348dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t bf_type;	/* BUF_* (enum buffer_type) */
349dd1de374Slin wang - Sun Microsystems - Beijing China 	/* key type used to encrypt this frame */
350dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t bfs_keyix;
351dd1de374Slin wang - Sun Microsystems - Beijing China 	enum ath9k_key_type bfs_keytype;
352dd1de374Slin wang - Sun Microsystems - Beijing China };
353dd1de374Slin wang - Sun Microsystems - Beijing China 
354dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_nframes		bf_state.bfs_nframes
355dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_al			bf_state.bfs_al
356dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_frmlen		bf_state.bfs_frmlen
357dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_retries		bf_state.bfs_retries
358dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_seqno		bf_state.bfs_seqno
359dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_tidno		bf_state.bfs_tidno
360dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_rcs			bf_state.bfs_rcs
361dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_keyix		bf_state.bfs_keyix
362dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_keytype		bf_state.bfs_keytype
363dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isdata(bf)		(bf->bf_state.bf_type & BUF_DATA)
364dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isaggr(bf)		(bf->bf_state.bf_type & BUF_AGGR)
365dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isampdu(bf)		(bf->bf_state.bf_type & BUF_AMPDU)
366dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isht(bf)		(bf->bf_state.bf_type & BUF_HT)
367dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isretried(bf)	(bf->bf_state.bf_type & BUF_RETRY)
368dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isxretried(bf)	(bf->bf_state.bf_type & BUF_XRETRY)
369dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isshpreamble(bf)	(bf->bf_state.bf_type & BUF_SHORT_PREAMBLE)
370dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isbar(bf)		(bf->bf_state.bf_type & BUF_BAR)
371dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_ispspoll(bf)		(bf->bf_state.bf_type & BUF_PSPOLL)
372dd1de374Slin wang - Sun Microsystems - Beijing China #define	bf_isaggrburst(bf)	(bf->bf_state.bf_type & BUF_AGGR_BURST)
373dd1de374Slin wang - Sun Microsystems - Beijing China 
374dd1de374Slin wang - Sun Microsystems - Beijing China /*
375dd1de374Slin wang - Sun Microsystems - Beijing China  * Abstraction of a contiguous buffer to transmit/receive.
376dd1de374Slin wang - Sun Microsystems - Beijing China  * There is only a single hw descriptor encapsulated here.
377dd1de374Slin wang - Sun Microsystems - Beijing China  */
378dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_buf {
379dd1de374Slin wang - Sun Microsystems - Beijing China 	/* last buf of this unit (a frame or an aggregate) */
380dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf *bf_lastbf;
381dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf *bf_lastfrm;	/* last buf of this frame */
382dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf *bf_next;	/* next subframe in the aggregate */
383dd1de374Slin wang - Sun Microsystems - Beijing China 	mblk_t *bf_m;
384dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_desc	*bf_desc;	/* virtual addr of desc */
385dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t bf_daddr;		/* physical addr of desc */
386dd1de374Slin wang - Sun Microsystems - Beijing China 	dma_area_t bf_dma;		/* dma area for buf */
387dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ieee80211_node *bf_in;	/* pointer to the node */
388dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t bf_status;
389dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t bf_flags;		/* tx descriptor flags */
390dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf_state bf_state;	/* buffer state */
391dd1de374Slin wang - Sun Microsystems - Beijing China 
392c0c93480Slin wang - Sun Microsystems - Beijing China 	/* Temp workground for rc */
393c0c93480Slin wang - Sun Microsystems - Beijing China 	struct ath9k_tx_rate rates[4];
394c0c93480Slin wang - Sun Microsystems - Beijing China 	struct ath_tx_info_priv tx_info_priv;
395c0c93480Slin wang - Sun Microsystems - Beijing China 
396c0c93480Slin wang - Sun Microsystems - Beijing China 	/* we're in list of sc->sc_txbuf_list or sc->sc_rxbuf_list */
397dd1de374Slin wang - Sun Microsystems - Beijing China 	list_node_t bf_node;
398dd1de374Slin wang - Sun Microsystems - Beijing China };
399dd1de374Slin wang - Sun Microsystems - Beijing China 
400dd1de374Slin wang - Sun Microsystems - Beijing China /*
401dd1de374Slin wang - Sun Microsystems - Beijing China  * reset the rx buffer.
402dd1de374Slin wang - Sun Microsystems - Beijing China  * any new fields added to the athbuf and require
403dd1de374Slin wang - Sun Microsystems - Beijing China  * reset need to be added to this macro.
404dd1de374Slin wang - Sun Microsystems - Beijing China  * currently bf_status is the only one requires that
405dd1de374Slin wang - Sun Microsystems - Beijing China  * requires reset.
406dd1de374Slin wang - Sun Microsystems - Beijing China  */
407dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_RXBUF_RESET(_bf)	((_bf)->bf_status = 0)
408dd1de374Slin wang - Sun Microsystems - Beijing China 
409dd1de374Slin wang - Sun Microsystems - Beijing China /* hw processing complete, desc processed by hal */
410dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_BUFSTATUS_DONE	0x00000001
411dd1de374Slin wang - Sun Microsystems - Beijing China /* hw processing complete, desc hold for hw */
412dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_BUFSTATUS_STALE	0x00000002
413dd1de374Slin wang - Sun Microsystems - Beijing China /* Rx-only: OS is done with this packet and it's ok to queued it to hw */
414dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_BUFSTATUS_FREE	0x00000004
415dd1de374Slin wang - Sun Microsystems - Beijing China 
416dd1de374Slin wang - Sun Microsystems - Beijing China /* RX / TX */
417dd1de374Slin wang - Sun Microsystems - Beijing China 
418dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_MAX_ANTENNA	3
419dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_RXBUF	512
420dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_NUM_TID	16
421dd1de374Slin wang - Sun Microsystems - Beijing China 
422dd1de374Slin wang - Sun Microsystems - Beijing China void arn_rx_buf_link(struct arn_softc *sc, struct ath_buf *bf);
423dd1de374Slin wang - Sun Microsystems - Beijing China int arn_startrecv(struct arn_softc *sc);
424dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t arn_stoprecv(struct arn_softc *sc);
425dd1de374Slin wang - Sun Microsystems - Beijing China void arn_flushrecv(struct arn_softc *sc);
426dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t arn_calcrxfilter(struct arn_softc *sc);
427dd1de374Slin wang - Sun Microsystems - Beijing China int arn_rx_init(struct arn_softc *sc, int nbufs);
428dd1de374Slin wang - Sun Microsystems - Beijing China void arn_rx_cleanup(struct arn_softc *sc);
429dd1de374Slin wang - Sun Microsystems - Beijing China uint_t arn_softint_handler(caddr_t data);
430dd1de374Slin wang - Sun Microsystems - Beijing China void arn_setdefantenna(struct arn_softc *sc, uint32_t antenna);
431dd1de374Slin wang - Sun Microsystems - Beijing China 
432dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TXBUF	512
433dd1de374Slin wang - Sun Microsystems - Beijing China /* max number of transmit attempts (tries) */
434dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TXMAXTRY	13
435dd1de374Slin wang - Sun Microsystems - Beijing China /* max number of 11n transmit attempts (tries) */
436dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_11N_TXMAXTRY	10
437dd1de374Slin wang - Sun Microsystems - Beijing China /* max number of tries for management and control frames */
438dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_MGT_TXMAXTRY	4
439dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_BA_BMP_SIZE		64
440dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_MAX_BA		WME_BA_BMP_SIZE
441dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TID_MAX_BUFS	(2 * WME_MAX_BA)
442dd1de374Slin wang - Sun Microsystems - Beijing China 
443dd1de374Slin wang - Sun Microsystems - Beijing China /* Wireless Multimedia Extension Defines */
444dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_AC_BE	0 /* best effort */
445dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_AC_BK	1 /* background */
446dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_AC_VI	2 /* video */
447dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_AC_VO	3 /* voice */
448dd1de374Slin wang - Sun Microsystems - Beijing China #define	WME_NUM_AC	4
449dd1de374Slin wang - Sun Microsystems - Beijing China 
450dd1de374Slin wang - Sun Microsystems - Beijing China /*
451dd1de374Slin wang - Sun Microsystems - Beijing China  * Data transmit queue state.  One of these exists for each
452dd1de374Slin wang - Sun Microsystems - Beijing China  * hardware transmit queue.  Packets sent to us from above
453dd1de374Slin wang - Sun Microsystems - Beijing China  * are assigned to queues based on their priority.  Not all
454dd1de374Slin wang - Sun Microsystems - Beijing China  * devices support a complete set of hardware transmit queues.
455dd1de374Slin wang - Sun Microsystems - Beijing China  * For those devices the array sc_ac2q will map multiple
456dd1de374Slin wang - Sun Microsystems - Beijing China  * priorities to fewer hardware queues (typically all to one
457dd1de374Slin wang - Sun Microsystems - Beijing China  * hardware queue).
458dd1de374Slin wang - Sun Microsystems - Beijing China  */
459dd1de374Slin wang - Sun Microsystems - Beijing China 
460dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_txq {
461c0c93480Slin wang - Sun Microsystems - Beijing China 	uint32_t	axq_qnum; /* hardware q number */
462dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	*axq_link; /* link ptr in last TX desc */
463dd1de374Slin wang - Sun Microsystems - Beijing China 	list_t		axq_list; /* transmit queue */
464dd1de374Slin wang - Sun Microsystems - Beijing China 	kmutex_t	axq_lock; /* lock on q and link */
465dd1de374Slin wang - Sun Microsystems - Beijing China 	unsigned long	axq_lockflags; /* intr state when must cli */
466c0c93480Slin wang - Sun Microsystems - Beijing China 	uint32_t		axq_depth; /* queue depth (stat only) */
467dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t 	axq_aggr_depth; /* aggregates queued */
468dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t 	axq_totalqueued; /* total ever queued */
469c0c93480Slin wang - Sun Microsystems - Beijing China 	boolean_t	stopped;
470dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf	*axq_linkbuf; /* virtual addr of last buffer */
471dd1de374Slin wang - Sun Microsystems - Beijing China 	/* first desc of the last descriptor that contains CTS */
472dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_desc *axq_lastdsWithCTS;
473c0c93480Slin wang - Sun Microsystems - Beijing China 
474c0c93480Slin wang - Sun Microsystems - Beijing China 	/*
475c0c93480Slin wang - Sun Microsystems - Beijing China 	 * final desc of the gating desc that determines whether
476c0c93480Slin wang - Sun Microsystems - Beijing China 	 * lastdsWithCTS has been DMA'ed or not
477c0c93480Slin wang - Sun Microsystems - Beijing China 	 */
478c0c93480Slin wang - Sun Microsystems - Beijing China 	struct ath_desc *axq_gatingds;
479c0c93480Slin wang - Sun Microsystems - Beijing China 
480c0c93480Slin wang - Sun Microsystems - Beijing China 	list_t axq_acq;
481c0c93480Slin wang - Sun Microsystems - Beijing China 
482c0c93480Slin wang - Sun Microsystems - Beijing China 	uint32_t	axq_intrcnt; /* interrupt count */
483dd1de374Slin wang - Sun Microsystems - Beijing China };
484dd1de374Slin wang - Sun Microsystems - Beijing China 
485dd1de374Slin wang - Sun Microsystems - Beijing China 
486dd1de374Slin wang - Sun Microsystems - Beijing China #define	AGGR_CLEANUP		BIT(1)
487dd1de374Slin wang - Sun Microsystems - Beijing China #define	AGGR_ADDBA_COMPLETE	BIT(2)
488dd1de374Slin wang - Sun Microsystems - Beijing China #define	AGGR_ADDBA_PROGRESS	BIT(3)
489dd1de374Slin wang - Sun Microsystems - Beijing China 
490dd1de374Slin wang - Sun Microsystems - Beijing China /* per TID aggregate tx state for a destination */
491dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_atx_tid {
492dd1de374Slin wang - Sun Microsystems - Beijing China 	list_node_t list;
493c0c93480Slin wang - Sun Microsystems - Beijing China 	list_t buf_q;
494dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_node *an;
495dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_atx_ac *ac;
496dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf *tx_buf[ATH_TID_MAX_BUFS]; /* active tx frames */
497dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t seq_start;
498dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t seq_next;
499dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t baw_size;
500dd1de374Slin wang - Sun Microsystems - Beijing China 	int tidno;
501dd1de374Slin wang - Sun Microsystems - Beijing China 	int baw_head; /* first un-acked tx buffer */
502dd1de374Slin wang - Sun Microsystems - Beijing China 	int baw_tail; /* next unused tx buffer slot */
503dd1de374Slin wang - Sun Microsystems - Beijing China 	int sched;
504dd1de374Slin wang - Sun Microsystems - Beijing China 	int paused;
505dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t state;
506dd1de374Slin wang - Sun Microsystems - Beijing China 	int addba_exchangeattempts;
507dd1de374Slin wang - Sun Microsystems - Beijing China };
508dd1de374Slin wang - Sun Microsystems - Beijing China 
509dd1de374Slin wang - Sun Microsystems - Beijing China /* per access-category aggregate tx state for a destination */
510dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_atx_ac {
511dd1de374Slin wang - Sun Microsystems - Beijing China 	int sched; /* dest-ac is scheduled */
512dd1de374Slin wang - Sun Microsystems - Beijing China 	int qnum; /* H/W queue number associated with this AC */
513dd1de374Slin wang - Sun Microsystems - Beijing China 	list_node_t		list;
514c0c93480Slin wang - Sun Microsystems - Beijing China 	list_t		tid_q;
515dd1de374Slin wang - Sun Microsystems - Beijing China };
516dd1de374Slin wang - Sun Microsystems - Beijing China 
517dd1de374Slin wang - Sun Microsystems - Beijing China /* per dest tx state */
518dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_atx {
519dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_atx_tid tid[WME_NUM_TID];
520dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_atx_ac ac[WME_NUM_AC];
521dd1de374Slin wang - Sun Microsystems - Beijing China };
522dd1de374Slin wang - Sun Microsystems - Beijing China 
523dd1de374Slin wang - Sun Microsystems - Beijing China /* per-frame tx control block */
524dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_tx_control {
525dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_txq *txq;
526dd1de374Slin wang - Sun Microsystems - Beijing China 	int if_id;
527dd1de374Slin wang - Sun Microsystems - Beijing China };
528dd1de374Slin wang - Sun Microsystems - Beijing China 
529dd1de374Slin wang - Sun Microsystems - Beijing China /* per frame tx status block */
530dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_xmit_status {
531dd1de374Slin wang - Sun Microsystems - Beijing China 	/* number of retries to successufully transmit this frame */
532dd1de374Slin wang - Sun Microsystems - Beijing China 	int retries;
533dd1de374Slin wang - Sun Microsystems - Beijing China 	int flags; /* status of transmit */
534dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_ERROR	0x01
535dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_XRETRY	0x02
536dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_BAR	0x04
537dd1de374Slin wang - Sun Microsystems - Beijing China };
538dd1de374Slin wang - Sun Microsystems - Beijing China 
539dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_tx_stat {
540dd1de374Slin wang - Sun Microsystems - Beijing China 	int rssi; /* RSSI (noise floor ajusted) */
541dd1de374Slin wang - Sun Microsystems - Beijing China 	int rssictl[ATH_MAX_ANTENNA]; /* RSSI (noise floor ajusted) */
542dd1de374Slin wang - Sun Microsystems - Beijing China 	int rssiextn[ATH_MAX_ANTENNA]; /* RSSI (noise floor ajusted) */
543dd1de374Slin wang - Sun Microsystems - Beijing China 	int rateieee; /* data rate xmitted (IEEE rate code) */
544dd1de374Slin wang - Sun Microsystems - Beijing China 	int rateKbps; /* data rate xmitted (Kbps) */
545dd1de374Slin wang - Sun Microsystems - Beijing China 	int ratecode; /* phy rate code */
546dd1de374Slin wang - Sun Microsystems - Beijing China 	int flags; /* validity flags */
547dd1de374Slin wang - Sun Microsystems - Beijing China /* if any of ctl,extn chain rssis are valid */
548dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_CHAIN_RSSI_VALID	0x01
549dd1de374Slin wang - Sun Microsystems - Beijing China /* if extn chain rssis are valid */
550dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_RSSI_EXTN_VALID	0x02
551dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t airtime; /* time on air per final tx rate */
552dd1de374Slin wang - Sun Microsystems - Beijing China };
553dd1de374Slin wang - Sun Microsystems - Beijing China 
554c0c93480Slin wang - Sun Microsystems - Beijing China void arn_tx_node_init(struct arn_softc *sc, struct ath_node *an);
555c0c93480Slin wang - Sun Microsystems - Beijing China void arn_tx_node_cleanup(struct arn_softc *sc, struct ieee80211_node *in);
556dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_txq *arn_txq_setup(struct arn_softc *sc, int qtype, int subtype);
557dd1de374Slin wang - Sun Microsystems - Beijing China void arn_tx_cleanupq(struct arn_softc *sc, struct ath_txq *txq);
558dd1de374Slin wang - Sun Microsystems - Beijing China int arn_tx_setup(struct arn_softc *sc, int haltype);
559dd1de374Slin wang - Sun Microsystems - Beijing China void arn_draintxq(struct arn_softc *sc, boolean_t retry_tx);
560dd1de374Slin wang - Sun Microsystems - Beijing China void arn_tx_draintxq(struct arn_softc *sc, struct ath_txq *txq);
561c0c93480Slin wang - Sun Microsystems - Beijing China void arn_txq_schedule(struct arn_softc *sc, struct ath_txq *txq);
562dd1de374Slin wang - Sun Microsystems - Beijing China int arn_tx(ieee80211com_t *ic, mblk_t *mp, uint8_t type);
563dd1de374Slin wang - Sun Microsystems - Beijing China int arn_txq_update(struct arn_softc *sc, int qnum,
564dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_tx_queue_info *qinfo);
565dd1de374Slin wang - Sun Microsystems - Beijing China void arn_tx_int_proc(void *arg);
566dd1de374Slin wang - Sun Microsystems - Beijing China 
567dd1de374Slin wang - Sun Microsystems - Beijing China /* Node / Aggregation */
568dd1de374Slin wang - Sun Microsystems - Beijing China 
569dd1de374Slin wang - Sun Microsystems - Beijing China #define	ADDBA_EXCHANGE_ATTEMPTS	10
570dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_AGGR_DELIM_SZ	4 /* delimiter size   */
571dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_AGGR_MINPLEN	256 /* in bytes, minimum packet length */
572dd1de374Slin wang - Sun Microsystems - Beijing China /* number of delimiters for encryption padding */
573dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_AGGR_ENCRYPTDELIM	10
574dd1de374Slin wang - Sun Microsystems - Beijing China /* minimum h/w qdepth to be sustained to maximize aggregation */
575dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_AGGR_MIN_QDEPTH			2
576dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_AMPDU_SUBFRAME_DEFAULT		32
577dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_SEQ_SEQ_SHIFT			4
578dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_SEQ_MAX			4096
579dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_MIN_AMPDU_BUF			0x8
580dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_HTCAP_MAXRXAMPDU_FACTOR	13
581dd1de374Slin wang - Sun Microsystems - Beijing China 
582dd1de374Slin wang - Sun Microsystems - Beijing China /*
583dd1de374Slin wang - Sun Microsystems - Beijing China  * return whether a bit at index _n in bitmap _bm is set
584dd1de374Slin wang - Sun Microsystems - Beijing China  * _sz is the size of the bitmap
585dd1de374Slin wang - Sun Microsystems - Beijing China  */
586dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_BA_ISSET(_bm, _n)	(((_n) < (WME_BA_BMP_SIZE)) &&	\
587dd1de374Slin wang - Sun Microsystems - Beijing China 	((_bm)[(_n) >> 5] & (1 << ((_n) & 31))))
588dd1de374Slin wang - Sun Microsystems - Beijing China 
589dd1de374Slin wang - Sun Microsystems - Beijing China /* return block-ack bitmap index given sequence and starting sequence */
590dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_BA_INDEX(_st, _seq)	(((_seq) - (_st)) & (IEEE80211_SEQ_MAX - 1))
591dd1de374Slin wang - Sun Microsystems - Beijing China 
592dd1de374Slin wang - Sun Microsystems - Beijing China /* returns delimiter padding required given the packet length */
593dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_AGGR_GET_NDELIM(_len)	\
594dd1de374Slin wang - Sun Microsystems - Beijing China 	(((((_len) + ATH_AGGR_DELIM_SZ) < ATH_AGGR_MINPLEN) ?	\
595dd1de374Slin wang - Sun Microsystems - Beijing China 	(ATH_AGGR_MINPLEN - (_len) - ATH_AGGR_DELIM_SZ) : 0) >> 2)
596dd1de374Slin wang - Sun Microsystems - Beijing China 
597dd1de374Slin wang - Sun Microsystems - Beijing China #define	BAW_WITHIN(_start, _bawsz, _seqno)	\
598dd1de374Slin wang - Sun Microsystems - Beijing China 	((((_seqno) - (_start)) & 4095) < (_bawsz))
599dd1de374Slin wang - Sun Microsystems - Beijing China 
600dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_DS_BA_SEQ(_ds)		((_ds)->ds_us.tx.ts_seqnum)
601dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_DS_BA_BITMAP(_ds)		(&(_ds)->ds_us.tx.ba_low)
602dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_DS_TX_BA(_ds)		((_ds)->ds_us.tx.ts_flags & ATH9K_TX_BA)
603c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_AN_2_TID(_an, _tidno)	(&(_an)->tid[(_tidno)])
604c0c93480Slin wang - Sun Microsystems - Beijing China 
605c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_ERROR	0x01
606c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_XRETRY	0x02
607c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_TX_BAR	0x04
608dd1de374Slin wang - Sun Microsystems - Beijing China 
609dd1de374Slin wang - Sun Microsystems - Beijing China enum ATH_AGGR_STATUS {
610dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_AGGR_DONE,
611dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_AGGR_BAW_CLOSED,
612dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_AGGR_LIMITED,
613dd1de374Slin wang - Sun Microsystems - Beijing China };
614dd1de374Slin wang - Sun Microsystems - Beijing China 
615dd1de374Slin wang - Sun Microsystems - Beijing China struct aggr_rifs_param {
616dd1de374Slin wang - Sun Microsystems - Beijing China 	int param_max_frames;
617dd1de374Slin wang - Sun Microsystems - Beijing China 	int param_max_len;
618dd1de374Slin wang - Sun Microsystems - Beijing China 	int param_rl;
619dd1de374Slin wang - Sun Microsystems - Beijing China 	int param_al;
620dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_rc_series *param_rcs;
621dd1de374Slin wang - Sun Microsystems - Beijing China };
622dd1de374Slin wang - Sun Microsystems - Beijing China 
623c0c93480Slin wang - Sun Microsystems - Beijing China /* RSSI correction */
624c0c93480Slin wang - Sun Microsystems - Beijing China void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah);
625c0c93480Slin wang - Sun Microsystems - Beijing China 
626c0c93480Slin wang - Sun Microsystems - Beijing China #define	AR_PHY_CCA_MAX_AR5416_GOOD_VALUE	-85
627c0c93480Slin wang - Sun Microsystems - Beijing China #define	AR_PHY_CCA_MAX_AR9280_GOOD_VALUE	-112
628c0c93480Slin wang - Sun Microsystems - Beijing China #define	AR_PHY_CCA_MAX_AR9285_GOOD_VALUE	-118
629c0c93480Slin wang - Sun Microsystems - Beijing China 
630c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_RSSI_LPF_LEN		10
631c0c93480Slin wang - Sun Microsystems - Beijing China #define	RSSI_LPF_THRESHOLD		-20
632c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH9K_RSSI_BAD			-128
633c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_RSSI_EP_MULTIPLIER		(1<<7)
634c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_EP_MUL(x, mul)		((x) * (mul))
635c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_RSSI_IN(x)		(ATH_EP_MUL((x), ATH_RSSI_EP_MULTIPLIER))
636c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_LPF_RSSI(x, y, len)	\
637c0c93480Slin wang - Sun Microsystems - Beijing China 	((x != ATH_RSSI_DUMMY_MARKER) ? \
638c0c93480Slin wang - Sun Microsystems - Beijing China 	(((x) * ((len) - 1) + (y)) / (len)) : (y))
639c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_RSSI_LPF(x, y)	do { \
640c0c93480Slin wang - Sun Microsystems - Beijing China     if ((y) >= RSSI_LPF_THRESHOLD)   \
641c0c93480Slin wang - Sun Microsystems - Beijing China 	x = ATH_LPF_RSSI((x), ATH_RSSI_IN((y)), ATH_RSSI_LPF_LEN);  \
642c0c93480Slin wang - Sun Microsystems - Beijing China } while (0)
643c0c93480Slin wang - Sun Microsystems - Beijing China #define	ATH_EP_RND(x, mul)	\
644c0c93480Slin wang - Sun Microsystems - Beijing China 	((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
645c0c93480Slin wang - Sun Microsystems - Beijing China 
646dd1de374Slin wang - Sun Microsystems - Beijing China /* driver-specific node state */
647dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_node {
648dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ieee80211_node an_node;	/* base class */
649dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	an_tx_times;	/* rate ctl times on one rate */
650dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	an_tx_ok;	/* tx ok pkt */
651dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	an_tx_err;	/* tx !ok pkt */
652dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	an_tx_retr;	/* tx retry count */
653dd1de374Slin wang - Sun Microsystems - Beijing China 	int32_t		an_tx_upper;	/* tx upper rate req cnt */
654dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t	an_tx_antenna;	/* antenna for last good frame */
655dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rix0;	/* series 0 rate index */
656dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_try0;	/* series 0 try count */
657dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_mgtrate;	/* h/w rate for management/ctl frames */
658dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_mgtratesp; /* short preamble h/w rate for " " */
659dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate0;	/* series 0 h/w rate */
660dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate1;	/* series 1 h/w rate */
661dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate2;	/* series 2 h/w rate */
662dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate3;	/* series 3 h/w rate */
663dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate0sp;	/* series 0 short preamble h/w rate */
664dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate1sp;	/* series 1 short preamble h/w rate */
665dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate2sp;	/* series 2 short preamble h/w rate */
666dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t		an_tx_rate3sp;	/* series 3 short preamble h/w rate */
667c0c93480Slin wang - Sun Microsystems - Beijing China 	struct ath_rate_priv rate_priv;
668c0c93480Slin wang - Sun Microsystems - Beijing China 	struct ath_atx_tid tid[WME_NUM_TID];
669c0c93480Slin wang - Sun Microsystems - Beijing China 	struct ath_atx_ac ac[WME_NUM_AC];
670dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t maxampdu;
671dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t mpdudensity;
672c0c93480Slin wang - Sun Microsystems - Beijing China 	int	last_rssi;
673dd1de374Slin wang - Sun Microsystems - Beijing China };
674dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_NODE(_n)	((struct ath_node *)(_n))
675dd1de374Slin wang - Sun Microsystems - Beijing China 
676dd1de374Slin wang - Sun Microsystems - Beijing China /*
677dd1de374Slin wang - Sun Microsystems - Beijing China  * Define the scheme that we select MAC address for multiple
678dd1de374Slin wang - Sun Microsystems - Beijing China  * BSS on the same radio. The very first VAP will just use the MAC
679dd1de374Slin wang - Sun Microsystems - Beijing China  * address from the EEPROM. For the next 3 VAPs, we set the
680dd1de374Slin wang - Sun Microsystems - Beijing China  * U/L bit (bit 1) in MAC address, and use the next two bits as the
681dd1de374Slin wang - Sun Microsystems - Beijing China  * index of the VAP.
682dd1de374Slin wang - Sun Microsystems - Beijing China  */
683dd1de374Slin wang - Sun Microsystems - Beijing China 
684dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_SET_VAP_BSSID_MASK(bssid_mask) \
685dd1de374Slin wang - Sun Microsystems - Beijing China 	((bssid_mask)[0] &= ~(((ATH_BCBUF-1)<<2)|0x02))
686dd1de374Slin wang - Sun Microsystems - Beijing China 
687dd1de374Slin wang - Sun Microsystems - Beijing China 
688dd1de374Slin wang - Sun Microsystems - Beijing China /* driver-specific vap state */
689dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_vap {
690dd1de374Slin wang - Sun Microsystems - Beijing China 	int av_bslot; /* beacon slot index */
691dd1de374Slin wang - Sun Microsystems - Beijing China 	enum ath9k_opmode av_opmode; /* VAP operational mode */
692dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_buf *av_bcbuf; /* beacon buffer */
693dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_tx_control av_btxctl; /* txctl information for beacon */
694dd1de374Slin wang - Sun Microsystems - Beijing China };
695dd1de374Slin wang - Sun Microsystems - Beijing China 
696dd1de374Slin wang - Sun Microsystems - Beijing China /* Beacon Handling */
697dd1de374Slin wang - Sun Microsystems - Beijing China 
698dd1de374Slin wang - Sun Microsystems - Beijing China /*
699dd1de374Slin wang - Sun Microsystems - Beijing China  * Regardless of the number of beacons we stagger, (i.e. regardless of the
700dd1de374Slin wang - Sun Microsystems - Beijing China  * number of BSSIDs) if a given beacon does not go out even after waiting this
701dd1de374Slin wang - Sun Microsystems - Beijing China  * number of beacon intervals, the game's up.
702dd1de374Slin wang - Sun Microsystems - Beijing China  */
703dd1de374Slin wang - Sun Microsystems - Beijing China #define	BSTUCK_THRESH		(9 * ATH_BCBUF)
704dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_BCBUF		4 /* number of beacon buffers */
705dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_DEFAULT_BINTVAL	100 /* default beacon interval in TU */
706dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_DEFAULT_BMISS_LIMIT	10
707dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_MS_TO_TU(x)	(((x) * 1000) / 1024)
708dd1de374Slin wang - Sun Microsystems - Beijing China 
709dd1de374Slin wang - Sun Microsystems - Beijing China /* beacon configuration */
710dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_beacon_config {
711dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t beacon_interval;
712dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t listen_interval;
713dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t dtim_period;
714dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t bmiss_timeout;
715dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t dtim_count;
716dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t tim_offset;
717dd1de374Slin wang - Sun Microsystems - Beijing China 	union {
718dd1de374Slin wang - Sun Microsystems - Beijing China 		uint64_t last_tsf;
719dd1de374Slin wang - Sun Microsystems - Beijing China 		uint8_t last_tstamp[8];
720dd1de374Slin wang - Sun Microsystems - Beijing China 	} u; /* last received beacon/probe response timestamp of this BSS. */
721dd1de374Slin wang - Sun Microsystems - Beijing China };
722dd1de374Slin wang - Sun Microsystems - Beijing China 
723dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t arn_beaconq_setup(struct ath_hal *ah);
724dd1de374Slin wang - Sun Microsystems - Beijing China int arn_beacon_alloc(struct arn_softc *sc, struct ieee80211_node *in);
725dd1de374Slin wang - Sun Microsystems - Beijing China void arn_beacon_config(struct arn_softc *sc);
726dd1de374Slin wang - Sun Microsystems - Beijing China void arn_beacon_return(struct arn_softc *sc);
727dd1de374Slin wang - Sun Microsystems - Beijing China void arn_beacon_sync(struct arn_softc *sc);
728dd1de374Slin wang - Sun Microsystems - Beijing China void arn_bmiss_proc(void *arg);
729dd1de374Slin wang - Sun Microsystems - Beijing China 
730dd1de374Slin wang - Sun Microsystems - Beijing China void arn_recv_mgmt(struct ieee80211com *ic, mblk_t *mp,
731dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ieee80211_node *in, int subtype, int rssi, uint32_t rstamp);
732dd1de374Slin wang - Sun Microsystems - Beijing China 
733dd1de374Slin wang - Sun Microsystems - Beijing China /* ANI */
734dd1de374Slin wang - Sun Microsystems - Beijing China 
735dd1de374Slin wang - Sun Microsystems - Beijing China /*
736dd1de374Slin wang - Sun Microsystems - Beijing China  * ANI values for STA only.
737dd1de374Slin wang - Sun Microsystems - Beijing China  * FIXME: Add appropriate values for AP later
738dd1de374Slin wang - Sun Microsystems - Beijing China  */
739dd1de374Slin wang - Sun Microsystems - Beijing China 
740dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_ANI_POLLINTERVAL	100	/* 100 milliseconds between ANI poll */
741dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_SHORT_CALINTERVAL	1000	/* 1 second between calibrations */
742dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_LONG_CALINTERVAL	30000	/* 30 seconds between calibrations */
743dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_RESTART_CALINTERVAL	1200000	/* 20 minutes between calibrations */
744dd1de374Slin wang - Sun Microsystems - Beijing China 
745dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_ani {
746dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t sc_caldone;
747dd1de374Slin wang - Sun Microsystems - Beijing China 	int16_t sc_noise_floor;
748dd1de374Slin wang - Sun Microsystems - Beijing China 	unsigned int sc_longcal_timer;
749dd1de374Slin wang - Sun Microsystems - Beijing China 	unsigned int sc_shortcal_timer;
750dd1de374Slin wang - Sun Microsystems - Beijing China 	unsigned int sc_resetcal_timer;
751dd1de374Slin wang - Sun Microsystems - Beijing China 	unsigned int sc_checkani_timer;
752dd1de374Slin wang - Sun Microsystems - Beijing China };
753dd1de374Slin wang - Sun Microsystems - Beijing China 
754dd1de374Slin wang - Sun Microsystems - Beijing China /* LED Control */
755dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_LED_PIN	1
756dd1de374Slin wang - Sun Microsystems - Beijing China 
757dd1de374Slin wang - Sun Microsystems - Beijing China enum ath_led_type {
758dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_LED_RADIO,
759dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_LED_ASSOC,
760dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_LED_TX,
761dd1de374Slin wang - Sun Microsystems - Beijing China 	ATH_LED_RX
762dd1de374Slin wang - Sun Microsystems - Beijing China };
763dd1de374Slin wang - Sun Microsystems - Beijing China 
764dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_led {
765dd1de374Slin wang - Sun Microsystems - Beijing China 	struct arn_softc *sc;
766dd1de374Slin wang - Sun Microsystems - Beijing China 	enum ath_led_type led_type;
767dd1de374Slin wang - Sun Microsystems - Beijing China 	char name[32];
768dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t registered;
769dd1de374Slin wang - Sun Microsystems - Beijing China };
770dd1de374Slin wang - Sun Microsystems - Beijing China 
771dd1de374Slin wang - Sun Microsystems - Beijing China /* Rfkill */
772dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_RFKILL_POLL_INTERVAL	2000 /* msecs */
773dd1de374Slin wang - Sun Microsystems - Beijing China 
774dd1de374Slin wang - Sun Microsystems - Beijing China /* Main driver core */
775dd1de374Slin wang - Sun Microsystems - Beijing China /*
776dd1de374Slin wang - Sun Microsystems - Beijing China  * Default cache line size, in bytes.
777dd1de374Slin wang - Sun Microsystems - Beijing China  * Used when PCI device not fully initialized by bootrom/BIOS
778dd1de374Slin wang - Sun Microsystems - Beijing China  */
779dd1de374Slin wang - Sun Microsystems - Beijing China #define	DEFAULT_CACHELINE	32
780dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_DEFAULT_NOISE_FLOOR	-95
781dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_REGCLASSIDS_MAX	10
782dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_CABQ_READY_TIME	80 /* % of beacon interval */
783dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_MAX_SW_RETRIES	10
784dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_CHAN_MAX		255
785dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_WEP_NKID	4 /* number of key ids */
786dd1de374Slin wang - Sun Microsystems - Beijing China #define	IEEE80211_RATE_VAL	0x7f
787dd1de374Slin wang - Sun Microsystems - Beijing China /*
788dd1de374Slin wang - Sun Microsystems - Beijing China  * The key cache is used for h/w cipher state and also for
789dd1de374Slin wang - Sun Microsystems - Beijing China  * tracking station state such as the current tx antenna.
790dd1de374Slin wang - Sun Microsystems - Beijing China  * We also setup a mapping table between key cache slot indices
791dd1de374Slin wang - Sun Microsystems - Beijing China  * and station state to short-circuit node lookups on rx.
792dd1de374Slin wang - Sun Microsystems - Beijing China  * Different parts have different size key caches.  We handle
793dd1de374Slin wang - Sun Microsystems - Beijing China  * up to ATH_KEYMAX entries (could dynamically allocate state).
794dd1de374Slin wang - Sun Microsystems - Beijing China  */
795dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_KEYMAX		128 /* max key cache size we handle */
796dd1de374Slin wang - Sun Microsystems - Beijing China 
797dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_IF_ID_ANY		0xff
798dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_TXPOWER_MAX		100 /* .5 dBm units */
799dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_RSSI_DUMMY_MARKER	0x127
800dd1de374Slin wang - Sun Microsystems - Beijing China #define	ATH_RATE_DUMMY_MARKER	0
801dd1de374Slin wang - Sun Microsystems - Beijing China 
802dd1de374Slin wang - Sun Microsystems - Beijing China enum PROT_MODE {
803dd1de374Slin wang - Sun Microsystems - Beijing China 	PROT_M_NONE = 0,
804dd1de374Slin wang - Sun Microsystems - Beijing China 	PROT_M_RTSCTS,
805dd1de374Slin wang - Sun Microsystems - Beijing China 	PROT_M_CTSONLY
806dd1de374Slin wang - Sun Microsystems - Beijing China };
807dd1de374Slin wang - Sun Microsystems - Beijing China 
808dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_INVALID		BIT(0)
809dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_BEACONS		BIT(1)
810dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_RXAGGR		BIT(2)
811dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_TXAGGR		BIT(3)
812dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_CHAINMASK_UPDATE	BIT(4)
813dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_FULL_RESET	BIT(5)
814dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_NO_RESET		BIT(6)
815dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_PREAMBLE_SHORT	BIT(7)
816dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_PROTECT_ENABLE	BIT(8)
817dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_RXFLUSH		BIT(9)
818dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_LED_ASSOCIATED	BIT(10)
819dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_RFKILL_REGISTERED	BIT(11)
820dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_RFKILL_SW_BLOCKED	BIT(12)
821dd1de374Slin wang - Sun Microsystems - Beijing China #define	SC_OP_RFKILL_HW_BLOCKED	BIT(13)
822dd1de374Slin wang - Sun Microsystems - Beijing China 
823c0c93480Slin wang - Sun Microsystems - Beijing China /* HT  */
824c0c93480Slin wang - Sun Microsystems - Beijing China typedef	struct ht_conf {
825c0c93480Slin wang - Sun Microsystems - Beijing China 	boolean_t		ht_supported;
826c0c93480Slin wang - Sun Microsystems - Beijing China 	uint16_t		cap;
827c0c93480Slin wang - Sun Microsystems - Beijing China 	uint8_t			ampdu_factor;
828c0c93480Slin wang - Sun Microsystems - Beijing China 	uint8_t			ampdu_density;
829c0c93480Slin wang - Sun Microsystems - Beijing China 	uint8_t			rx_mcs_mask[10];
830c0c93480Slin wang - Sun Microsystems - Beijing China } arn_ht_conf;
831c0c93480Slin wang - Sun Microsystems - Beijing China 
832c0c93480Slin wang - Sun Microsystems - Beijing China uint8_t parse_mpdudensity(uint8_t mpdudensity);
833c0c93480Slin wang - Sun Microsystems - Beijing China 
834c0c93480Slin wang - Sun Microsystems - Beijing China void arn_ampdu_recv_action(struct ieee80211_node *in,
835c0c93480Slin wang - Sun Microsystems - Beijing China     const uint8_t *frm, const uint8_t *efrm);
836c0c93480Slin wang - Sun Microsystems - Beijing China int arn_ampdu_send_action(struct ieee80211_node *in,
837c0c93480Slin wang - Sun Microsystems - Beijing China     int category, int action, uint16_t args[4]);
838c0c93480Slin wang - Sun Microsystems - Beijing China void arn_dump_line(unsigned char *p, uint32_t len, boolean_t isaddress,
839c0c93480Slin wang - Sun Microsystems - Beijing China     uint32_t group);
840c0c93480Slin wang - Sun Microsystems - Beijing China void arn_dump_pkg(unsigned char *p, uint32_t len, boolean_t isaddress,
841c0c93480Slin wang - Sun Microsystems - Beijing China     uint32_t group);
842c0c93480Slin wang - Sun Microsystems - Beijing China 
843dd1de374Slin wang - Sun Microsystems - Beijing China struct arn_softc {
844dd1de374Slin wang - Sun Microsystems - Beijing China 	ieee80211com_t sc_isc;	/* IEEE 802.11 common */
845dd1de374Slin wang - Sun Microsystems - Beijing China 	dev_info_t *sc_dev;    /* back pointer to dev_info_t */
846dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_taskq_t *sc_tq;    /* private task queue */
847dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal *sc_ah;
848dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_config sc_config;
849dd1de374Slin wang - Sun Microsystems - Beijing China 	caddr_t mem;
850dd1de374Slin wang - Sun Microsystems - Beijing China 
851dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t sc_isrunning; /* device is operational */
852dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t sc_mrretry;   /* multi-rate retry support */
853dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t sc_have11g;   /* have 11g support */
854dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t sc_bsync;	/* beacon sync */
855dd1de374Slin wang - Sun Microsystems - Beijing China 
856dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_acc_handle_t	sc_cfg_handle;    /* DDI I/O handle */
857dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_acc_handle_t	sc_io_handle;	   /* DDI I/O handle */
858dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_acc_handle_t	sc_EEPROM_handle; /* DDI I/O handle */
859dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_iblock_cookie_t	sc_iblock;
860dd1de374Slin wang - Sun Microsystems - Beijing China 	ddi_softintr_t		sc_softint_id;
861dd1de374Slin wang - Sun Microsystems - Beijing China 
862c0c93480Slin wang - Sun Microsystems - Beijing China 	/* 802.11n/HT capabilities */
863c0c93480Slin wang - Sun Microsystems - Beijing China 	arn_ht_conf		sc_ht_conf;
864c0c93480Slin wang - Sun Microsystems - Beijing China 	void			(*sc_recv_action)(ieee80211_node_t *,
865c0c93480Slin wang - Sun Microsystems - Beijing China 				    const uint8_t *, const uint8_t *);
866c0c93480Slin wang - Sun Microsystems - Beijing China 	int			(*sc_send_action)(ieee80211_node_t *,
867c0c93480Slin wang - Sun Microsystems - Beijing China 				    int, int, uint16_t[4]);
868c0c93480Slin wang - Sun Microsystems - Beijing China 
869dd1de374Slin wang - Sun Microsystems - Beijing China 	/* TX/RX descriptors */
870dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_desc *sc_desc;
871dd1de374Slin wang - Sun Microsystems - Beijing China 	/* descriptor structure */
872dd1de374