xref: /freebsd/sys/net80211/ieee80211_ht.h (revision 0a48773f8c6108ad8755065c5cdc13fcdc0728b2)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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 #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 #define	IEEE80211_AGGR_WAITRX		0x0040	/* Wait for first RX frame to define BAW */
50 	uint8_t		txa_tid;
51 	uint8_t		txa_token;	/* dialog token */
52 	int		txa_lastsample;	/* ticks @ last traffic sample */
53 	int		txa_pkts;	/* packets over last sample interval */
54 	int		txa_avgpps;	/* filtered traffic over window */
55 	int		txa_qbytes;	/* data queued (bytes) */
56 	short		txa_qframes;	/* data queued (frames) */
57 	ieee80211_seq	txa_start;	/* BA window left edge */
58 	ieee80211_seq	txa_seqpending;	/* new txa_start pending BAR response */
59 	uint16_t	txa_wnd;	/* BA window size */
60 	uint8_t		txa_attempts;	/* # ADDBA/BAR requests w/o a response*/
61 	int		txa_nextrequest;/* soonest to make next request */
62 	struct callout	txa_timer;
63 	void		*txa_private;	/* driver-private storage */
64 	uint64_t	txa_pad[4];
65 };
66 
67 /* return non-zero if AMPDU tx for the TID is running */
68 #define	IEEE80211_AMPDU_RUNNING(tap) \
69 	(((tap)->txa_flags & IEEE80211_AGGR_RUNNING) != 0)
70 
71 /* return non-zero if AMPDU tx for the TID was NACKed */
72 #define	IEEE80211_AMPDU_NACKED(tap)\
73 	(!! ((tap)->txa_flags & IEEE80211_AGGR_NAK))
74 
75 /* return non-zero if AMPDU tx for the TID is running or started */
76 #define	IEEE80211_AMPDU_REQUESTED(tap) \
77 	(((tap)->txa_flags & \
78 	 (IEEE80211_AGGR_RUNNING|IEEE80211_AGGR_XCHGPEND|IEEE80211_AGGR_NAK)) != 0)
79 
80 #define	IEEE80211_AGGR_BITS \
81 	"\20\1IMMEDIATE\2XCHGPEND\3RUNNING\4SETUP\5NAK"
82 
83 /*
84  * Traffic estimator support.  We estimate packets/sec for
85  * each AC that is setup for AMPDU or will potentially be
86  * setup for AMPDU.  The traffic rate can be used to decide
87  * when AMPDU should be setup (according to a threshold)
88  * and is available for drivers to do things like cache
89  * eviction when only a limited number of BA streams are
90  * available and more streams are requested than available.
91  */
92 
93 static __inline void
94 ieee80211_txampdu_init_pps(struct ieee80211_tx_ampdu *tap)
95 {
96 	/*
97 	 * Reset packet estimate.
98 	 */
99 	tap->txa_lastsample = ticks;
100 	tap->txa_avgpps = 0;
101 }
102 
103 static __inline void
104 ieee80211_txampdu_update_pps(struct ieee80211_tx_ampdu *tap)
105 {
106 
107 	/* NB: scale factor of 2 was picked heuristically */
108 	tap->txa_avgpps = ((tap->txa_avgpps << 2) -
109 	     tap->txa_avgpps + tap->txa_pkts) >> 2;
110 }
111 
112 /*
113  * Count a packet towards the pps estimate.
114  */
115 static __inline void
116 ieee80211_txampdu_count_packet(struct ieee80211_tx_ampdu *tap)
117 {
118 
119 	/* XXX bound loop/do more crude estimate? */
120 	while (ticks - tap->txa_lastsample >= hz) {
121 		ieee80211_txampdu_update_pps(tap);
122 		/* reset to start new sample interval */
123 		tap->txa_pkts = 0;
124 		if (tap->txa_avgpps == 0) {
125 			tap->txa_lastsample = ticks;
126 			break;
127 		}
128 		tap->txa_lastsample += hz;
129 	}
130 	tap->txa_pkts++;
131 }
132 
133 /*
134  * Get the current pps estimate.  If the average is out of
135  * date due to lack of traffic then we decay the estimate
136  * to account for the idle time.
137  */
138 static __inline int
139 ieee80211_txampdu_getpps(struct ieee80211_tx_ampdu *tap)
140 {
141 	/* XXX bound loop/do more crude estimate? */
142 	while (ticks - tap->txa_lastsample >= hz) {
143 		ieee80211_txampdu_update_pps(tap);
144 		tap->txa_pkts = 0;
145 		if (tap->txa_avgpps == 0) {
146 			tap->txa_lastsample = ticks;
147 			break;
148 		}
149 		tap->txa_lastsample += hz;
150 	}
151 	return tap->txa_avgpps;
152 }
153 
154 struct ieee80211_rx_ampdu {
155 	int		rxa_flags;
156 	int		rxa_qbytes;	/* data queued (bytes) */
157 	short		rxa_qframes;	/* data queued (frames) */
158 	ieee80211_seq	rxa_seqstart;
159 	ieee80211_seq	rxa_start;	/* start of current BA window */
160 	uint16_t	rxa_wnd;	/* BA window size */
161 	int		rxa_age;	/* age of oldest frame in window */
162 	int		rxa_nframes;	/* frames since ADDBA */
163 	struct mbuf *rxa_m[IEEE80211_AGGR_BAWMAX];
164 	void		*rxa_private;
165 	uint64_t	rxa_pad[3];
166 };
167 
168 void	ieee80211_ht_attach(struct ieee80211com *);
169 void	ieee80211_ht_detach(struct ieee80211com *);
170 void	ieee80211_ht_vattach(struct ieee80211vap *);
171 void	ieee80211_ht_vdetach(struct ieee80211vap *);
172 
173 void	ieee80211_ht_announce(struct ieee80211com *);
174 
175 struct ieee80211_mcs_rates {
176 	uint16_t	ht20_rate_800ns;
177 	uint16_t	ht20_rate_400ns;
178 	uint16_t	ht40_rate_800ns;
179 	uint16_t	ht40_rate_400ns;
180 };
181 extern const struct ieee80211_mcs_rates ieee80211_htrates[];
182 void	ieee80211_init_suphtrates(struct ieee80211com *);
183 
184 struct ieee80211_node;
185 int	ieee80211_setup_htrates(struct ieee80211_node *,
186 		const uint8_t *htcap, int flags);
187 void	ieee80211_setup_basic_htrates(struct ieee80211_node *,
188 		const uint8_t *htinfo);
189 struct mbuf *ieee80211_decap_amsdu(struct ieee80211_node *, struct mbuf *);
190 int	ieee80211_ampdu_reorder(struct ieee80211_node *, struct mbuf *,
191 	    const struct ieee80211_rx_stats *);
192 void	ieee80211_recv_bar(struct ieee80211_node *, struct mbuf *);
193 void	ieee80211_ht_node_init(struct ieee80211_node *);
194 void	ieee80211_ht_node_cleanup(struct ieee80211_node *);
195 void	ieee80211_ht_node_age(struct ieee80211_node *);
196 
197 struct ieee80211_channel *ieee80211_ht_adjust_channel(struct ieee80211com *,
198 		struct ieee80211_channel *, int);
199 void	ieee80211_ht_wds_init(struct ieee80211_node *);
200 void	ieee80211_ht_node_join(struct ieee80211_node *);
201 void	ieee80211_ht_node_leave(struct ieee80211_node *);
202 void	ieee80211_htprot_update(struct ieee80211com *, int protmode);
203 void	ieee80211_ht_timeout(struct ieee80211com *);
204 void	ieee80211_parse_htcap(struct ieee80211_node *, const uint8_t *);
205 void	ieee80211_parse_htinfo(struct ieee80211_node *, const uint8_t *);
206 void	ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *,
207 		const uint8_t *);
208 int	ieee80211_ht_updateparams_final(struct ieee80211_node *,
209 	    const uint8_t *, const uint8_t *);
210 void	ieee80211_ht_updatehtcap(struct ieee80211_node *, const uint8_t *);
211 void	ieee80211_ht_updatehtcap_final(struct ieee80211_node *);
212 int	ieee80211_ampdu_request(struct ieee80211_node *,
213 		struct ieee80211_tx_ampdu *);
214 void	ieee80211_ampdu_stop(struct ieee80211_node *,
215 		struct ieee80211_tx_ampdu *, int);
216 int	ieee80211_send_bar(struct ieee80211_node *, struct ieee80211_tx_ampdu *,
217 		ieee80211_seq);
218 uint8_t	*ieee80211_add_htcap(uint8_t *, struct ieee80211_node *);
219 uint8_t	*ieee80211_add_htcap_ch(uint8_t *, struct ieee80211vap *,
220 	    struct ieee80211_channel *);
221 uint8_t	*ieee80211_add_htcap_vendor(uint8_t *, struct ieee80211_node *);
222 uint8_t	*ieee80211_add_htinfo(uint8_t *, struct ieee80211_node *);
223 uint8_t	*ieee80211_add_htinfo_vendor(uint8_t *, struct ieee80211_node *);
224 struct ieee80211_beacon_offsets;
225 void	ieee80211_ht_update_beacon(struct ieee80211vap *,
226 		struct ieee80211_beacon_offsets *);
227 int	ieee80211_ampdu_rx_start_ext(struct ieee80211_node *ni, int tid,
228 	    int seq, int baw);
229 void	ieee80211_ampdu_rx_stop_ext(struct ieee80211_node *ni, int tid);
230 int	ieee80211_ampdu_tx_request_ext(struct ieee80211_node *ni, int tid);
231 int	ieee80211_ampdu_tx_request_active_ext(struct ieee80211_node *ni,
232 	    int tid, int status);
233 
234 #endif /* _NET80211_IEEE80211_HT_H_ */
235