net_shaper.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _NET_SHAPER_H_
  3. #define _NET_SHAPER_H_
  4. #include <linux/types.h>
  5. #include <uapi/linux/net_shaper.h>
  6. struct net_device;
  7. struct devlink;
  8. struct netlink_ext_ack;
  9. enum net_shaper_binding_type {
  10. NET_SHAPER_BINDING_TYPE_NETDEV,
  11. /* NET_SHAPER_BINDING_TYPE_DEVLINK_PORT */
  12. };
  13. struct net_shaper_binding {
  14. enum net_shaper_binding_type type;
  15. union {
  16. struct net_device *netdev;
  17. struct devlink *devlink;
  18. };
  19. };
  20. struct net_shaper_handle {
  21. enum net_shaper_scope scope;
  22. u32 id;
  23. };
  24. /**
  25. * struct net_shaper - represents a shaping node on the NIC H/W
  26. * zeroed field are considered not set.
  27. * @parent: Unique identifier for the shaper parent, usually implied
  28. * @handle: Unique identifier for this shaper
  29. * @metric: Specify if the rate limits refers to PPS or BPS
  30. * @bw_min: Minimum guaranteed rate for this shaper
  31. * @bw_max: Maximum peak rate allowed for this shaper
  32. * @burst: Maximum burst for the peek rate of this shaper
  33. * @priority: Scheduling priority for this shaper
  34. * @weight: Scheduling weight for this shaper
  35. */
  36. struct net_shaper {
  37. struct net_shaper_handle parent;
  38. struct net_shaper_handle handle;
  39. enum net_shaper_metric metric;
  40. u64 bw_min;
  41. u64 bw_max;
  42. u64 burst;
  43. u32 priority;
  44. u32 weight;
  45. /* private: */
  46. u32 leaves; /* accounted only for NODE scope */
  47. struct rcu_head rcu;
  48. };
  49. /**
  50. * struct net_shaper_ops - Operations on device H/W shapers
  51. *
  52. * The operations applies to either net_device and devlink objects.
  53. * The initial shaping configuration at device initialization is empty:
  54. * does not constraint the rate in any way.
  55. * The network core keeps track of the applied user-configuration in
  56. * the net_device or devlink structure.
  57. * The operations are serialized via a per device lock.
  58. *
  59. * Device not supporting any kind of nesting should not provide the
  60. * group operation.
  61. *
  62. * Each shaper is uniquely identified within the device with a 'handle'
  63. * comprising the shaper scope and a scope-specific id.
  64. */
  65. struct net_shaper_ops {
  66. /**
  67. * @group: create the specified shapers scheduling group
  68. *
  69. * Nest the @leaves shapers identified under the * @node shaper.
  70. * All the shapers belong to the device specified by @binding.
  71. * The @leaves arrays size is specified by @leaves_count.
  72. * Create either the @leaves and the @node shaper; or if they already
  73. * exists, links them together in the desired way.
  74. * @leaves scope must be NET_SHAPER_SCOPE_QUEUE.
  75. */
  76. int (*group)(struct net_shaper_binding *binding, int leaves_count,
  77. const struct net_shaper *leaves,
  78. const struct net_shaper *node,
  79. struct netlink_ext_ack *extack);
  80. /**
  81. * @set: Updates the specified shaper
  82. *
  83. * Updates or creates the @shaper on the device specified by @binding.
  84. */
  85. int (*set)(struct net_shaper_binding *binding,
  86. const struct net_shaper *shaper,
  87. struct netlink_ext_ack *extack);
  88. /**
  89. * @delete: Removes the specified shaper
  90. *
  91. * Removes the shaper configuration as identified by the given @handle
  92. * on the device specified by @binding, restoring the default behavior.
  93. */
  94. int (*delete)(struct net_shaper_binding *binding,
  95. const struct net_shaper_handle *handle,
  96. struct netlink_ext_ack *extack);
  97. /**
  98. * @capabilities: get the shaper features supported by the device
  99. *
  100. * Fills the bitmask @cap with the supported capabilities for the
  101. * specified @scope and device specified by @binding.
  102. */
  103. void (*capabilities)(struct net_shaper_binding *binding,
  104. enum net_shaper_scope scope, unsigned long *cap);
  105. };
  106. #endif