logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

if_xdp.h (5010B)


  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 _LINUX_IF_XDP_H
  10. #define _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. struct xdp_umem_reg {
  72. __u64 addr; /* Start of packet data area */
  73. __u64 len; /* Length of packet data area */
  74. __u32 chunk_size;
  75. __u32 headroom;
  76. __u32 flags;
  77. __u32 tx_metadata_len;
  78. };
  79. struct xdp_statistics {
  80. __u64 rx_dropped; /* Dropped for other reasons */
  81. __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
  82. __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
  83. __u64 rx_ring_full; /* Dropped due to rx ring being full */
  84. __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
  85. __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
  86. };
  87. struct xdp_options {
  88. __u32 flags;
  89. };
  90. /* Flags for the flags field of struct xdp_options */
  91. #define XDP_OPTIONS_ZEROCOPY (1 << 0)
  92. /* Pgoff for mmaping the rings */
  93. #define XDP_PGOFF_RX_RING 0
  94. #define XDP_PGOFF_TX_RING 0x80000000
  95. #define XDP_UMEM_PGOFF_FILL_RING 0x100000000ULL
  96. #define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
  97. /* Masks for unaligned chunks mode */
  98. #define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
  99. #define XSK_UNALIGNED_BUF_ADDR_MASK \
  100. ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
  101. /* Request transmit timestamp. Upon completion, put it into tx_timestamp
  102. * field of struct xsk_tx_metadata.
  103. */
  104. #define XDP_TXMD_FLAGS_TIMESTAMP (1 << 0)
  105. /* Request transmit checksum offload. Checksum start position and offset
  106. * are communicated via csum_start and csum_offset fields of struct
  107. * xsk_tx_metadata.
  108. */
  109. #define XDP_TXMD_FLAGS_CHECKSUM (1 << 1)
  110. /* AF_XDP offloads request. 'request' union member is consumed by the driver
  111. * when the packet is being transmitted. 'completion' union member is
  112. * filled by the driver when the transmit completion arrives.
  113. */
  114. struct xsk_tx_metadata {
  115. __u64 flags;
  116. union {
  117. struct {
  118. /* XDP_TXMD_FLAGS_CHECKSUM */
  119. /* Offset from desc->addr where checksumming should start. */
  120. __u16 csum_start;
  121. /* Offset from csum_start where checksum should be stored. */
  122. __u16 csum_offset;
  123. } request;
  124. struct {
  125. /* XDP_TXMD_FLAGS_TIMESTAMP */
  126. __u64 tx_timestamp;
  127. } completion;
  128. };
  129. };
  130. /* Rx/Tx descriptor */
  131. struct xdp_desc {
  132. __u64 addr;
  133. __u32 len;
  134. __u32 options;
  135. };
  136. /* UMEM descriptor is __u64 */
  137. /* Flag indicating that the packet continues with the buffer pointed out by the
  138. * next frame in the ring. The end of the packet is signalled by setting this
  139. * bit to zero. For single buffer packets, every descriptor has 'options' set
  140. * to 0 and this maintains backward compatibility.
  141. */
  142. #define XDP_PKT_CONTD (1 << 0)
  143. /* TX packet carries valid metadata. */
  144. #define XDP_TX_METADATA (1 << 1)
  145. #endif /* _LINUX_IF_XDP_H */