xref: /haiku/src/libs/compat/freebsd_wlan/net80211/ieee80211_ht.h (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
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$
26  */
27 #ifndef _FBSD_COMPAT_NET80211_IEEE80211_HT_H_
28 #define _FBSD_COMPAT_NET80211_IEEE80211_HT_H_
29 
30 /*
31  * 802.11n protocol implementation definitions.
32  */
33 
34 void ieee80211_ht_init(void);
35 
36 #define	IEEE80211_AGGR_BAWMAX	64	/* max block ack window size */
37 /* threshold for aging overlapping non-HT bss */
38 #define	IEEE80211_NONHT_PRESENT_AGE	msecs_to_ticks(60*1000)
39 
40 struct ieee80211_tx_ampdu {
41 	struct ieee80211_node *txa_ni;	/* back pointer */
42 	u_short		txa_flags;
43 #define	IEEE80211_AGGR_IMMEDIATE	0x0001	/* BA policy */
44 #define	IEEE80211_AGGR_XCHGPEND		0x0002	/* ADDBA response pending */
45 #define	IEEE80211_AGGR_RUNNING		0x0004	/* ADDBA response received */
46 #define	IEEE80211_AGGR_SETUP		0x0008	/* deferred state setup */
47 #define	IEEE80211_AGGR_NAK		0x0010	/* peer NAK'd ADDBA request */
48 #define	IEEE80211_AGGR_BARPEND		0x0020	/* BAR response pending */
49 	uint8_t		txa_ac;
50 	uint8_t		txa_token;	/* dialog token */
51 	int		txa_lastsample;	/* ticks @ last traffic sample */
52 	int		txa_pkts;	/* packets over last sample interval */
53 	int		txa_avgpps;	/* filtered traffic over window */
54 	int		txa_qbytes;	/* data queued (bytes) */
55 	short		txa_qframes;	/* data queued (frames) */
56 	ieee80211_seq	txa_start;	/* BA window left edge */
57 	ieee80211_seq	txa_seqpending;	/* new txa_start pending BAR response */
58 	uint16_t	txa_wnd;	/* BA window size */
59 	uint8_t		txa_attempts;	/* # ADDBA/BAR requests w/o a response*/
60 	int		txa_nextrequest;/* soonest to make next request */
61 	struct callout	txa_timer;
62 	void		*txa_private;	/* driver-private storage */
63 	uint64_t	txa_pad[4];
64 };
65 
66 /* return non-zero if AMPDU tx for the TID is running */
67 #define	IEEE80211_AMPDU_RUNNING(tap) \
68 	(((tap)->txa_flags & IEEE80211_AGGR_RUNNING) != 0)
69 
70 /* return non-zero if AMPDU tx for the TID is running or started */
71 #define	IEEE80211_AMPDU_REQUESTED(tap) \
72 	(((tap)->txa_flags & \
73 	 (IEEE80211_AGGR_RUNNING|IEEE80211_AGGR_XCHGPEND|IEEE80211_AGGR_NAK)) != 0)
74 
75 #define	IEEE80211_AGGR_BITS \
76 	"\20\1IMMEDIATE\2XCHGPEND\3RUNNING\4SETUP\5NAK"
77 
78 /*
79  * Traffic estimator support.  We estimate packets/sec for
80  * each AC that is setup for AMPDU or will potentially be
81  * setup for AMPDU.  The traffic rate can be used to decide
82  * when AMPDU should be setup (according to a threshold)
83  * and is available for drivers to do things like cache
84  * eviction when only a limited number of BA streams are
85  * available and more streams are requested than available.
86  */
87 
88 static __inline void
89 ieee80211_txampdu_update_pps(struct ieee80211_tx_ampdu *tap)
90 {
91 	/* NB: scale factor of 2 was picked heuristically */
92 	tap->txa_avgpps = ((tap->txa_avgpps << 2) -
93 	     tap->txa_avgpps + tap->txa_pkts) >> 2;
94 }
95 
96 /*
97  * Count a packet towards the pps estimate.
98  */
99 static __inline void
100 ieee80211_txampdu_count_packet(struct ieee80211_tx_ampdu *tap)
101 {
102 	/* XXX bound loop/do more crude estimate? */
103 	while (ticks - tap->txa_lastsample >= hz) {
104 		ieee80211_txampdu_update_pps(tap);
105 		/* reset to start new sample interval */
106 		tap->txa_pkts = 0;
107 		if (tap->txa_avgpps == 0) {
108 			tap->txa_lastsample = ticks;
109 			break;
110 		}
111 		tap->txa_lastsample += hz;
112 	}
113 	tap->txa_pkts++;
114 }
115 
116 /*
117  * Get the current pps estimate.  If the average is out of
118  * date due to lack of traffic then we decay the estimate
119  * to account for the idle time.
120  */
121 static __inline int
122 ieee80211_txampdu_getpps(struct ieee80211_tx_ampdu *tap)
123 {
124 	/* XXX bound loop/do more crude estimate? */
125 	while (ticks - tap->txa_lastsample >= hz) {
126 		ieee80211_txampdu_update_pps(tap);
127 		tap->txa_pkts = 0;
128 		if (tap->txa_avgpps == 0) {
129 			tap->txa_lastsample = ticks;
130 			break;
131 		}
132 		tap->txa_lastsample += hz;
133 	}
134 	return tap->txa_avgpps;
135 }
136 
137 struct ieee80211_rx_ampdu {
138 	int		rxa_flags;
139 	int		rxa_qbytes;	/* data queued (bytes) */
140 	short		rxa_qframes;	/* data queued (frames) */
141 	ieee80211_seq	rxa_seqstart;
142 	ieee80211_seq	rxa_start;	/* start of current BA window */
143 	uint16_t	rxa_wnd;	/* BA window size */
144 	int		rxa_age;	/* age of oldest frame in window */
145 	int		rxa_nframes;	/* frames since ADDBA */
146 	struct mbuf *rxa_m[IEEE80211_AGGR_BAWMAX];
147 	uint64_t	rxa_pad[4];
148 };
149 
150 void	ieee80211_ht_attach(struct ieee80211com *);
151 void	ieee80211_ht_detach(struct ieee80211com *);
152 void	ieee80211_ht_vattach(struct ieee80211vap *);
153 void	ieee80211_ht_vdetach(struct ieee80211vap *);
154 
155 void	ieee80211_ht_announce(struct ieee80211com *);
156 
157 struct ieee80211_mcs_rates {
158 	uint16_t	ht20_rate_800ns;
159 	uint16_t	ht20_rate_400ns;
160 	uint16_t	ht40_rate_800ns;
161 	uint16_t	ht40_rate_400ns;
162 };
163 extern const struct ieee80211_mcs_rates ieee80211_htrates[16];
164 const struct ieee80211_htrateset *ieee80211_get_suphtrates(
165 		struct ieee80211com *, const struct ieee80211_channel *);
166 
167 struct ieee80211_node;
168 int	ieee80211_setup_htrates(struct ieee80211_node *,
169 		const uint8_t *htcap, int flags);
170 void	ieee80211_setup_basic_htrates(struct ieee80211_node *,
171 		const uint8_t *htinfo);
172 struct mbuf *ieee80211_decap_amsdu(struct ieee80211_node *, struct mbuf *);
173 int	ieee80211_ampdu_reorder(struct ieee80211_node *, struct mbuf *);
174 void	ieee80211_recv_bar(struct ieee80211_node *, struct mbuf *);
175 void	ieee80211_ht_node_init(struct ieee80211_node *);
176 void	ieee80211_ht_node_cleanup(struct ieee80211_node *);
177 void	ieee80211_ht_node_age(struct ieee80211_node *);
178 
179 struct ieee80211_channel *ieee80211_ht_adjust_channel(struct ieee80211com *,
180 		struct ieee80211_channel *, int);
181 void	ieee80211_ht_wds_init(struct ieee80211_node *);
182 void	ieee80211_ht_node_join(struct ieee80211_node *);
183 void	ieee80211_ht_node_leave(struct ieee80211_node *);
184 void	ieee80211_htprot_update(struct ieee80211com *, int protmode);
185 void	ieee80211_ht_timeout(struct ieee80211com *);
186 void	ieee80211_parse_htcap(struct ieee80211_node *, const uint8_t *);
187 void	ieee80211_parse_htinfo(struct ieee80211_node *, const uint8_t *);
188 void	ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *,
189 		const uint8_t *);
190 void	ieee80211_ht_updatehtcap(struct ieee80211_node *, const uint8_t *);
191 int	ieee80211_ampdu_request(struct ieee80211_node *,
192 		struct ieee80211_tx_ampdu *);
193 void	ieee80211_ampdu_stop(struct ieee80211_node *,
194 		struct ieee80211_tx_ampdu *, int);
195 int	ieee80211_send_bar(struct ieee80211_node *, struct ieee80211_tx_ampdu *,
196 		ieee80211_seq);
197 uint8_t	*ieee80211_add_htcap(uint8_t *, struct ieee80211_node *);
198 uint8_t	*ieee80211_add_htcap_vendor(uint8_t *, struct ieee80211_node *);
199 uint8_t	*ieee80211_add_htinfo(uint8_t *, struct ieee80211_node *);
200 uint8_t	*ieee80211_add_htinfo_vendor(uint8_t *, struct ieee80211_node *);
201 struct ieee80211_beacon_offsets;
202 void	ieee80211_ht_update_beacon(struct ieee80211vap *,
203 		struct ieee80211_beacon_offsets *);
204 #endif /* _FBSD_COMPAT_NET80211_IEEE80211_HT_H_ */
205