if_xdp.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <[email protected]>
  7. * Magnus Karlsson <[email protected]>
  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. /* Flags for xsk_umem_config flags */
  26. #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
  27. struct sockaddr_xdp {
  28. __u16 sxdp_family;
  29. __u16 sxdp_flags;
  30. __u32 sxdp_ifindex;
  31. __u32 sxdp_queue_id;
  32. __u32 sxdp_shared_umem_fd;
  33. };
  34. /* XDP_RING flags */
  35. #define XDP_RING_NEED_WAKEUP (1 << 0)
  36. struct xdp_ring_offset {
  37. __u64 producer;
  38. __u64 consumer;
  39. __u64 desc;
  40. __u64 flags;
  41. };
  42. struct xdp_mmap_offsets {
  43. struct xdp_ring_offset rx;
  44. struct xdp_ring_offset tx;
  45. struct xdp_ring_offset fr; /* Fill */
  46. struct xdp_ring_offset cr; /* Completion */
  47. };
  48. /* XDP socket options */
  49. #define XDP_MMAP_OFFSETS 1
  50. #define XDP_RX_RING 2
  51. #define XDP_TX_RING 3
  52. #define XDP_UMEM_REG 4
  53. #define XDP_UMEM_FILL_RING 5
  54. #define XDP_UMEM_COMPLETION_RING 6
  55. #define XDP_STATISTICS 7
  56. #define XDP_OPTIONS 8
  57. struct xdp_umem_reg {
  58. __u64 addr; /* Start of packet data area */
  59. __u64 len; /* Length of packet data area */
  60. __u32 chunk_size;
  61. __u32 headroom;
  62. __u32 flags;
  63. };
  64. struct xdp_statistics {
  65. __u64 rx_dropped; /* Dropped for other reasons */
  66. __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
  67. __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
  68. __u64 rx_ring_full; /* Dropped due to rx ring being full */
  69. __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
  70. __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
  71. };
  72. struct xdp_options {
  73. __u32 flags;
  74. };
  75. /* Flags for the flags field of struct xdp_options */
  76. #define XDP_OPTIONS_ZEROCOPY (1 << 0)
  77. /* Pgoff for mmaping the rings */
  78. #define XDP_PGOFF_RX_RING 0
  79. #define XDP_PGOFF_TX_RING 0x80000000
  80. #define XDP_UMEM_PGOFF_FILL_RING 0x100000000ULL
  81. #define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
  82. /* Masks for unaligned chunks mode */
  83. #define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
  84. #define XSK_UNALIGNED_BUF_ADDR_MASK \
  85. ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
  86. /* Rx/Tx descriptor */
  87. struct xdp_desc {
  88. __u64 addr;
  89. __u32 len;
  90. __u32 options;
  91. };
  92. /* UMEM descriptor is __u64 */
  93. #endif /* _LINUX_IF_XDP_H */