xref: /dflybsd-src/sys/netproto/802_11/ieee80211_ht.h (revision 4f655ef568316df0b575f05cebf37546415c0d24)
132176cfdSRui Paulo /*-
232176cfdSRui Paulo  * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
332176cfdSRui Paulo  * All rights reserved.
432176cfdSRui Paulo  *
532176cfdSRui Paulo  * Redistribution and use in source and binary forms, with or without
632176cfdSRui Paulo  * modification, are permitted provided that the following conditions
732176cfdSRui Paulo  * are met:
832176cfdSRui Paulo  * 1. Redistributions of source code must retain the above copyright
932176cfdSRui Paulo  *    notice, this list of conditions and the following disclaimer.
1032176cfdSRui Paulo  * 2. Redistributions in binary form must reproduce the above copyright
1132176cfdSRui Paulo  *    notice, this list of conditions and the following disclaimer in the
1232176cfdSRui Paulo  *    documentation and/or other materials provided with the distribution.
1332176cfdSRui Paulo  *
1432176cfdSRui Paulo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1532176cfdSRui Paulo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1632176cfdSRui Paulo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1732176cfdSRui Paulo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1832176cfdSRui Paulo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1932176cfdSRui Paulo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2032176cfdSRui Paulo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2132176cfdSRui Paulo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2232176cfdSRui Paulo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2332176cfdSRui Paulo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2432176cfdSRui Paulo  *
25085ff963SMatthew Dillon  * $FreeBSD$
2632176cfdSRui Paulo  */
2732176cfdSRui Paulo #ifndef _NET80211_IEEE80211_HT_H_
2832176cfdSRui Paulo #define _NET80211_IEEE80211_HT_H_
2932176cfdSRui Paulo 
3032176cfdSRui Paulo /*
3132176cfdSRui Paulo  * 802.11n protocol implementation definitions.
3232176cfdSRui Paulo  */
3332176cfdSRui Paulo 
3432176cfdSRui Paulo #define	IEEE80211_AGGR_BAWMAX	64	/* max block ack window size */
3532176cfdSRui Paulo /* threshold for aging overlapping non-HT bss */
3632176cfdSRui Paulo #define	IEEE80211_NONHT_PRESENT_AGE	msecs_to_ticks(60*1000)
3732176cfdSRui Paulo 
3832176cfdSRui Paulo struct ieee80211_tx_ampdu {
3932176cfdSRui Paulo 	struct ieee80211_node *txa_ni;	/* back pointer */
4032176cfdSRui Paulo 	u_short		txa_flags;
4132176cfdSRui Paulo #define	IEEE80211_AGGR_IMMEDIATE	0x0001	/* BA policy */
4232176cfdSRui Paulo #define	IEEE80211_AGGR_XCHGPEND		0x0002	/* ADDBA response pending */
4332176cfdSRui Paulo #define	IEEE80211_AGGR_RUNNING		0x0004	/* ADDBA response received */
4432176cfdSRui Paulo #define	IEEE80211_AGGR_SETUP		0x0008	/* deferred state setup */
4532176cfdSRui Paulo #define	IEEE80211_AGGR_NAK		0x0010	/* peer NAK'd ADDBA request */
4632176cfdSRui Paulo #define	IEEE80211_AGGR_BARPEND		0x0020	/* BAR response pending */
47085ff963SMatthew Dillon 	uint8_t		txa_tid;
4832176cfdSRui Paulo 	uint8_t		txa_token;	/* dialog token */
4932176cfdSRui Paulo 	int		txa_lastsample;	/* ticks @ last traffic sample */
5032176cfdSRui Paulo 	int		txa_pkts;	/* packets over last sample interval */
5132176cfdSRui Paulo 	int		txa_avgpps;	/* filtered traffic over window */
5232176cfdSRui Paulo 	int		txa_qbytes;	/* data queued (bytes) */
5332176cfdSRui Paulo 	short		txa_qframes;	/* data queued (frames) */
5432176cfdSRui Paulo 	ieee80211_seq	txa_start;	/* BA window left edge */
5532176cfdSRui Paulo 	ieee80211_seq	txa_seqpending;	/* new txa_start pending BAR response */
5632176cfdSRui Paulo 	uint16_t	txa_wnd;	/* BA window size */
5732176cfdSRui Paulo 	uint8_t		txa_attempts;	/* # ADDBA/BAR requests w/o a response*/
5832176cfdSRui Paulo 	int		txa_nextrequest;/* soonest to make next request */
5932176cfdSRui Paulo 	struct callout	txa_timer;
6032176cfdSRui Paulo 	void		*txa_private;	/* driver-private storage */
6132176cfdSRui Paulo 	uint64_t	txa_pad[4];
6232176cfdSRui Paulo };
6332176cfdSRui Paulo 
6432176cfdSRui Paulo /* return non-zero if AMPDU tx for the TID is running */
6532176cfdSRui Paulo #define	IEEE80211_AMPDU_RUNNING(tap) \
6632176cfdSRui Paulo 	(((tap)->txa_flags & IEEE80211_AGGR_RUNNING) != 0)
6732176cfdSRui Paulo 
68*4f655ef5SMatthew Dillon /* return non-zero if AMPDU tx for the TID was NACKed */
69*4f655ef5SMatthew Dillon #define	IEEE80211_AMPDU_NACKED(tap)\
70*4f655ef5SMatthew Dillon 	(!! ((tap)->txa_flags & IEEE80211_AGGR_NAK))
71*4f655ef5SMatthew Dillon 
7232176cfdSRui Paulo /* return non-zero if AMPDU tx for the TID is running or started */
7332176cfdSRui Paulo #define	IEEE80211_AMPDU_REQUESTED(tap) \
7432176cfdSRui Paulo 	(((tap)->txa_flags & \
7532176cfdSRui Paulo 	 (IEEE80211_AGGR_RUNNING|IEEE80211_AGGR_XCHGPEND|IEEE80211_AGGR_NAK)) != 0)
7632176cfdSRui Paulo 
7732176cfdSRui Paulo #define	IEEE80211_AGGR_BITS \
7832176cfdSRui Paulo 	"\20\1IMMEDIATE\2XCHGPEND\3RUNNING\4SETUP\5NAK"
7932176cfdSRui Paulo 
8032176cfdSRui Paulo /*
8132176cfdSRui Paulo  * Traffic estimator support.  We estimate packets/sec for
8232176cfdSRui Paulo  * each AC that is setup for AMPDU or will potentially be
8332176cfdSRui Paulo  * setup for AMPDU.  The traffic rate can be used to decide
8432176cfdSRui Paulo  * when AMPDU should be setup (according to a threshold)
8532176cfdSRui Paulo  * and is available for drivers to do things like cache
8632176cfdSRui Paulo  * eviction when only a limited number of BA streams are
8732176cfdSRui Paulo  * available and more streams are requested than available.
8832176cfdSRui Paulo  */
8932176cfdSRui Paulo 
9032176cfdSRui Paulo static __inline void
ieee80211_txampdu_init_pps(struct ieee80211_tx_ampdu * tap)91*4f655ef5SMatthew Dillon ieee80211_txampdu_init_pps(struct ieee80211_tx_ampdu *tap)
92*4f655ef5SMatthew Dillon {
93*4f655ef5SMatthew Dillon 	/*
94*4f655ef5SMatthew Dillon 	 * Reset packet estimate.
95*4f655ef5SMatthew Dillon 	 */
96*4f655ef5SMatthew Dillon 	tap->txa_lastsample = ticks;
97*4f655ef5SMatthew Dillon 	tap->txa_avgpps = 0;
98*4f655ef5SMatthew Dillon }
99*4f655ef5SMatthew Dillon 
100*4f655ef5SMatthew Dillon static __inline void
ieee80211_txampdu_update_pps(struct ieee80211_tx_ampdu * tap)10132176cfdSRui Paulo ieee80211_txampdu_update_pps(struct ieee80211_tx_ampdu *tap)
10232176cfdSRui Paulo {
103*4f655ef5SMatthew Dillon 
10432176cfdSRui Paulo 	/* NB: scale factor of 2 was picked heuristically */
10532176cfdSRui Paulo 	tap->txa_avgpps = ((tap->txa_avgpps << 2) -
10632176cfdSRui Paulo 	     tap->txa_avgpps + tap->txa_pkts) >> 2;
10732176cfdSRui Paulo }
10832176cfdSRui Paulo 
10932176cfdSRui Paulo /*
11032176cfdSRui Paulo  * Count a packet towards the pps estimate.
11132176cfdSRui Paulo  */
11232176cfdSRui Paulo static __inline void
ieee80211_txampdu_count_packet(struct ieee80211_tx_ampdu * tap)11332176cfdSRui Paulo ieee80211_txampdu_count_packet(struct ieee80211_tx_ampdu *tap)
11432176cfdSRui Paulo {
115*4f655ef5SMatthew Dillon 
11632176cfdSRui Paulo 	/* XXX bound loop/do more crude estimate? */
11732176cfdSRui Paulo 	while (ticks - tap->txa_lastsample >= hz) {
11832176cfdSRui Paulo 		ieee80211_txampdu_update_pps(tap);
11932176cfdSRui Paulo 		/* reset to start new sample interval */
12032176cfdSRui Paulo 		tap->txa_pkts = 0;
12132176cfdSRui Paulo 		if (tap->txa_avgpps == 0) {
12232176cfdSRui Paulo 			tap->txa_lastsample = ticks;
12332176cfdSRui Paulo 			break;
12432176cfdSRui Paulo 		}
12532176cfdSRui Paulo 		tap->txa_lastsample += hz;
12632176cfdSRui Paulo 	}
12732176cfdSRui Paulo 	tap->txa_pkts++;
12832176cfdSRui Paulo }
12932176cfdSRui Paulo 
13032176cfdSRui Paulo /*
13132176cfdSRui Paulo  * Get the current pps estimate.  If the average is out of
13232176cfdSRui Paulo  * date due to lack of traffic then we decay the estimate
13332176cfdSRui Paulo  * to account for the idle time.
13432176cfdSRui Paulo  */
13532176cfdSRui Paulo static __inline int
ieee80211_txampdu_getpps(struct ieee80211_tx_ampdu * tap)13632176cfdSRui Paulo ieee80211_txampdu_getpps(struct ieee80211_tx_ampdu *tap)
13732176cfdSRui Paulo {
13832176cfdSRui Paulo 	/* XXX bound loop/do more crude estimate? */
13932176cfdSRui Paulo 	while (ticks - tap->txa_lastsample >= hz) {
14032176cfdSRui Paulo 		ieee80211_txampdu_update_pps(tap);
14132176cfdSRui Paulo 		tap->txa_pkts = 0;
14232176cfdSRui Paulo 		if (tap->txa_avgpps == 0) {
14332176cfdSRui Paulo 			tap->txa_lastsample = ticks;
14432176cfdSRui Paulo 			break;
14532176cfdSRui Paulo 		}
14632176cfdSRui Paulo 		tap->txa_lastsample += hz;
14732176cfdSRui Paulo 	}
14832176cfdSRui Paulo 	return tap->txa_avgpps;
14932176cfdSRui Paulo }
15032176cfdSRui Paulo 
15132176cfdSRui Paulo struct ieee80211_rx_ampdu {
15232176cfdSRui Paulo 	int		rxa_flags;
15332176cfdSRui Paulo 	int		rxa_qbytes;	/* data queued (bytes) */
15432176cfdSRui Paulo 	short		rxa_qframes;	/* data queued (frames) */
15532176cfdSRui Paulo 	ieee80211_seq	rxa_seqstart;
15632176cfdSRui Paulo 	ieee80211_seq	rxa_start;	/* start of current BA window */
15732176cfdSRui Paulo 	uint16_t	rxa_wnd;	/* BA window size */
15832176cfdSRui Paulo 	int		rxa_age;	/* age of oldest frame in window */
15932176cfdSRui Paulo 	int		rxa_nframes;	/* frames since ADDBA */
16032176cfdSRui Paulo 	struct mbuf *rxa_m[IEEE80211_AGGR_BAWMAX];
161085ff963SMatthew Dillon 	void		*rxa_private;
162085ff963SMatthew Dillon 	uint64_t	rxa_pad[3];
16332176cfdSRui Paulo };
16432176cfdSRui Paulo 
16532176cfdSRui Paulo void	ieee80211_ht_attach(struct ieee80211com *);
16632176cfdSRui Paulo void	ieee80211_ht_detach(struct ieee80211com *);
16732176cfdSRui Paulo void	ieee80211_ht_vattach(struct ieee80211vap *);
16832176cfdSRui Paulo void	ieee80211_ht_vdetach(struct ieee80211vap *);
16932176cfdSRui Paulo 
17032176cfdSRui Paulo void	ieee80211_ht_announce(struct ieee80211com *);
17132176cfdSRui Paulo 
17232176cfdSRui Paulo struct ieee80211_mcs_rates {
17332176cfdSRui Paulo 	uint16_t	ht20_rate_800ns;
17432176cfdSRui Paulo 	uint16_t	ht20_rate_400ns;
17532176cfdSRui Paulo 	uint16_t	ht40_rate_800ns;
17632176cfdSRui Paulo 	uint16_t	ht40_rate_400ns;
17732176cfdSRui Paulo };
178085ff963SMatthew Dillon extern const struct ieee80211_mcs_rates ieee80211_htrates[];
17932176cfdSRui Paulo const struct ieee80211_htrateset *ieee80211_get_suphtrates(
18032176cfdSRui Paulo 		struct ieee80211com *, const struct ieee80211_channel *);
18132176cfdSRui Paulo 
18232176cfdSRui Paulo struct ieee80211_node;
18332176cfdSRui Paulo int	ieee80211_setup_htrates(struct ieee80211_node *,
18432176cfdSRui Paulo 		const uint8_t *htcap, int flags);
18532176cfdSRui Paulo void	ieee80211_setup_basic_htrates(struct ieee80211_node *,
18632176cfdSRui Paulo 		const uint8_t *htinfo);
18732176cfdSRui Paulo struct mbuf *ieee80211_decap_amsdu(struct ieee80211_node *, struct mbuf *);
18832176cfdSRui Paulo int	ieee80211_ampdu_reorder(struct ieee80211_node *, struct mbuf *);
18932176cfdSRui Paulo void	ieee80211_recv_bar(struct ieee80211_node *, struct mbuf *);
19032176cfdSRui Paulo void	ieee80211_ht_node_init(struct ieee80211_node *);
19132176cfdSRui Paulo void	ieee80211_ht_node_cleanup(struct ieee80211_node *);
19232176cfdSRui Paulo void	ieee80211_ht_node_age(struct ieee80211_node *);
19332176cfdSRui Paulo 
19432176cfdSRui Paulo struct ieee80211_channel *ieee80211_ht_adjust_channel(struct ieee80211com *,
19532176cfdSRui Paulo 		struct ieee80211_channel *, int);
19632176cfdSRui Paulo void	ieee80211_ht_wds_init(struct ieee80211_node *);
19732176cfdSRui Paulo void	ieee80211_ht_node_join(struct ieee80211_node *);
19832176cfdSRui Paulo void	ieee80211_ht_node_leave(struct ieee80211_node *);
19932176cfdSRui Paulo void	ieee80211_htprot_update(struct ieee80211com *, int protmode);
20032176cfdSRui Paulo void	ieee80211_ht_timeout(struct ieee80211com *);
20132176cfdSRui Paulo void	ieee80211_parse_htcap(struct ieee80211_node *, const uint8_t *);
20232176cfdSRui Paulo void	ieee80211_parse_htinfo(struct ieee80211_node *, const uint8_t *);
203085ff963SMatthew Dillon int	ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *,
20432176cfdSRui Paulo 		const uint8_t *);
20532176cfdSRui Paulo void	ieee80211_ht_updatehtcap(struct ieee80211_node *, const uint8_t *);
20632176cfdSRui Paulo int	ieee80211_ampdu_request(struct ieee80211_node *,
20732176cfdSRui Paulo 		struct ieee80211_tx_ampdu *);
20832176cfdSRui Paulo void	ieee80211_ampdu_stop(struct ieee80211_node *,
20932176cfdSRui Paulo 		struct ieee80211_tx_ampdu *, int);
21032176cfdSRui Paulo int	ieee80211_send_bar(struct ieee80211_node *, struct ieee80211_tx_ampdu *,
21132176cfdSRui Paulo 		ieee80211_seq);
21232176cfdSRui Paulo uint8_t	*ieee80211_add_htcap(uint8_t *, struct ieee80211_node *);
21332176cfdSRui Paulo uint8_t	*ieee80211_add_htcap_vendor(uint8_t *, struct ieee80211_node *);
21432176cfdSRui Paulo uint8_t	*ieee80211_add_htinfo(uint8_t *, struct ieee80211_node *);
21532176cfdSRui Paulo uint8_t	*ieee80211_add_htinfo_vendor(uint8_t *, struct ieee80211_node *);
21632176cfdSRui Paulo struct ieee80211_beacon_offsets;
21732176cfdSRui Paulo void	ieee80211_ht_update_beacon(struct ieee80211vap *,
21832176cfdSRui Paulo 		struct ieee80211_beacon_offsets *);
219*4f655ef5SMatthew Dillon int	ieee80211_ampdu_rx_start_ext(struct ieee80211_node *ni, int tid,
220*4f655ef5SMatthew Dillon 	    int seq, int baw);
221*4f655ef5SMatthew Dillon int	ieee80211_ampdu_tx_request_ext(struct ieee80211_node *ni, int tid);
222*4f655ef5SMatthew Dillon int	ieee80211_ampdu_tx_request_active_ext(struct ieee80211_node *ni,
223*4f655ef5SMatthew Dillon 	    int tid, int status);
224*4f655ef5SMatthew Dillon 
22532176cfdSRui Paulo #endif /* _NET80211_IEEE80211_HT_H_ */
226