Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * if_xdp: XDP socket user-space interface
0004  * Copyright(c) 2018 Intel Corporation.
0005  *
0006  * Author(s): Björn Töpel <bjorn.topel@intel.com>
0007  *        Magnus Karlsson <magnus.karlsson@intel.com>
0008  */
0009 
0010 #ifndef _LINUX_IF_XDP_H
0011 #define _LINUX_IF_XDP_H
0012 
0013 #include <linux/types.h>
0014 
0015 /* Options for the sxdp_flags field */
0016 #define XDP_SHARED_UMEM (1 << 0)
0017 #define XDP_COPY    (1 << 1) /* Force copy-mode */
0018 #define XDP_ZEROCOPY    (1 << 2) /* Force zero-copy mode */
0019 /* If this option is set, the driver might go sleep and in that case
0020  * the XDP_RING_NEED_WAKEUP flag in the fill and/or Tx rings will be
0021  * set. If it is set, the application need to explicitly wake up the
0022  * driver with a poll() (Rx and Tx) or sendto() (Tx only). If you are
0023  * running the driver and the application on the same core, you should
0024  * use this option so that the kernel will yield to the user space
0025  * application.
0026  */
0027 #define XDP_USE_NEED_WAKEUP (1 << 3)
0028 
0029 /* Flags for xsk_umem_config flags */
0030 #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
0031 
0032 struct sockaddr_xdp {
0033     __u16 sxdp_family;
0034     __u16 sxdp_flags;
0035     __u32 sxdp_ifindex;
0036     __u32 sxdp_queue_id;
0037     __u32 sxdp_shared_umem_fd;
0038 };
0039 
0040 /* XDP_RING flags */
0041 #define XDP_RING_NEED_WAKEUP (1 << 0)
0042 
0043 struct xdp_ring_offset {
0044     __u64 producer;
0045     __u64 consumer;
0046     __u64 desc;
0047     __u64 flags;
0048 };
0049 
0050 struct xdp_mmap_offsets {
0051     struct xdp_ring_offset rx;
0052     struct xdp_ring_offset tx;
0053     struct xdp_ring_offset fr; /* Fill */
0054     struct xdp_ring_offset cr; /* Completion */
0055 };
0056 
0057 /* XDP socket options */
0058 #define XDP_MMAP_OFFSETS        1
0059 #define XDP_RX_RING         2
0060 #define XDP_TX_RING         3
0061 #define XDP_UMEM_REG            4
0062 #define XDP_UMEM_FILL_RING      5
0063 #define XDP_UMEM_COMPLETION_RING    6
0064 #define XDP_STATISTICS          7
0065 #define XDP_OPTIONS         8
0066 
0067 struct xdp_umem_reg {
0068     __u64 addr; /* Start of packet data area */
0069     __u64 len; /* Length of packet data area */
0070     __u32 chunk_size;
0071     __u32 headroom;
0072     __u32 flags;
0073 };
0074 
0075 struct xdp_statistics {
0076     __u64 rx_dropped; /* Dropped for other reasons */
0077     __u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
0078     __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
0079     __u64 rx_ring_full; /* Dropped due to rx ring being full */
0080     __u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
0081     __u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
0082 };
0083 
0084 struct xdp_options {
0085     __u32 flags;
0086 };
0087 
0088 /* Flags for the flags field of struct xdp_options */
0089 #define XDP_OPTIONS_ZEROCOPY (1 << 0)
0090 
0091 /* Pgoff for mmaping the rings */
0092 #define XDP_PGOFF_RX_RING             0
0093 #define XDP_PGOFF_TX_RING        0x80000000
0094 #define XDP_UMEM_PGOFF_FILL_RING    0x100000000ULL
0095 #define XDP_UMEM_PGOFF_COMPLETION_RING  0x180000000ULL
0096 
0097 /* Masks for unaligned chunks mode */
0098 #define XSK_UNALIGNED_BUF_OFFSET_SHIFT 48
0099 #define XSK_UNALIGNED_BUF_ADDR_MASK \
0100     ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
0101 
0102 /* Rx/Tx descriptor */
0103 struct xdp_desc {
0104     __u64 addr;
0105     __u32 len;
0106     __u32 options;
0107 };
0108 
0109 /* UMEM descriptor is __u64 */
0110 
0111 #endif /* _LINUX_IF_XDP_H */