xref: /titanic_44/usr/src/uts/common/io/ral/ral_rate.h (revision fe598cdcd847f8359013532d5c691bb6190378c0)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Data-rate adaptation loosely based on "Link Adaptation Strategy
46  * for IEEE 802.11 WLAN via Received Signal Strength Measurement"
47  * by Javier del Prado Pavon and Sunghyun Choi.
48  */
49 
50 /* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */
51 #define	RAL_RSSADAPT_BKTS		3
52 #define	RAL_RSSADAPT_BKT0		128
53 #define	RAL_RSSADAPT_BKTPOWER	3	/* 2**_BKTPOWER */
54 
55 #define	ral_rssadapt_thresh_new \
56 	(ral_rssadapt_thresh_denom - ral_rssadapt_thresh_old)
57 #define	ral_rssadapt_decay_new \
58 	(ral_rssadapt_decay_denom - ral_rssadapt_decay_old)
59 #define	ral_rssadapt_avgrssi_new \
60 	(ral_rssadapt_avgrssi_denom - ral_rssadapt_avgrssi_old)
61 
62 struct ral_rssadapt_expavgctl {
63 	/* RSS threshold decay. */
64 	uint32_t rc_decay_denom;
65 	uint32_t rc_decay_old;
66 	/* RSS threshold update. */
67 	uint32_t rc_thresh_denom;
68 	uint32_t rc_thresh_old;
69 	/* RSS average update. */
70 	uint32_t rc_avgrssi_denom;
71 	uint32_t rc_avgrssi_old;
72 };
73 
74 struct ral_rssadapt {
75 	/* exponential average RSSI << 8 */
76 	uint16_t		ra_avg_rssi;
77 	/* Tx failures in this update interval */
78 	uint32_t		ra_nfail;
79 	/* Tx successes in this update interval */
80 	uint32_t		ra_nok;
81 	/* exponential average packets/second */
82 	uint32_t		ra_pktrate;
83 	/* RSSI threshold for each Tx rate */
84 	uint16_t		ra_rate_thresh[RAL_RSSADAPT_BKTS]
85 				    [IEEE80211_RATE_SIZE];
86 	struct timeval		ra_last_raise;
87 	struct timeval		ra_raise_interval;
88 };
89 
90 /* Properties of a Tx packet, for link adaptation. */
91 struct ral_rssdesc {
92 	uint32_t		 id_len;	/* Tx packet length */
93 	uint32_t		 id_rateidx;	/* index into ni->ni_rates */
94 	struct ieee80211_node	*id_node;	/* destination STA MAC */
95 	uint8_t			 id_rssi;	/* dest STA avg RSS @Tx time */
96 };
97 
98 void	ral_rate_init(void);
99 void	ral_rssadapt_updatestats(struct ral_rssadapt *);
100 void	ral_rssadapt_input(struct ieee80211com *, struct ieee80211_node *,
101 	    struct ral_rssadapt *, int);
102 void	ral_rssadapt_lower_rate(struct ieee80211com *,
103 	    struct ieee80211_node *, struct ral_rssadapt *,
104 	    struct ral_rssdesc *);
105 void	ral_rssadapt_raise_rate(struct ieee80211com *,
106 	    struct ral_rssadapt *, struct ral_rssdesc *);
107 int	ral_rssadapt_choose(struct ral_rssadapt *,
108 	    struct ieee80211_rateset *, struct ieee80211_frame *, uint_t,
109 	    const char *, int);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* _RAL_RATE_H */
116