xref: /illumos-gate/usr/src/uts/common/io/ral/ral_rate.h (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above
15  *    copyright notice, this list of conditions and the following
16  *    disclaimer in the documentation and/or other materials provided
17  *    with the distribution.
18  * 3. The name of David Young may not be used to endorse or promote
19  *    products derived from this software without specific prior
20  *    written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL David
26  * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33  * OF SUCH DAMAGE.
34  */
35 #ifndef _RAL_RATE_H
36 #define	_RAL_RATE_H
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Data-rate adaptation loosely based on "Link Adaptation Strategy
44  * for IEEE 802.11 WLAN via Received Signal Strength Measurement"
45  * by Javier del Prado Pavon and Sunghyun Choi.
46  */
47 
48 /* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */
49 #define	RAL_RSSADAPT_BKTS		3
50 #define	RAL_RSSADAPT_BKT0		128
51 #define	RAL_RSSADAPT_BKTPOWER	3	/* 2**_BKTPOWER */
52 
53 #define	ral_rssadapt_thresh_new \
54 	(ral_rssadapt_thresh_denom - ral_rssadapt_thresh_old)
55 #define	ral_rssadapt_decay_new \
56 	(ral_rssadapt_decay_denom - ral_rssadapt_decay_old)
57 #define	ral_rssadapt_avgrssi_new \
58 	(ral_rssadapt_avgrssi_denom - ral_rssadapt_avgrssi_old)
59 
60 struct ral_rssadapt_expavgctl {
61 	/* RSS threshold decay. */
62 	uint32_t rc_decay_denom;
63 	uint32_t rc_decay_old;
64 	/* RSS threshold update. */
65 	uint32_t rc_thresh_denom;
66 	uint32_t rc_thresh_old;
67 	/* RSS average update. */
68 	uint32_t rc_avgrssi_denom;
69 	uint32_t rc_avgrssi_old;
70 };
71 
72 struct ral_rssadapt {
73 	/* exponential average RSSI << 8 */
74 	uint16_t		ra_avg_rssi;
75 	/* Tx failures in this update interval */
76 	uint32_t		ra_nfail;
77 	/* Tx successes in this update interval */
78 	uint32_t		ra_nok;
79 	/* exponential average packets/second */
80 	uint32_t		ra_pktrate;
81 	/* RSSI threshold for each Tx rate */
82 	uint16_t		ra_rate_thresh[RAL_RSSADAPT_BKTS]
83 				    [IEEE80211_RATE_SIZE];
84 	struct timeval		ra_last_raise;
85 	struct timeval		ra_raise_interval;
86 };
87 
88 /* Properties of a Tx packet, for link adaptation. */
89 struct ral_rssdesc {
90 	uint32_t		 id_len;	/* Tx packet length */
91 	uint32_t		 id_rateidx;	/* index into ni->ni_rates */
92 	struct ieee80211_node	*id_node;	/* destination STA MAC */
93 	uint8_t			 id_rssi;	/* dest STA avg RSS @Tx time */
94 };
95 
96 void	ral_rate_init(void);
97 void	ral_rssadapt_updatestats(struct ral_rssadapt *);
98 void	ral_rssadapt_input(struct ieee80211com *, struct ieee80211_node *,
99 	    struct ral_rssadapt *, int);
100 void	ral_rssadapt_lower_rate(struct ieee80211com *,
101 	    struct ieee80211_node *, struct ral_rssadapt *,
102 	    struct ral_rssdesc *);
103 void	ral_rssadapt_raise_rate(struct ieee80211com *,
104 	    struct ral_rssadapt *, struct ral_rssdesc *);
105 int	ral_rssadapt_choose(struct ral_rssadapt *,
106 	    struct ieee80211_rateset *, struct ieee80211_frame *, uint_t,
107 	    const char *, int);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* _RAL_RATE_H */
114