if_xdp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * if_xdp: XDP socket user-space interface
  4. * Copyright(c) 2018 Intel Corporation.
  5. *
  6. * Author(s): Björn Töpel <bjorn.topel@intel.com>
  7. * Magnus Karlsson <magnus.karlsson@intel.com>
  8. */
  9. #ifndef _UAPI_LINUX_IF_XDP_H
  10. #define _UAPI_LINUX_IF_XDP_H
  11. #include <linux/types.h>
  12. /* Options for the sxdp_flags field */
  13. #define XDP_SHARED_UMEM (1 << 0)
  14. #define XDP_COPY (1 << 1) /* Force copy-mode */
  15. #define XDP_ZEROCOPY (1 << 2) /* Force zero-copy mode */
  16. /* If this option is set, the driver might go sleep and in that case
  17. * the XDP_RING_NEED_WAKEUP flag in the fill and/or Tx rings will be
  18. * set. If it is set, the application need to explicitly wake up the
  19. * driver with a poll() (Rx and Tx) or sendto() (Tx only). If you are
  20. * running the driver and the application on the same core, you should
  21. * use this option so that the kernel will yield to the user space
  22. * application.
  23. */
  24. #define XDP_USE_NEED_WAKEUP (1 << 3)
  25. /* By setting this option, userspace application indicates that it can
  26. * handle multiple descriptors per packet thus enabling AF_XDP to split
  27. * multi-buffer XDP frames into multiple Rx descriptors. Without this set
  28. * such frames will be dropped.
  29. */
  30. #define XDP_USE_SG (1 << 4)
  31. /* Flags for xsk_umem_config flags */
  32. #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
  33. /* Force checksum calculation in software. Can be used for testing or
  34. * working around potential HW issues. This option causes performance
  35. * degradation and only works in XDP_COPY mode.
  36. */
  37. #define XDP_UMEM_TX_SW_CSUM (1 << 1)
  38. /* Request to reserve tx_metadata_len bytes of per-chunk metadata.
  39. */
  40. #define XDP_UMEM_TX_METADATA_LEN (1 << 2)
  41. struct sockaddr_xdp {
  42. __u16 sxdp_family;
  43. __u16 sxdp_flags;
  44. __u32 sxdp_ifindex;
  45. __u32 sxdp_queue_id;
  46. __u32 sxdp_shared_umem_fd;
  47. };
  48. /* XDP_RING flags */
  49. #define XDP_RING_NEED_WAKEUP (1 << 0)
  50. struct xdp_ring_offset {
  51. __u64 producer;
  52. __u64 consumer;
  53. __u64 desc;
  54. __u64 flags;
  55. };
  56. struct xdp_mmap_offsets {
  57. struct xdp_ring_offset rx;
  58. struct xdp_ring_offset tx;
  59. struct xdp_ring_offset fr; /* Fill */
  60. struct xdp_ring_offset cr; /* Completion */
  61. };
  62. /* XDP socket options */
  63. #define XDP_MMAP_OFFSETS 1
  64. #define XDP_RX_RING 2
  65. #define XDP_TX_RING 3
  66. #define XDP_UMEM_REG 4
  67. #define XDP_UMEM_FILL_RING 5
  68. #define XDP_UMEM_COMPLETION_RING 6
  69. #define XDP_STATISTICS 7
  70. #define XDP_OPTIONS 8
  71. #define XDP_MAX_TX_SKB_BUDGET 9
  72. struct xdp_umem_reg {
  73. __u64 addr; /* Start of packet data area */
  74. __u64 len; /* Length of packet data area */
  75. __u32 chunk_size;
  76. __u32 headroom;
  77. __u32 flags;
  78. __u32 tx_metadata_len;
  79. };
  80. struct xdp_statistics {
  81. __u64 rx_dropped; /* Dropped for other reasons */
  82. __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
  83. __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
  84. __u64 rx_ring_full; /* Dropped due to rx ring being full */
  85. __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
  86. __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
  87. };
  88. struct xdp_options {
  89. __u32 flags;
  90. };
  91. /* Flags for the flags field of struct xdp_options */
  92. #define XDP_OPTIONS_ZEROCOPY (1 << 0)
  93. /* Pgoff for mmaping the rings */
  94. #define XDP_PGOFF_RX_RING 0
  95. #define XDP_PGOFF_TX_RING 0x80000000
  96. #define XDP_UMEM_PGOFF_FILL_RING 0x100000000ULL
  97. #define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
  98. /* Masks for unaligned chunks mode */
  99. #define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
  100. #define XSK_UNALIGNED_BUF_ADDR_MASK \
  101. ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
  102. /* Request transmit timestamp. Upon completion, put it into tx_timestamp
  103. * field of struct xsk_tx_metadata.
  104. */
  105. #define XDP_TXMD_FLAGS_TIMESTAMP (1 << 0)
  106. /* Request transmit checksum offload. Checksum start position and offset
  107. * are communicated via csum_start and csum_offset fields of struct
  108. * xsk_tx_metadata.
  109. */
  110. #define XDP_TXMD_FLAGS_CHECKSUM (1 << 1)
  111. /* Request launch time hardware offload. The device will schedule the packet for
  112. * transmission at a pre-determined time called launch time. The value of
  113. * launch time is communicated via launch_time field of struct xsk_tx_metadata.
  114. */
  115. #define XDP_TXMD_FLAGS_LAUNCH_TIME (1 << 2)
  116. /* AF_XDP offloads request. 'request' union member is consumed by the driver
  117. * when the packet is being transmitted. 'completion' union member is
  118. * filled by the driver when the transmit completion arrives.
  119. */
  120. struct xsk_tx_metadata {
  121. __u64 flags;
  122. union {
  123. struct {
  124. /* XDP_TXMD_FLAGS_CHECKSUM */
  125. /* Offset from desc->addr where checksumming should start. */
  126. __u16 csum_start;
  127. /* Offset from csum_start where checksum should be stored. */
  128. __u16 csum_offset;
  129. /* XDP_TXMD_FLAGS_LAUNCH_TIME */
  130. /* Launch time in nanosecond against the PTP HW Clock */
  131. __u64 launch_time;
  132. } request;
  133. struct {
  134. /* XDP_TXMD_FLAGS_TIMESTAMP */
  135. __u64 tx_timestamp;
  136. } completion;
  137. };
  138. };
  139. /* Rx/Tx descriptor */
  140. struct xdp_desc {
  141. __u64 addr;
  142. __u32 len;
  143. __u32 options;
  144. };
  145. /* UMEM descriptor is __u64 */
  146. /* Flag indicating that the packet continues with the buffer pointed out by the
  147. * next frame in the ring. The end of the packet is signalled by setting this
  148. * bit to zero. For single buffer packets, every descriptor has 'options' set
  149. * to 0 and this maintains backward compatibility.
  150. */
  151. #define XDP_PKT_CONTD (1 << 0)
  152. /* TX packet carries valid metadata. */
  153. #define XDP_TX_METADATA (1 << 1)
  154. #endif /* _UAPI_LINUX_IF_XDP_H */