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