blob: e9720b14327536192b72fa282d97fa439eeb0a99 [file] [log] [blame]
Arnaldo Carvalho de Melo36729c12005-08-28 00:47:15 -03001#ifndef _TFRC_H_
2#define _TFRC_H_
3/*
4 * net/dccp/ccids/lib/tfrc.h
5 *
Gerrit Renkerc40616c2007-12-06 12:26:38 -02006 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
7 * Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
8 * Copyright (c) 2005-6 Ian McDonald <ian.mcdonald@jandi.co.nz>
9 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
10 * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
Arnaldo Carvalho de Melo36729c12005-08-28 00:47:15 -030011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
Arnaldo Carvalho de Melo36729c12005-08-28 00:47:15 -030017#include <linux/types.h>
Gerrit Renker7deb0f82008-06-11 11:19:10 +010018#include <linux/math64.h>
Gerrit Renkerc40616c2007-12-06 12:26:38 -020019#include "../../dccp.h"
Gerrit Renker129fa442009-01-04 21:45:33 -080020
21/* internal includes that this library exports: */
Gerrit Renker8a9c7e92007-12-12 13:50:51 -020022#include "loss_interval.h"
23#include "packet_history.h"
Gerrit Renkerc40616c2007-12-06 12:26:38 -020024
25#ifdef CONFIG_IP_DCCP_TFRC_DEBUG
26extern int tfrc_debug;
27#define tfrc_pr_debug(format, a...) DCCP_PR_DEBUG(tfrc_debug, format, ##a)
28#else
29#define tfrc_pr_debug(format, a...)
30#endif
Gerrit Renkerd63d8362006-12-10 00:04:16 -020031
32/* integer-arithmetic divisions of type (a * 1000000)/b */
Gerrit Renker7deb0f82008-06-11 11:19:10 +010033static inline u64 scaled_div(u64 a, u64 b)
Gerrit Renkerd63d8362006-12-10 00:04:16 -020034{
35 BUG_ON(b==0);
Gerrit Renker7deb0f82008-06-11 11:19:10 +010036 return div64_u64(a * 1000000, b);
Gerrit Renkerd63d8362006-12-10 00:04:16 -020037}
38
Gerrit Renker7deb0f82008-06-11 11:19:10 +010039static inline u32 scaled_div32(u64 a, u64 b)
Gerrit Renkerd63d8362006-12-10 00:04:16 -020040{
41 u64 result = scaled_div(a, b);
42
43 if (result > UINT_MAX) {
Gerrit Renker7deb0f82008-06-11 11:19:10 +010044 DCCP_CRIT("Overflow: %llu/%llu > UINT_MAX",
45 (unsigned long long)a, (unsigned long long)b);
Gerrit Renkerd63d8362006-12-10 00:04:16 -020046 return UINT_MAX;
47 }
48 return result;
49}
Arnaldo Carvalho de Melo36729c12005-08-28 00:47:15 -030050
Gerrit Renkerc3ada462007-11-20 18:09:59 -020051/**
52 * tfrc_ewma - Exponentially weighted moving average
53 * @weight: Weight to be used as damping factor, in units of 1/10
54 */
55static inline u32 tfrc_ewma(const u32 avg, const u32 newval, const u8 weight)
56{
57 return avg ? (weight * avg + (10 - weight) * newval) / 10 : newval;
58}
59
Gerrit Renker1e2f0e5e2008-06-11 11:19:09 +010060extern u32 tfrc_calc_x(u16 s, u32 R, u32 p);
61extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue);
Arnaldo Carvalho de Melo36729c12005-08-28 00:47:15 -030062
Gerrit Renker1e2f0e5e2008-06-11 11:19:09 +010063extern int tfrc_tx_packet_history_init(void);
64extern void tfrc_tx_packet_history_exit(void);
65extern int tfrc_rx_packet_history_init(void);
66extern void tfrc_rx_packet_history_exit(void);
67
68extern int tfrc_li_init(void);
69extern void tfrc_li_exit(void);
Gerrit Renker129fa442009-01-04 21:45:33 -080070
71#ifdef CONFIG_IP_DCCP_TFRC_LIB
72extern int tfrc_lib_init(void);
73extern void tfrc_lib_exit(void);
74#else
75#define tfrc_lib_init() (0)
76#define tfrc_lib_exit()
77#endif
Arnaldo Carvalho de Melo36729c12005-08-28 00:47:15 -030078#endif /* _TFRC_H_ */