18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 48c2ecf20Sopenharmony_ci * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * An implementation of the DCCP protocol 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * This code has been developed by the University of Waikato WAND 98c2ecf20Sopenharmony_ci * research group. For further information please see https://www.wand.net.nz/ 108c2ecf20Sopenharmony_ci * or e-mail Ian McDonald - ian.mcdonald@jandi.co.nz 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This code also uses code from Lulea University, rereleased as GPL by its 138c2ecf20Sopenharmony_ci * authors: 148c2ecf20Sopenharmony_ci * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * Changes to meet Linux coding standards, to make it meet latest ccid3 draft 178c2ecf20Sopenharmony_ci * and to make it work as a loadable module in the DCCP stack written by 188c2ecf20Sopenharmony_ci * Arnaldo Carvalho de Melo <acme@conectiva.com.br>. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci#ifndef _DCCP_CCID3_H_ 238c2ecf20Sopenharmony_ci#define _DCCP_CCID3_H_ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include <linux/ktime.h> 268c2ecf20Sopenharmony_ci#include <linux/list.h> 278c2ecf20Sopenharmony_ci#include <linux/types.h> 288c2ecf20Sopenharmony_ci#include <linux/tfrc.h> 298c2ecf20Sopenharmony_ci#include "lib/tfrc.h" 308c2ecf20Sopenharmony_ci#include "../ccid.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* Two seconds as per RFC 5348, 4.2 */ 338c2ecf20Sopenharmony_ci#define TFRC_INITIAL_TIMEOUT (2 * USEC_PER_SEC) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* Parameter t_mbi from [RFC 3448, 4.3]: backoff interval in seconds */ 368c2ecf20Sopenharmony_ci#define TFRC_T_MBI 64 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* 398c2ecf20Sopenharmony_ci * The t_delta parameter (RFC 5348, 8.3): delays of less than %USEC_PER_MSEC are 408c2ecf20Sopenharmony_ci * rounded down to 0, since sk_reset_timer() here uses millisecond granularity. 418c2ecf20Sopenharmony_ci * Hence we can use a constant t_delta = %USEC_PER_MSEC when HZ >= 500. A coarse 428c2ecf20Sopenharmony_ci * resolution of HZ < 500 means that the error is below one timer tick (t_gran) 438c2ecf20Sopenharmony_ci * when using the constant t_delta = t_gran / 2 = %USEC_PER_SEC / (2 * HZ). 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ci#if (HZ >= 500) 468c2ecf20Sopenharmony_ci# define TFRC_T_DELTA USEC_PER_MSEC 478c2ecf20Sopenharmony_ci#else 488c2ecf20Sopenharmony_ci# define TFRC_T_DELTA (USEC_PER_SEC / (2 * HZ)) 498c2ecf20Sopenharmony_ci#endif 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cienum ccid3_options { 528c2ecf20Sopenharmony_ci TFRC_OPT_LOSS_EVENT_RATE = 192, 538c2ecf20Sopenharmony_ci TFRC_OPT_LOSS_INTERVALS = 193, 548c2ecf20Sopenharmony_ci TFRC_OPT_RECEIVE_RATE = 194, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* TFRC sender states */ 588c2ecf20Sopenharmony_cienum ccid3_hc_tx_states { 598c2ecf20Sopenharmony_ci TFRC_SSTATE_NO_SENT = 1, 608c2ecf20Sopenharmony_ci TFRC_SSTATE_NO_FBACK, 618c2ecf20Sopenharmony_ci TFRC_SSTATE_FBACK, 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/** 658c2ecf20Sopenharmony_ci * struct ccid3_hc_tx_sock - CCID3 sender half-connection socket 668c2ecf20Sopenharmony_ci * @tx_x: Current sending rate in 64 * bytes per second 678c2ecf20Sopenharmony_ci * @tx_x_recv: Receive rate in 64 * bytes per second 688c2ecf20Sopenharmony_ci * @tx_x_calc: Calculated rate in bytes per second 698c2ecf20Sopenharmony_ci * @tx_rtt: Estimate of current round trip time in usecs 708c2ecf20Sopenharmony_ci * @tx_p: Current loss event rate (0-1) scaled by 1000000 718c2ecf20Sopenharmony_ci * @tx_s: Packet size in bytes 728c2ecf20Sopenharmony_ci * @tx_t_rto: Nofeedback Timer setting in usecs 738c2ecf20Sopenharmony_ci * @tx_t_ipi: Interpacket (send) interval (RFC 3448, 4.6) in usecs 748c2ecf20Sopenharmony_ci * @tx_state: Sender state, one of %ccid3_hc_tx_states 758c2ecf20Sopenharmony_ci * @tx_last_win_count: Last window counter sent 768c2ecf20Sopenharmony_ci * @tx_t_last_win_count: Timestamp of earliest packet 778c2ecf20Sopenharmony_ci * with last_win_count value sent 788c2ecf20Sopenharmony_ci * @tx_no_feedback_timer: Handle to no feedback timer 798c2ecf20Sopenharmony_ci * @tx_t_ld: Time last doubled during slow start 808c2ecf20Sopenharmony_ci * @tx_t_nom: Nominal send time of next packet 818c2ecf20Sopenharmony_ci * @tx_hist: Packet history 828c2ecf20Sopenharmony_ci */ 838c2ecf20Sopenharmony_cistruct ccid3_hc_tx_sock { 848c2ecf20Sopenharmony_ci u64 tx_x; 858c2ecf20Sopenharmony_ci u64 tx_x_recv; 868c2ecf20Sopenharmony_ci u32 tx_x_calc; 878c2ecf20Sopenharmony_ci u32 tx_rtt; 888c2ecf20Sopenharmony_ci u32 tx_p; 898c2ecf20Sopenharmony_ci u32 tx_t_rto; 908c2ecf20Sopenharmony_ci u32 tx_t_ipi; 918c2ecf20Sopenharmony_ci u16 tx_s; 928c2ecf20Sopenharmony_ci enum ccid3_hc_tx_states tx_state:8; 938c2ecf20Sopenharmony_ci u8 tx_last_win_count; 948c2ecf20Sopenharmony_ci ktime_t tx_t_last_win_count; 958c2ecf20Sopenharmony_ci struct timer_list tx_no_feedback_timer; 968c2ecf20Sopenharmony_ci struct sock *sk; 978c2ecf20Sopenharmony_ci ktime_t tx_t_ld; 988c2ecf20Sopenharmony_ci ktime_t tx_t_nom; 998c2ecf20Sopenharmony_ci struct tfrc_tx_hist_entry *tx_hist; 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci struct ccid3_hc_tx_sock *hctx = ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid); 1058c2ecf20Sopenharmony_ci BUG_ON(hctx == NULL); 1068c2ecf20Sopenharmony_ci return hctx; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* TFRC receiver states */ 1108c2ecf20Sopenharmony_cienum ccid3_hc_rx_states { 1118c2ecf20Sopenharmony_ci TFRC_RSTATE_NO_DATA = 1, 1128c2ecf20Sopenharmony_ci TFRC_RSTATE_DATA, 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/** 1168c2ecf20Sopenharmony_ci * struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket 1178c2ecf20Sopenharmony_ci * @rx_last_counter: Tracks window counter (RFC 4342, 8.1) 1188c2ecf20Sopenharmony_ci * @rx_state: Receiver state, one of %ccid3_hc_rx_states 1198c2ecf20Sopenharmony_ci * @rx_bytes_recv: Total sum of DCCP payload bytes 1208c2ecf20Sopenharmony_ci * @rx_x_recv: Receiver estimate of send rate (RFC 3448, sec. 4.3) 1218c2ecf20Sopenharmony_ci * @rx_rtt: Receiver estimate of RTT 1228c2ecf20Sopenharmony_ci * @rx_tstamp_last_feedback: Time at which last feedback was sent 1238c2ecf20Sopenharmony_ci * @rx_hist: Packet history (loss detection + RTT sampling) 1248c2ecf20Sopenharmony_ci * @rx_li_hist: Loss Interval database 1258c2ecf20Sopenharmony_ci * @rx_s: Received packet size in bytes 1268c2ecf20Sopenharmony_ci * @rx_pinv: Inverse of Loss Event Rate (RFC 4342, sec. 8.5) 1278c2ecf20Sopenharmony_ci */ 1288c2ecf20Sopenharmony_cistruct ccid3_hc_rx_sock { 1298c2ecf20Sopenharmony_ci u8 rx_last_counter:4; 1308c2ecf20Sopenharmony_ci enum ccid3_hc_rx_states rx_state:8; 1318c2ecf20Sopenharmony_ci u32 rx_bytes_recv; 1328c2ecf20Sopenharmony_ci u32 rx_x_recv; 1338c2ecf20Sopenharmony_ci u32 rx_rtt; 1348c2ecf20Sopenharmony_ci ktime_t rx_tstamp_last_feedback; 1358c2ecf20Sopenharmony_ci struct tfrc_rx_hist rx_hist; 1368c2ecf20Sopenharmony_ci struct tfrc_loss_hist rx_li_hist; 1378c2ecf20Sopenharmony_ci u16 rx_s; 1388c2ecf20Sopenharmony_ci#define rx_pinv rx_li_hist.i_mean 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci struct ccid3_hc_rx_sock *hcrx = ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid); 1448c2ecf20Sopenharmony_ci BUG_ON(hcrx == NULL); 1458c2ecf20Sopenharmony_ci return hcrx; 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci#endif /* _DCCP_CCID3_H_ */ 149