xref: /OK3568_Linux_fs/kernel/include/net/fq.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2016 Qualcomm Atheros, Inc
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Based on net/sched/sch_fq_codel.c
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef __NET_SCHED_FQ_H
8*4882a593Smuzhiyun #define __NET_SCHED_FQ_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun struct fq_tin;
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /**
13*4882a593Smuzhiyun  * struct fq_flow - per traffic flow queue
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * @tin: owner of this flow. Used to manage collisions, i.e. when a packet
16*4882a593Smuzhiyun  *	hashes to an index which points to a flow that is already owned by a
17*4882a593Smuzhiyun  *	different tin the packet is destined to. In such case the implementer
18*4882a593Smuzhiyun  *	must provide a fallback flow
19*4882a593Smuzhiyun  * @flowchain: can be linked to fq_tin's new_flows or old_flows. Used for DRR++
20*4882a593Smuzhiyun  *	(deficit round robin) based round robin queuing similar to the one
21*4882a593Smuzhiyun  *	found in net/sched/sch_fq_codel.c
22*4882a593Smuzhiyun  * @backlogchain: can be linked to other fq_flow and fq. Used to keep track of
23*4882a593Smuzhiyun  *	fat flows and efficient head-dropping if packet limit is reached
24*4882a593Smuzhiyun  * @queue: sk_buff queue to hold packets
25*4882a593Smuzhiyun  * @backlog: number of bytes pending in the queue. The number of packets can be
26*4882a593Smuzhiyun  *	found in @queue.qlen
27*4882a593Smuzhiyun  * @deficit: used for DRR++
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun struct fq_flow {
30*4882a593Smuzhiyun 	struct fq_tin *tin;
31*4882a593Smuzhiyun 	struct list_head flowchain;
32*4882a593Smuzhiyun 	struct list_head backlogchain;
33*4882a593Smuzhiyun 	struct sk_buff_head queue;
34*4882a593Smuzhiyun 	u32 backlog;
35*4882a593Smuzhiyun 	int deficit;
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /**
39*4882a593Smuzhiyun  * struct fq_tin - a logical container of fq_flows
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * Used to group fq_flows into a logical aggregate. DRR++ scheme is used to
42*4882a593Smuzhiyun  * pull interleaved packets out of the associated flows.
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * @new_flows: linked list of fq_flow
45*4882a593Smuzhiyun  * @old_flows: linked list of fq_flow
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun struct fq_tin {
48*4882a593Smuzhiyun 	struct list_head new_flows;
49*4882a593Smuzhiyun 	struct list_head old_flows;
50*4882a593Smuzhiyun 	u32 backlog_bytes;
51*4882a593Smuzhiyun 	u32 backlog_packets;
52*4882a593Smuzhiyun 	u32 overlimit;
53*4882a593Smuzhiyun 	u32 collisions;
54*4882a593Smuzhiyun 	u32 flows;
55*4882a593Smuzhiyun 	u32 tx_bytes;
56*4882a593Smuzhiyun 	u32 tx_packets;
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /**
60*4882a593Smuzhiyun  * struct fq - main container for fair queuing purposes
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * @backlogs: linked to fq_flows. Used to maintain fat flows for efficient
63*4882a593Smuzhiyun  *	head-dropping when @backlog reaches @limit
64*4882a593Smuzhiyun  * @limit: max number of packets that can be queued across all flows
65*4882a593Smuzhiyun  * @backlog: number of packets queued across all flows
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun struct fq {
68*4882a593Smuzhiyun 	struct fq_flow *flows;
69*4882a593Smuzhiyun 	struct list_head backlogs;
70*4882a593Smuzhiyun 	spinlock_t lock;
71*4882a593Smuzhiyun 	u32 flows_cnt;
72*4882a593Smuzhiyun 	u32 limit;
73*4882a593Smuzhiyun 	u32 memory_limit;
74*4882a593Smuzhiyun 	u32 memory_usage;
75*4882a593Smuzhiyun 	u32 quantum;
76*4882a593Smuzhiyun 	u32 backlog;
77*4882a593Smuzhiyun 	u32 overlimit;
78*4882a593Smuzhiyun 	u32 overmemory;
79*4882a593Smuzhiyun 	u32 collisions;
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun typedef struct sk_buff *fq_tin_dequeue_t(struct fq *,
83*4882a593Smuzhiyun 					 struct fq_tin *,
84*4882a593Smuzhiyun 					 struct fq_flow *flow);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun typedef void fq_skb_free_t(struct fq *,
87*4882a593Smuzhiyun 			   struct fq_tin *,
88*4882a593Smuzhiyun 			   struct fq_flow *,
89*4882a593Smuzhiyun 			   struct sk_buff *);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /* Return %true to filter (drop) the frame. */
92*4882a593Smuzhiyun typedef bool fq_skb_filter_t(struct fq *,
93*4882a593Smuzhiyun 			     struct fq_tin *,
94*4882a593Smuzhiyun 			     struct fq_flow *,
95*4882a593Smuzhiyun 			     struct sk_buff *,
96*4882a593Smuzhiyun 			     void *);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun typedef struct fq_flow *fq_flow_get_default_t(struct fq *,
99*4882a593Smuzhiyun 					      struct fq_tin *,
100*4882a593Smuzhiyun 					      int idx,
101*4882a593Smuzhiyun 					      struct sk_buff *);
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #endif
104