Line data Source code
1 : #ifndef HEADER_fd_src_waltz_xdp_fd_xsk_private_h 2 : #define HEADER_fd_src_waltz_xdp_fd_xsk_private_h 3 : 4 : #if defined(__linux__) 5 : 6 : #include "fd_xsk.h" 7 : #include "../../util/fd_util.h" 8 : 9 : #include <linux/if_xdp.h> 10 : 11 : /* fd_ring_desc_t describes an XSK descriptor ring in the thread group's 12 : local address space. All pointers fall into kernel-managed XSK 13 : descriptor buffer at [mem;mem+mem_sz) that are valid during the 14 : lifetime of an fd_xsk_t join. The ring producer and consumer are 15 : synchronized via incrementing sequence numbers that wrap at 2^64. */ 16 : 17 : struct __attribute__((aligned(64UL))) fd_ring_desc { 18 : /* This point is 64-byte aligned */ 19 : 20 : /* mmap() params, only used during join/leave for munmap() */ 21 : 22 : void * mem; /* Points to start of shared descriptor ring mmap region */ 23 : ulong map_sz; /* Size of shared descriptor ring mmap region */ 24 : ulong _pad_0x10; 25 : ulong _pad_0x18; 26 : 27 : /* This point is 64-byte aligned */ 28 : 29 : /* Pointers to fields opaque XSK ring structure. 30 : This indirection is required because the memory layout of the 31 : kernel-provided descriptor rings is unstable. The field offsets 32 : can be queried using getsockopt(SOL_XDP, XDP_MMAP_OFFSETS). */ 33 : 34 : union { 35 : void * ptr; /* Opaque pointer */ 36 : struct xdp_desc * packet_ring; /* For RX, TX rings */ 37 : ulong * frame_ring; /* For FILL, COMPLETION rings */ 38 : }; 39 : uint * flags; /* Points to flags in shared descriptor ring */ 40 : uint * prod; /* Points to producer seq in shared descriptor ring */ 41 : uint * cons; /* Points to consumer seq in shared descriptor ring */ 42 : 43 : /* This point is 64-byte aligned */ 44 : 45 : /* Managed by fd_xsk_t */ 46 : 47 : uint depth; /* Capacity of ring in no of entries */ 48 : uint cached_prod; /* Cached value of *prod */ 49 : uint cached_cons; /* Cached value of *cons */ 50 : }; 51 : typedef struct fd_ring_desc fd_ring_desc_t; 52 : 53 : /* Private definition of an fd_xsk_t */ 54 : 55 6 : #define FD_XSK_MAGIC (0xf17eda2c3778736bUL) /* firedancer hex(xsk) */ 56 : 57 : struct __attribute__((aligned(FD_XSK_ALIGN))) fd_xsk_private { 58 : ulong magic; /* ==FD_XSK_MAGIC */ 59 : ulong session; /* TODO, use as mutex lock */ 60 : 61 : /* Network interface config *****************************************/ 62 : 63 : /* Informational */ 64 : uint if_idx; /* index of net device */ 65 : uint if_queue_id; /* net device combined queue index */ 66 : 67 : fd_xsk_params_t params; 68 : 69 : /* Per-join thread-group-local objects ******************************/ 70 : 71 : /* Kernel descriptor of UMEM in local address space */ 72 : struct xdp_umem_reg umem; 73 : 74 : /* Kernel descriptor of XSK rings in local address space 75 : returned by getsockopt(SOL_XDP, XDP_MMAP_OFFSETS) */ 76 : struct xdp_mmap_offsets offsets; 77 : 78 : /* Open file descriptors */ 79 : int xsk_fd; /* AF_XDP socket file descriptor */ 80 : int xdp_map_fd; /* eBPF XSKMAP */ 81 : int xdp_udp_map_fd; /* eBPF UDP map */ 82 : 83 : /* ring_{rx,tx,fr,cr}: XSK ring descriptors */ 84 : 85 : fd_ring_desc_t ring_rx; 86 : fd_ring_desc_t ring_tx; 87 : fd_ring_desc_t ring_fr; 88 : fd_ring_desc_t ring_cr; 89 : 90 : /* Variable-length data *********************************************/ 91 : 92 : /* ... UMEM area follows ... */ 93 : }; 94 : 95 : FD_PROTOTYPES_BEGIN 96 : 97 : /* fd_xsk_rx_need_wakeup: returns whether a wakeup is required to 98 : complete a rx operation */ 99 : 100 : static inline int 101 72 : fd_xsk_rx_need_wakeup( fd_xsk_t * xsk ) { 102 72 : return !!( *xsk->ring_fr.flags & XDP_RING_NEED_WAKEUP ); 103 72 : } 104 : 105 : /* fd_xsk_tx_need_wakeup: returns whether a wakeup is required to 106 : complete a tx operation */ 107 : 108 : static inline int 109 36 : fd_xsk_tx_need_wakeup( fd_xsk_t * xsk ) { 110 36 : return !!( *xsk->ring_tx.flags & XDP_RING_NEED_WAKEUP ); 111 36 : } 112 : 113 : FD_PROTOTYPES_END 114 : 115 : #endif /* defined(__linux__) */ 116 : #endif /* HEADER_fd_src_waltz_xdp_fd_xsk_private_h */