blob: 07b5aff6ec583923d0fd4992873c2a273d44005c [file] [log] [blame]
Thomas Gleixnerfb9e53c2019-05-29 07:12:31 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Michal Kazior557fc4a2016-04-22 14:20:13 +02002/*
3 * Copyright (c) 2016 Qualcomm Atheros, Inc
4 *
Michal Kazior557fc4a2016-04-22 14:20:13 +02005 * Based on net/sched/sch_fq_codel.c
6 */
7#ifndef __NET_SCHED_FQ_H
8#define __NET_SCHED_FQ_H
9
Jakub Kicinski949d6b42022-07-20 16:57:58 -070010#include <linux/skbuff.h>
11#include <linux/spinlock.h>
12#include <linux/types.h>
13
Michal Kazior557fc4a2016-04-22 14:20:13 +020014struct fq_tin;
15
16/**
17 * struct fq_flow - per traffic flow queue
18 *
19 * @tin: owner of this flow. Used to manage collisions, i.e. when a packet
20 * hashes to an index which points to a flow that is already owned by a
21 * different tin the packet is destined to. In such case the implementer
22 * must provide a fallback flow
23 * @flowchain: can be linked to fq_tin's new_flows or old_flows. Used for DRR++
24 * (deficit round robin) based round robin queuing similar to the one
25 * found in net/sched/sch_fq_codel.c
Michal Kazior557fc4a2016-04-22 14:20:13 +020026 * @queue: sk_buff queue to hold packets
27 * @backlog: number of bytes pending in the queue. The number of packets can be
28 * found in @queue.qlen
29 * @deficit: used for DRR++
30 */
31struct fq_flow {
32 struct fq_tin *tin;
33 struct list_head flowchain;
Michal Kazior557fc4a2016-04-22 14:20:13 +020034 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 */
48struct fq_tin {
49 struct list_head new_flows;
50 struct list_head old_flows;
Felix Fietkaud7b64922020-12-18 19:47:15 +010051 struct list_head tin_list;
Felix Fietkaubf9009b2020-12-18 19:47:14 +010052 struct fq_flow default_flow;
Michal Kazior557fc4a2016-04-22 14:20:13 +020053 u32 backlog_bytes;
54 u32 backlog_packets;
55 u32 overlimit;
56 u32 collisions;
57 u32 flows;
58 u32 tx_bytes;
59 u32 tx_packets;
60};
61
62/**
63 * struct fq - main container for fair queuing purposes
64 *
Michal Kazior557fc4a2016-04-22 14:20:13 +020065 * @limit: max number of packets that can be queued across all flows
66 * @backlog: number of packets queued across all flows
67 */
68struct fq {
69 struct fq_flow *flows;
Felix Fietkaud7b64922020-12-18 19:47:15 +010070 unsigned long *flows_bitmap;
71
72 struct list_head tin_backlog;
Michal Kazior557fc4a2016-04-22 14:20:13 +020073 spinlock_t lock;
74 u32 flows_cnt;
Michal Kazior557fc4a2016-04-22 14:20:13 +020075 u32 limit;
Toke Høiland-Jørgensen097b0652016-09-23 21:59:09 +020076 u32 memory_limit;
77 u32 memory_usage;
Michal Kazior557fc4a2016-04-22 14:20:13 +020078 u32 quantum;
79 u32 backlog;
80 u32 overlimit;
Toke Høiland-Jørgensen097b0652016-09-23 21:59:09 +020081 u32 overmemory;
Michal Kazior557fc4a2016-04-22 14:20:13 +020082 u32 collisions;
83};
84
85typedef struct sk_buff *fq_tin_dequeue_t(struct fq *,
86 struct fq_tin *,
87 struct fq_flow *flow);
88
89typedef void fq_skb_free_t(struct fq *,
90 struct fq_tin *,
91 struct fq_flow *,
92 struct sk_buff *);
93
Johannes Berg8c418b52017-10-06 11:53:32 +020094/* Return %true to filter (drop) the frame. */
95typedef bool fq_skb_filter_t(struct fq *,
96 struct fq_tin *,
97 struct fq_flow *,
98 struct sk_buff *,
99 void *);
100
Michal Kazior557fc4a2016-04-22 14:20:13 +0200101typedef struct fq_flow *fq_flow_get_default_t(struct fq *,
102 struct fq_tin *,
103 int idx,
104 struct sk_buff *);
105
106#endif