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