1fb9e53ccSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2557fc4a0SMichal Kazior /* 3557fc4a0SMichal Kazior * Copyright (c) 2016 Qualcomm Atheros, Inc 4557fc4a0SMichal Kazior * 5557fc4a0SMichal Kazior * Based on net/sched/sch_fq_codel.c 6557fc4a0SMichal Kazior */ 7557fc4a0SMichal Kazior #ifndef __NET_SCHED_FQ_H 8557fc4a0SMichal Kazior #define __NET_SCHED_FQ_H 9557fc4a0SMichal Kazior 10*949d6b40SJakub Kicinski #include <linux/skbuff.h> 11*949d6b40SJakub Kicinski #include <linux/spinlock.h> 12*949d6b40SJakub Kicinski #include <linux/types.h> 13*949d6b40SJakub Kicinski 14557fc4a0SMichal Kazior struct fq_tin; 15557fc4a0SMichal Kazior 16557fc4a0SMichal Kazior /** 17557fc4a0SMichal Kazior * struct fq_flow - per traffic flow queue 18557fc4a0SMichal Kazior * 19557fc4a0SMichal Kazior * @tin: owner of this flow. Used to manage collisions, i.e. when a packet 20557fc4a0SMichal Kazior * hashes to an index which points to a flow that is already owned by a 21557fc4a0SMichal Kazior * different tin the packet is destined to. In such case the implementer 22557fc4a0SMichal Kazior * must provide a fallback flow 23557fc4a0SMichal Kazior * @flowchain: can be linked to fq_tin's new_flows or old_flows. Used for DRR++ 24557fc4a0SMichal Kazior * (deficit round robin) based round robin queuing similar to the one 25557fc4a0SMichal Kazior * found in net/sched/sch_fq_codel.c 26557fc4a0SMichal Kazior * @queue: sk_buff queue to hold packets 27557fc4a0SMichal Kazior * @backlog: number of bytes pending in the queue. The number of packets can be 28557fc4a0SMichal Kazior * found in @queue.qlen 29557fc4a0SMichal Kazior * @deficit: used for DRR++ 30557fc4a0SMichal Kazior */ 31557fc4a0SMichal Kazior struct fq_flow { 32557fc4a0SMichal Kazior struct fq_tin *tin; 33557fc4a0SMichal Kazior struct list_head flowchain; 34557fc4a0SMichal Kazior struct sk_buff_head queue; 35557fc4a0SMichal Kazior u32 backlog; 36557fc4a0SMichal Kazior int deficit; 37557fc4a0SMichal Kazior }; 38557fc4a0SMichal Kazior 39557fc4a0SMichal Kazior /** 40557fc4a0SMichal Kazior * struct fq_tin - a logical container of fq_flows 41557fc4a0SMichal Kazior * 42557fc4a0SMichal Kazior * Used to group fq_flows into a logical aggregate. DRR++ scheme is used to 43557fc4a0SMichal Kazior * pull interleaved packets out of the associated flows. 44557fc4a0SMichal Kazior * 45557fc4a0SMichal Kazior * @new_flows: linked list of fq_flow 46557fc4a0SMichal Kazior * @old_flows: linked list of fq_flow 47557fc4a0SMichal Kazior */ 48557fc4a0SMichal Kazior struct fq_tin { 49557fc4a0SMichal Kazior struct list_head new_flows; 50557fc4a0SMichal Kazior struct list_head old_flows; 51d7b64929SFelix Fietkau struct list_head tin_list; 52bf9009bfSFelix Fietkau struct fq_flow default_flow; 53557fc4a0SMichal Kazior u32 backlog_bytes; 54557fc4a0SMichal Kazior u32 backlog_packets; 55557fc4a0SMichal Kazior u32 overlimit; 56557fc4a0SMichal Kazior u32 collisions; 57557fc4a0SMichal Kazior u32 flows; 58557fc4a0SMichal Kazior u32 tx_bytes; 59557fc4a0SMichal Kazior u32 tx_packets; 60557fc4a0SMichal Kazior }; 61557fc4a0SMichal Kazior 62557fc4a0SMichal Kazior /** 63557fc4a0SMichal Kazior * struct fq - main container for fair queuing purposes 64557fc4a0SMichal Kazior * 65557fc4a0SMichal Kazior * @limit: max number of packets that can be queued across all flows 66557fc4a0SMichal Kazior * @backlog: number of packets queued across all flows 67557fc4a0SMichal Kazior */ 68557fc4a0SMichal Kazior struct fq { 69557fc4a0SMichal Kazior struct fq_flow *flows; 70d7b64929SFelix Fietkau unsigned long *flows_bitmap; 71d7b64929SFelix Fietkau 72d7b64929SFelix Fietkau struct list_head tin_backlog; 73557fc4a0SMichal Kazior spinlock_t lock; 74557fc4a0SMichal Kazior u32 flows_cnt; 75557fc4a0SMichal Kazior u32 limit; 76097b065bSToke Høiland-Jørgensen u32 memory_limit; 77097b065bSToke Høiland-Jørgensen u32 memory_usage; 78557fc4a0SMichal Kazior u32 quantum; 79557fc4a0SMichal Kazior u32 backlog; 80557fc4a0SMichal Kazior u32 overlimit; 81097b065bSToke Høiland-Jørgensen u32 overmemory; 82557fc4a0SMichal Kazior u32 collisions; 83557fc4a0SMichal Kazior }; 84557fc4a0SMichal Kazior 85557fc4a0SMichal Kazior typedef struct sk_buff *fq_tin_dequeue_t(struct fq *, 86557fc4a0SMichal Kazior struct fq_tin *, 87557fc4a0SMichal Kazior struct fq_flow *flow); 88557fc4a0SMichal Kazior 89557fc4a0SMichal Kazior typedef void fq_skb_free_t(struct fq *, 90557fc4a0SMichal Kazior struct fq_tin *, 91557fc4a0SMichal Kazior struct fq_flow *, 92557fc4a0SMichal Kazior struct sk_buff *); 93557fc4a0SMichal Kazior 948c418b5bSJohannes Berg /* Return %true to filter (drop) the frame. */ 958c418b5bSJohannes Berg typedef bool fq_skb_filter_t(struct fq *, 968c418b5bSJohannes Berg struct fq_tin *, 978c418b5bSJohannes Berg struct fq_flow *, 988c418b5bSJohannes Berg struct sk_buff *, 998c418b5bSJohannes Berg void *); 1008c418b5bSJohannes Berg 101557fc4a0SMichal Kazior #endif 102