if_xdp.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. struct sockaddr_xdp {
  17. __u16 sxdp_family;
  18. __u16 sxdp_flags;
  19. __u32 sxdp_ifindex;
  20. __u32 sxdp_queue_id;
  21. __u32 sxdp_shared_umem_fd;
  22. };
  23. struct xdp_ring_offset {
  24. __u64 producer;
  25. __u64 consumer;
  26. __u64 desc;
  27. };
  28. struct xdp_mmap_offsets {
  29. struct xdp_ring_offset rx;
  30. struct xdp_ring_offset tx;
  31. struct xdp_ring_offset fr; /* Fill */
  32. struct xdp_ring_offset cr; /* Completion */
  33. };
  34. /* XDP socket options */
  35. #define XDP_MMAP_OFFSETS 1
  36. #define XDP_RX_RING 2
  37. #define XDP_TX_RING 3
  38. #define XDP_UMEM_REG 4
  39. #define XDP_UMEM_FILL_RING 5
  40. #define XDP_UMEM_COMPLETION_RING 6
  41. #define XDP_STATISTICS 7
  42. struct xdp_umem_reg {
  43. __u64 addr; /* Start of packet data area */
  44. __u64 len; /* Length of packet data area */
  45. __u32 chunk_size;
  46. __u32 headroom;
  47. };
  48. struct xdp_statistics {
  49. __u64 rx_dropped; /* Dropped for reasons other than invalid desc */
  50. __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
  51. __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
  52. };
  53. /* Pgoff for mmaping the rings */
  54. #define XDP_PGOFF_RX_RING 0
  55. #define XDP_PGOFF_TX_RING 0x80000000
  56. #define XDP_UMEM_PGOFF_FILL_RING 0x100000000ULL
  57. #define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
  58. /* Rx/Tx descriptor */
  59. struct xdp_desc {
  60. __u64 addr;
  61. __u32 len;
  62. __u32 options;
  63. };
  64. /* UMEM descriptor is __u64 */
  65. #endif /* _LINUX_IF_XDP_H */