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