18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci#ifndef _DCCP_LI_HIST_ 38c2ecf20Sopenharmony_ci#define _DCCP_LI_HIST_ 48c2ecf20Sopenharmony_ci/* 58c2ecf20Sopenharmony_ci * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 68c2ecf20Sopenharmony_ci * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 78c2ecf20Sopenharmony_ci * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz> 88c2ecf20Sopenharmony_ci * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#include <linux/ktime.h> 118c2ecf20Sopenharmony_ci#include <linux/list.h> 128c2ecf20Sopenharmony_ci#include <linux/slab.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* 158c2ecf20Sopenharmony_ci * Number of loss intervals (RFC 4342, 8.6.1). The history size is one more than 168c2ecf20Sopenharmony_ci * NINTERVAL, since the `open' interval I_0 is always stored as the first entry. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#define NINTERVAL 8 198c2ecf20Sopenharmony_ci#define LIH_SIZE (NINTERVAL + 1) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/** 228c2ecf20Sopenharmony_ci * tfrc_loss_interval - Loss history record for TFRC-based protocols 238c2ecf20Sopenharmony_ci * @li_seqno: Highest received seqno before the start of loss 248c2ecf20Sopenharmony_ci * @li_ccval: The CCVal belonging to @li_seqno 258c2ecf20Sopenharmony_ci * @li_is_closed: Whether @li_seqno is older than 1 RTT 268c2ecf20Sopenharmony_ci * @li_length: Loss interval sequence length 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_cistruct tfrc_loss_interval { 298c2ecf20Sopenharmony_ci u64 li_seqno:48, 308c2ecf20Sopenharmony_ci li_ccval:4, 318c2ecf20Sopenharmony_ci li_is_closed:1; 328c2ecf20Sopenharmony_ci u32 li_length; 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/** 368c2ecf20Sopenharmony_ci * tfrc_loss_hist - Loss record database 378c2ecf20Sopenharmony_ci * @ring: Circular queue managed in LIFO manner 388c2ecf20Sopenharmony_ci * @counter: Current count of entries (can be more than %LIH_SIZE) 398c2ecf20Sopenharmony_ci * @i_mean: Current Average Loss Interval [RFC 3448, 5.4] 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_cistruct tfrc_loss_hist { 428c2ecf20Sopenharmony_ci struct tfrc_loss_interval *ring[LIH_SIZE]; 438c2ecf20Sopenharmony_ci u8 counter; 448c2ecf20Sopenharmony_ci u32 i_mean; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic inline void tfrc_lh_init(struct tfrc_loss_hist *lh) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci memset(lh, 0, sizeof(struct tfrc_loss_hist)); 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic inline u8 tfrc_lh_is_initialised(struct tfrc_loss_hist *lh) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci return lh->counter > 0; 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic inline u8 tfrc_lh_length(struct tfrc_loss_hist *lh) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci return min(lh->counter, (u8)LIH_SIZE); 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistruct tfrc_rx_hist; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciint tfrc_lh_interval_add(struct tfrc_loss_hist *, struct tfrc_rx_hist *, 658c2ecf20Sopenharmony_ci u32 (*first_li)(struct sock *), struct sock *); 668c2ecf20Sopenharmony_ciu8 tfrc_lh_update_i_mean(struct tfrc_loss_hist *lh, struct sk_buff *); 678c2ecf20Sopenharmony_civoid tfrc_lh_cleanup(struct tfrc_loss_hist *lh); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#endif /* _DCCP_LI_HIST_ */ 70