Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __NET_PKT_SCHED_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __NET_PKT_SCHED_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <net/sch_generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <uapi/linux/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define DEFAULT_TX_QUEUE_LEN	1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define STAB_SIZE_LOG_MAX	30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) struct qdisc_walker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	int	stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	int	skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	int	count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	int	(*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static inline void *qdisc_priv(struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	return &q->privdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)    Timer resolution MUST BE < 10% of min_schedulable_packet_size/bandwidth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)    Normal IP packet size ~ 512byte, hence:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)    0.5Kbyte/1Mbyte/sec = 0.5msec, so that we need 50usec timer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)    10Mbit ethernet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)    10msec resolution -> <50Kbit/sec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)    The result: [34]86 is not good choice for QoS router :-(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)    The things are not so bad, because we may use artificial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)    clock evaluated by integration of network data flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)    in the most critical places.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) typedef u64	psched_time_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) typedef long	psched_tdiff_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* Avoid doing 64 bit divide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define PSCHED_SHIFT			6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define PSCHED_TICKS2NS(x)		((s64)(x) << PSCHED_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define PSCHED_NS2TICKS(x)		((x) >> PSCHED_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define PSCHED_TICKS_PER_SEC		PSCHED_NS2TICKS(NSEC_PER_SEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define PSCHED_PASTPERFECT		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static inline psched_time_t psched_get_time(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return PSCHED_NS2TICKS(ktime_get_ns());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static inline psched_tdiff_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) psched_tdiff_bounded(psched_time_t tv1, psched_time_t tv2, psched_time_t bound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return min(tv1 - tv2, bound);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) struct qdisc_watchdog {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u64		last_expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct hrtimer	timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct Qdisc	*qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) void qdisc_watchdog_init_clockid(struct qdisc_watchdog *wd, struct Qdisc *qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				 clockid_t clockid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) void qdisc_watchdog_init(struct qdisc_watchdog *wd, struct Qdisc *qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) void qdisc_watchdog_schedule_range_ns(struct qdisc_watchdog *wd, u64 expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				      u64 delta_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static inline void qdisc_watchdog_schedule_ns(struct qdisc_watchdog *wd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 					      u64 expires)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return qdisc_watchdog_schedule_range_ns(wd, expires, 0ULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static inline void qdisc_watchdog_schedule(struct qdisc_watchdog *wd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					   psched_time_t expires)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	qdisc_watchdog_schedule_ns(wd, PSCHED_TICKS2NS(expires));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) void qdisc_watchdog_cancel(struct qdisc_watchdog *wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) extern struct Qdisc_ops pfifo_qdisc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) extern struct Qdisc_ops bfifo_qdisc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) extern struct Qdisc_ops pfifo_head_drop_qdisc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) int fifo_set_limit(struct Qdisc *q, unsigned int limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) struct Qdisc *fifo_create_dflt(struct Qdisc *sch, struct Qdisc_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			       unsigned int limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			       struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int register_qdisc(struct Qdisc_ops *qops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int unregister_qdisc(struct Qdisc_ops *qops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void qdisc_get_default(char *id, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int qdisc_set_default(const char *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void qdisc_hash_add(struct Qdisc *q, bool invisible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void qdisc_hash_del(struct Qdisc *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct Qdisc *qdisc_lookup_rcu(struct net_device *dev, u32 handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 					struct nlattr *tab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 					struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void qdisc_put_rtab(struct qdisc_rate_table *tab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void qdisc_put_stab(struct qdisc_size_table *tab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) void qdisc_warn_nonwc(const char *txt, struct Qdisc *qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) bool sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		     struct net_device *dev, struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		     spinlock_t *root_lock, bool validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void __qdisc_run(struct Qdisc *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline void qdisc_run(struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (qdisc_run_begin(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		__qdisc_run(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		qdisc_run_end(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* Calculate maximal size of packet seen by hard_start_xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)    routine of this device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline unsigned int psched_mtu(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return dev->mtu + dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static inline struct net *qdisc_net(struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return dev_net(q->dev_queue->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct tc_cbs_qopt_offload {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u8 enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	s32 queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	s32 hicredit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	s32 locredit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	s32 idleslope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	s32 sendslope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct tc_etf_qopt_offload {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	u8 enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	s32 queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct tc_taprio_sched_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	u8 command; /* TC_TAPRIO_CMD_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* The gate_mask in the offloading side refers to traffic classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	u32 gate_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	u32 interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct tc_taprio_qopt_offload {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	u8 enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	ktime_t base_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	u64 cycle_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	u64 cycle_time_extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	size_t num_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct tc_taprio_sched_entry entries[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Reference counting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct tc_taprio_qopt_offload *taprio_offload_get(struct tc_taprio_qopt_offload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 						  *offload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void taprio_offload_free(struct tc_taprio_qopt_offload *offload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #endif