pkt_sched.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NET_PKT_SCHED_H
  3. #define __NET_PKT_SCHED_H
  4. #include <linux/jiffies.h>
  5. #include <linux/ktime.h>
  6. #include <linux/if_vlan.h>
  7. #include <linux/netdevice.h>
  8. #include <net/sch_generic.h>
  9. #include <net/net_namespace.h>
  10. #include <uapi/linux/pkt_sched.h>
  11. #define DEFAULT_TX_QUEUE_LEN 1000
  12. struct qdisc_walker {
  13. int stop;
  14. int skip;
  15. int count;
  16. int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
  17. };
  18. #define QDISC_ALIGNTO 64
  19. #define QDISC_ALIGN(len) (((len) + QDISC_ALIGNTO-1) & ~(QDISC_ALIGNTO-1))
  20. static inline void *qdisc_priv(struct Qdisc *q)
  21. {
  22. return (char *) q + QDISC_ALIGN(sizeof(struct Qdisc));
  23. }
  24. /*
  25. Timer resolution MUST BE < 10% of min_schedulable_packet_size/bandwidth
  26. Normal IP packet size ~ 512byte, hence:
  27. 0.5Kbyte/1Mbyte/sec = 0.5msec, so that we need 50usec timer for
  28. 10Mbit ethernet.
  29. 10msec resolution -> <50Kbit/sec.
  30. The result: [34]86 is not good choice for QoS router :-(
  31. The things are not so bad, because we may use artificial
  32. clock evaluated by integration of network data flow
  33. in the most critical places.
  34. */
  35. typedef u64 psched_time_t;
  36. typedef long psched_tdiff_t;
  37. /* Avoid doing 64 bit divide */
  38. #define PSCHED_SHIFT 6
  39. #define PSCHED_TICKS2NS(x) ((s64)(x) << PSCHED_SHIFT)
  40. #define PSCHED_NS2TICKS(x) ((x) >> PSCHED_SHIFT)
  41. #define PSCHED_TICKS_PER_SEC PSCHED_NS2TICKS(NSEC_PER_SEC)
  42. #define PSCHED_PASTPERFECT 0
  43. static inline psched_time_t psched_get_time(void)
  44. {
  45. return PSCHED_NS2TICKS(ktime_get_ns());
  46. }
  47. static inline psched_tdiff_t
  48. psched_tdiff_bounded(psched_time_t tv1, psched_time_t tv2, psched_time_t bound)
  49. {
  50. return min(tv1 - tv2, bound);
  51. }
  52. struct qdisc_watchdog {
  53. u64 last_expires;
  54. struct hrtimer timer;
  55. struct Qdisc *qdisc;
  56. };
  57. void qdisc_watchdog_init_clockid(struct qdisc_watchdog *wd, struct Qdisc *qdisc,
  58. clockid_t clockid);
  59. void qdisc_watchdog_init(struct qdisc_watchdog *wd, struct Qdisc *qdisc);
  60. void qdisc_watchdog_schedule_ns(struct qdisc_watchdog *wd, u64 expires);
  61. static inline void qdisc_watchdog_schedule(struct qdisc_watchdog *wd,
  62. psched_time_t expires)
  63. {
  64. qdisc_watchdog_schedule_ns(wd, PSCHED_TICKS2NS(expires));
  65. }
  66. void qdisc_watchdog_cancel(struct qdisc_watchdog *wd);
  67. extern struct Qdisc_ops pfifo_qdisc_ops;
  68. extern struct Qdisc_ops bfifo_qdisc_ops;
  69. extern struct Qdisc_ops pfifo_head_drop_qdisc_ops;
  70. int fifo_set_limit(struct Qdisc *q, unsigned int limit);
  71. struct Qdisc *fifo_create_dflt(struct Qdisc *sch, struct Qdisc_ops *ops,
  72. unsigned int limit,
  73. struct netlink_ext_ack *extack);
  74. int register_qdisc(struct Qdisc_ops *qops);
  75. int unregister_qdisc(struct Qdisc_ops *qops);
  76. void qdisc_get_default(char *id, size_t len);
  77. int qdisc_set_default(const char *id);
  78. void qdisc_hash_add(struct Qdisc *q, bool invisible);
  79. void qdisc_hash_del(struct Qdisc *q);
  80. struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle);
  81. struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r,
  82. struct nlattr *tab,
  83. struct netlink_ext_ack *extack);
  84. void qdisc_put_rtab(struct qdisc_rate_table *tab);
  85. void qdisc_put_stab(struct qdisc_size_table *tab);
  86. void qdisc_warn_nonwc(const char *txt, struct Qdisc *qdisc);
  87. bool sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
  88. struct net_device *dev, struct netdev_queue *txq,
  89. spinlock_t *root_lock, bool validate);
  90. void __qdisc_run(struct Qdisc *q);
  91. static inline void qdisc_run(struct Qdisc *q)
  92. {
  93. if (qdisc_run_begin(q)) {
  94. __qdisc_run(q);
  95. qdisc_run_end(q);
  96. }
  97. }
  98. /* Calculate maximal size of packet seen by hard_start_xmit
  99. routine of this device.
  100. */
  101. static inline unsigned int psched_mtu(const struct net_device *dev)
  102. {
  103. return dev->mtu + dev->hard_header_len;
  104. }
  105. static inline struct net *qdisc_net(struct Qdisc *q)
  106. {
  107. return dev_net(q->dev_queue->dev);
  108. }
  109. struct tc_cbs_qopt_offload {
  110. u8 enable;
  111. s32 queue;
  112. s32 hicredit;
  113. s32 locredit;
  114. s32 idleslope;
  115. s32 sendslope;
  116. };
  117. struct tc_etf_qopt_offload {
  118. u8 enable;
  119. s32 queue;
  120. };
  121. #endif