ieee80211_ht.h revision 191756
1/*-
2 * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD: head/sys/net80211/ieee80211_ht.h 191756 2009-05-02 20:25:22Z sam $
26 */
27#ifndef _NET80211_IEEE80211_HT_H_
28#define _NET80211_IEEE80211_HT_H_
29
30/*
31 * 802.11n protocol implementation definitions.
32 */
33
34#define	IEEE80211_AGGR_BAWMAX	64	/* max block ack window size */
35/* threshold for aging overlapping non-HT bss */
36#define	IEEE80211_NONHT_PRESENT_AGE	msecs_to_ticks(60*1000)
37
38struct ieee80211_tx_ampdu {
39	struct ieee80211_node *txa_ni;	/* back pointer */
40	u_short		txa_flags;
41#define	IEEE80211_AGGR_IMMEDIATE	0x0001	/* BA policy */
42#define	IEEE80211_AGGR_XCHGPEND		0x0002	/* ADDBA response pending */
43#define	IEEE80211_AGGR_RUNNING		0x0004	/* ADDBA response received */
44#define	IEEE80211_AGGR_SETUP		0x0008	/* deferred state setup */
45#define	IEEE80211_AGGR_NAK		0x0010	/* peer NAK'd ADDBA request */
46#define	IEEE80211_AGGR_BARPEND		0x0020	/* BAR response pending */
47	uint8_t		txa_ac;
48	uint8_t		txa_token;	/* dialog token */
49	int		txa_lastsample;	/* ticks @ last traffic sample */
50	int		txa_pkts;	/* packets over last sample interval */
51	int		txa_avgpps;	/* filtered traffic over window */
52	int		txa_qbytes;	/* data queued (bytes) */
53	short		txa_qframes;	/* data queued (frames) */
54	ieee80211_seq	txa_start;	/* BA window left edge */
55	ieee80211_seq	txa_seqpending;	/* new txa_start pending BAR response */
56	uint16_t	txa_wnd;	/* BA window size */
57	uint8_t		txa_attempts;	/* # ADDBA/BAR requests w/o a response*/
58	int		txa_nextrequest;/* soonest to make next request */
59	struct callout	txa_timer;
60	void		*txa_private;	/* driver-private storage */
61};
62
63/* return non-zero if AMPDU tx for the TID is running */
64#define	IEEE80211_AMPDU_RUNNING(tap) \
65	(((tap)->txa_flags & IEEE80211_AGGR_RUNNING) != 0)
66
67/* return non-zero if AMPDU tx for the TID is running or started */
68#define	IEEE80211_AMPDU_REQUESTED(tap) \
69	(((tap)->txa_flags & \
70	 (IEEE80211_AGGR_RUNNING|IEEE80211_AGGR_XCHGPEND|IEEE80211_AGGR_NAK)) != 0)
71
72#define	IEEE80211_AGGR_BITS \
73	"\20\1IMMEDIATE\2XCHGPEND\3RUNNING\4SETUP\5NAK"
74
75/*
76 * Traffic estimator support.  We estimate packets/sec for
77 * each AC that is setup for AMPDU or will potentially be
78 * setup for AMPDU.  The traffic rate can be used to decide
79 * when AMPDU should be setup (according to a threshold)
80 * and is available for drivers to do things like cache
81 * eviction when only a limited number of BA streams are
82 * available and more streams are requested than available.
83 */
84
85static __inline void
86ieee80211_txampdu_update_pps(struct ieee80211_tx_ampdu *tap)
87{
88	/* NB: scale factor of 2 was picked heuristically */
89	tap->txa_avgpps = ((tap->txa_avgpps << 2) -
90	     tap->txa_avgpps + tap->txa_pkts) >> 2;
91}
92
93/*
94 * Count a packet towards the pps estimate.
95 */
96static __inline void
97ieee80211_txampdu_count_packet(struct ieee80211_tx_ampdu *tap)
98{
99	/* XXX bound loop/do more crude estimate? */
100	while (ticks - tap->txa_lastsample >= hz) {
101		ieee80211_txampdu_update_pps(tap);
102		/* reset to start new sample interval */
103		tap->txa_pkts = 0;
104		if (tap->txa_avgpps == 0) {
105			tap->txa_lastsample = ticks;
106			break;
107		}
108		tap->txa_lastsample += hz;
109	}
110	tap->txa_pkts++;
111}
112
113/*
114 * Get the current pps estimate.  If the average is out of
115 * date due to lack of traffic then we decay the estimate
116 * to account for the idle time.
117 */
118static __inline int
119ieee80211_txampdu_getpps(struct ieee80211_tx_ampdu *tap)
120{
121	/* XXX bound loop/do more crude estimate? */
122	while (ticks - tap->txa_lastsample >= hz) {
123		ieee80211_txampdu_update_pps(tap);
124		tap->txa_pkts = 0;
125		if (tap->txa_avgpps == 0) {
126			tap->txa_lastsample = ticks;
127			break;
128		}
129		tap->txa_lastsample += hz;
130	}
131	return tap->txa_avgpps;
132}
133
134struct ieee80211_rx_ampdu {
135	int		rxa_flags;
136	int		rxa_qbytes;	/* data queued (bytes) */
137	short		rxa_qframes;	/* data queued (frames) */
138	ieee80211_seq	rxa_seqstart;
139	ieee80211_seq	rxa_start;	/* start of current BA window */
140	uint16_t	rxa_wnd;	/* BA window size */
141	int		rxa_age;	/* age of oldest frame in window */
142	int		rxa_nframes;	/* frames since ADDBA */
143	struct mbuf *rxa_m[IEEE80211_AGGR_BAWMAX];
144};
145
146void	ieee80211_ht_attach(struct ieee80211com *);
147void	ieee80211_ht_detach(struct ieee80211com *);
148void	ieee80211_ht_vattach(struct ieee80211vap *);
149void	ieee80211_ht_vdetach(struct ieee80211vap *);
150
151void	ieee80211_ht_announce(struct ieee80211com *);
152
153struct ieee80211_mcs_rates {
154	uint16_t	ht20_rate_800ns;
155	uint16_t	ht20_rate_400ns;
156	uint16_t	ht40_rate_800ns;
157	uint16_t	ht40_rate_400ns;
158};
159extern const struct ieee80211_mcs_rates ieee80211_htrates[16];
160const struct ieee80211_htrateset *ieee80211_get_suphtrates(
161		struct ieee80211com *, const struct ieee80211_channel *);
162
163struct ieee80211_node;
164int	ieee80211_setup_htrates(struct ieee80211_node *,
165		const uint8_t *htcap, int flags);
166void	ieee80211_setup_basic_htrates(struct ieee80211_node *,
167		const uint8_t *htinfo);
168struct mbuf *ieee80211_decap_amsdu(struct ieee80211_node *, struct mbuf *);
169int	ieee80211_ampdu_reorder(struct ieee80211_node *, struct mbuf *);
170void	ieee80211_recv_bar(struct ieee80211_node *, struct mbuf *);
171void	ieee80211_ht_node_init(struct ieee80211_node *);
172void	ieee80211_ht_node_cleanup(struct ieee80211_node *);
173void	ieee80211_ht_node_age(struct ieee80211_node *);
174
175struct ieee80211_channel *ieee80211_ht_adjust_channel(struct ieee80211com *,
176		struct ieee80211_channel *, int);
177void	ieee80211_ht_wds_init(struct ieee80211_node *);
178void	ieee80211_ht_node_join(struct ieee80211_node *);
179void	ieee80211_ht_node_leave(struct ieee80211_node *);
180void	ieee80211_htprot_update(struct ieee80211com *, int protmode);
181void	ieee80211_ht_timeout(struct ieee80211com *);
182void	ieee80211_parse_htcap(struct ieee80211_node *, const uint8_t *);
183void	ieee80211_parse_htinfo(struct ieee80211_node *, const uint8_t *);
184void	ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *,
185		const uint8_t *);
186void	ieee80211_ht_updatehtcap(struct ieee80211_node *, const uint8_t *);
187void	ieee80211_recv_action(struct ieee80211_node *,
188		const uint8_t *, const uint8_t *);
189int	ieee80211_ampdu_request(struct ieee80211_node *,
190		struct ieee80211_tx_ampdu *);
191void	ieee80211_ampdu_stop(struct ieee80211_node *,
192		struct ieee80211_tx_ampdu *, int);
193int	ieee80211_send_bar(struct ieee80211_node *, struct ieee80211_tx_ampdu *,
194		ieee80211_seq);
195int	ieee80211_send_action(struct ieee80211_node *,
196		int, int, uint16_t [4]);
197uint8_t	*ieee80211_add_htcap(uint8_t *, struct ieee80211_node *);
198uint8_t	*ieee80211_add_htcap_vendor(uint8_t *, struct ieee80211_node *);
199uint8_t	*ieee80211_add_htinfo(uint8_t *, struct ieee80211_node *);
200uint8_t	*ieee80211_add_htinfo_vendor(uint8_t *, struct ieee80211_node *);
201struct ieee80211_beacon_offsets;
202void	ieee80211_ht_update_beacon(struct ieee80211vap *,
203		struct ieee80211_beacon_offsets *);
204#endif /* _NET80211_IEEE80211_HT_H_ */
205