Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __NET_PKT_SCHED_H
0003 #define __NET_PKT_SCHED_H
0004 
0005 #include <linux/jiffies.h>
0006 #include <linux/ktime.h>
0007 #include <linux/if_vlan.h>
0008 #include <linux/netdevice.h>
0009 #include <net/sch_generic.h>
0010 #include <net/net_namespace.h>
0011 #include <uapi/linux/pkt_sched.h>
0012 
0013 #define DEFAULT_TX_QUEUE_LEN    1000
0014 #define STAB_SIZE_LOG_MAX   30
0015 
0016 struct qdisc_walker {
0017     int stop;
0018     int skip;
0019     int count;
0020     int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
0021 };
0022 
0023 static inline void *qdisc_priv(struct Qdisc *q)
0024 {
0025     return &q->privdata;
0026 }
0027 
0028 static inline struct Qdisc *qdisc_from_priv(void *priv)
0029 {
0030     return container_of(priv, struct Qdisc, privdata);
0031 }
0032 
0033 /* 
0034    Timer resolution MUST BE < 10% of min_schedulable_packet_size/bandwidth
0035    
0036    Normal IP packet size ~ 512byte, hence:
0037 
0038    0.5Kbyte/1Mbyte/sec = 0.5msec, so that we need 50usec timer for
0039    10Mbit ethernet.
0040 
0041    10msec resolution -> <50Kbit/sec.
0042    
0043    The result: [34]86 is not good choice for QoS router :-(
0044 
0045    The things are not so bad, because we may use artificial
0046    clock evaluated by integration of network data flow
0047    in the most critical places.
0048  */
0049 
0050 typedef u64 psched_time_t;
0051 typedef long    psched_tdiff_t;
0052 
0053 /* Avoid doing 64 bit divide */
0054 #define PSCHED_SHIFT            6
0055 #define PSCHED_TICKS2NS(x)      ((s64)(x) << PSCHED_SHIFT)
0056 #define PSCHED_NS2TICKS(x)      ((x) >> PSCHED_SHIFT)
0057 
0058 #define PSCHED_TICKS_PER_SEC        PSCHED_NS2TICKS(NSEC_PER_SEC)
0059 #define PSCHED_PASTPERFECT      0
0060 
0061 static inline psched_time_t psched_get_time(void)
0062 {
0063     return PSCHED_NS2TICKS(ktime_get_ns());
0064 }
0065 
0066 struct qdisc_watchdog {
0067     u64     last_expires;
0068     struct hrtimer  timer;
0069     struct Qdisc    *qdisc;
0070 };
0071 
0072 void qdisc_watchdog_init_clockid(struct qdisc_watchdog *wd, struct Qdisc *qdisc,
0073                  clockid_t clockid);
0074 void qdisc_watchdog_init(struct qdisc_watchdog *wd, struct Qdisc *qdisc);
0075 
0076 void qdisc_watchdog_schedule_range_ns(struct qdisc_watchdog *wd, u64 expires,
0077                       u64 delta_ns);
0078 
0079 static inline void qdisc_watchdog_schedule_ns(struct qdisc_watchdog *wd,
0080                           u64 expires)
0081 {
0082     return qdisc_watchdog_schedule_range_ns(wd, expires, 0ULL);
0083 }
0084 
0085 static inline void qdisc_watchdog_schedule(struct qdisc_watchdog *wd,
0086                        psched_time_t expires)
0087 {
0088     qdisc_watchdog_schedule_ns(wd, PSCHED_TICKS2NS(expires));
0089 }
0090 
0091 void qdisc_watchdog_cancel(struct qdisc_watchdog *wd);
0092 
0093 extern struct Qdisc_ops pfifo_qdisc_ops;
0094 extern struct Qdisc_ops bfifo_qdisc_ops;
0095 extern struct Qdisc_ops pfifo_head_drop_qdisc_ops;
0096 
0097 int fifo_set_limit(struct Qdisc *q, unsigned int limit);
0098 struct Qdisc *fifo_create_dflt(struct Qdisc *sch, struct Qdisc_ops *ops,
0099                    unsigned int limit,
0100                    struct netlink_ext_ack *extack);
0101 
0102 int register_qdisc(struct Qdisc_ops *qops);
0103 int unregister_qdisc(struct Qdisc_ops *qops);
0104 void qdisc_get_default(char *id, size_t len);
0105 int qdisc_set_default(const char *id);
0106 
0107 void qdisc_hash_add(struct Qdisc *q, bool invisible);
0108 void qdisc_hash_del(struct Qdisc *q);
0109 struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle);
0110 struct Qdisc *qdisc_lookup_rcu(struct net_device *dev, u32 handle);
0111 struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r,
0112                     struct nlattr *tab,
0113                     struct netlink_ext_ack *extack);
0114 void qdisc_put_rtab(struct qdisc_rate_table *tab);
0115 void qdisc_put_stab(struct qdisc_size_table *tab);
0116 void qdisc_warn_nonwc(const char *txt, struct Qdisc *qdisc);
0117 bool sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
0118              struct net_device *dev, struct netdev_queue *txq,
0119              spinlock_t *root_lock, bool validate);
0120 
0121 void __qdisc_run(struct Qdisc *q);
0122 
0123 static inline void qdisc_run(struct Qdisc *q)
0124 {
0125     if (qdisc_run_begin(q)) {
0126         __qdisc_run(q);
0127         qdisc_run_end(q);
0128     }
0129 }
0130 
0131 /* Calculate maximal size of packet seen by hard_start_xmit
0132    routine of this device.
0133  */
0134 static inline unsigned int psched_mtu(const struct net_device *dev)
0135 {
0136     return dev->mtu + dev->hard_header_len;
0137 }
0138 
0139 static inline struct net *qdisc_net(struct Qdisc *q)
0140 {
0141     return dev_net(q->dev_queue->dev);
0142 }
0143 
0144 struct tc_cbs_qopt_offload {
0145     u8 enable;
0146     s32 queue;
0147     s32 hicredit;
0148     s32 locredit;
0149     s32 idleslope;
0150     s32 sendslope;
0151 };
0152 
0153 struct tc_etf_qopt_offload {
0154     u8 enable;
0155     s32 queue;
0156 };
0157 
0158 struct tc_taprio_sched_entry {
0159     u8 command; /* TC_TAPRIO_CMD_* */
0160 
0161     /* The gate_mask in the offloading side refers to traffic classes */
0162     u32 gate_mask;
0163     u32 interval;
0164 };
0165 
0166 struct tc_taprio_qopt_offload {
0167     u8 enable;
0168     ktime_t base_time;
0169     u64 cycle_time;
0170     u64 cycle_time_extension;
0171 
0172     size_t num_entries;
0173     struct tc_taprio_sched_entry entries[];
0174 };
0175 
0176 #if IS_ENABLED(CONFIG_NET_SCH_TAPRIO)
0177 
0178 /* Reference counting */
0179 struct tc_taprio_qopt_offload *taprio_offload_get(struct tc_taprio_qopt_offload
0180                           *offload);
0181 void taprio_offload_free(struct tc_taprio_qopt_offload *offload);
0182 
0183 #else
0184 
0185 /* Reference counting */
0186 static inline struct tc_taprio_qopt_offload *
0187 taprio_offload_get(struct tc_taprio_qopt_offload *offload)
0188 {
0189     return NULL;
0190 }
0191 
0192 static inline void taprio_offload_free(struct tc_taprio_qopt_offload *offload)
0193 {
0194 }
0195 
0196 #endif
0197 
0198 /* Ensure skb_mstamp_ns, which might have been populated with the txtime, is
0199  * not mistaken for a software timestamp, because this will otherwise prevent
0200  * the dispatch of hardware timestamps to the socket.
0201  */
0202 static inline void skb_txtime_consumed(struct sk_buff *skb)
0203 {
0204     skb->tstamp = ktime_set(0, 0);
0205 }
0206 
0207 struct tc_skb_cb {
0208     struct qdisc_skb_cb qdisc_cb;
0209 
0210     u16 mru;
0211     u8 post_ct:1;
0212     u8 post_ct_snat:1;
0213     u8 post_ct_dnat:1;
0214     u16 zone; /* Only valid if post_ct = true */
0215 };
0216 
0217 static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
0218 {
0219     struct tc_skb_cb *cb = (struct tc_skb_cb *)skb->cb;
0220 
0221     BUILD_BUG_ON(sizeof(*cb) > sizeof_field(struct sk_buff, cb));
0222     return cb;
0223 }
0224 
0225 #endif