XLIO
The NVIDIA® Accelerated IO
xlio_types.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3  * Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4  * SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
5  */
6 
14 #ifndef XLIO_TYPES_H
15 #define XLIO_TYPES_H
16 
17 #include <stddef.h>
18 #include <stdint.h>
19 #include <netinet/in.h>
20 #include <sys/socket.h>
21 #include <sys/time.h>
22 
23 /*
24  * Options for setsockopt()/getsockopt()
25  */
26 #define SO_XLIO_GET_API 2800
27 #define SO_XLIO_RING_ALLOC_LOGIC 2810
28 #define SO_XLIO_SHUTDOWN_RX 2821
29 #define SO_XLIO_EXT_VLAN_TAG 2824
30 
31 /*
32  * Return values for the receive packet notify callback function
33  */
34 typedef enum {
35  XLIO_PACKET_DROP, /* The library will drop the received packet and recycle
36  the buffer if no other socket needs it */
37 
38  XLIO_PACKET_RECV, /* The library will queue the received packet on this socket ready queue.
39  The application will read it with the usual recv socket APIs */
40 
41  XLIO_PACKET_HOLD /* Application will handle the queuing of the received packet. The application
42  must return the descriptor to the library using the free packet function
43  But not in the context of XLIO's callback itself. */
44 } xlio_recv_callback_retval_t;
45 
46 /*
47  * Structure holding additional information on the packet and socket
48  * Note: Check structure size value for future library changes
49  */
50 struct __attribute__((packed)) xlio_info_t {
51  size_t
52  struct_sz; /* Compare this value with sizeof(xlio_info_t) to check version compatability */
53  void *packet_id; /* Handle to received packet buffer to be return if zero copy logic is used */
54 
55  /* Packet addressing information (in network byte order) */
56  const struct sockaddr *src;
57  const struct sockaddr *dst;
58 
59  /* Packet information */
60  size_t payload_sz;
61 
62  /* Socket's information */
63  uint32_t socket_ready_queue_pkt_count; /* Current count of packets waiting to be read from the
64  socket */
65  uint32_t socket_ready_queue_byte_count; /* Current count of bytes waiting to be read from the
66  socket */
67 
68  /* Packet timestamping information */
69  struct timespec hw_timestamp;
70  struct timespec sw_timestamp;
71 };
72 
74  uint32_t rate; /* rate limit in Kbps */
75  uint32_t max_burst_sz; /* maximum burst size in bytes */
76  uint16_t typical_pkt_sz; /* typical packet size in bytes */
77 };
78 
79 typedef enum {
80  RING_LOGIC_PER_INTERFACE = 0,
81  RING_LOGIC_PER_IP = 1,
82  RING_LOGIC_PER_SOCKET = 10,
83  RING_LOGIC_PER_USER_ID = 11,
84  RING_LOGIC_PER_THREAD = 20,
85  RING_LOGIC_PER_CORE = 30,
86  RING_LOGIC_PER_CORE_ATTACH_THREADS = 31,
87  RING_LOGIC_PER_OBJECT = 32,
88  RING_LOGIC_LAST
89 } ring_logic_t;
90 
91 typedef enum {
92  XLIO_RING_ALLOC_MASK_RING_USER_ID = (1 << 0),
93  XLIO_RING_ALLOC_MASK_RING_INGRESS = (1 << 1),
94  XLIO_RING_ALLOC_MASK_RING_ENGRESS = (1 << 2),
95 } xlio_ring_alloc_logic_attr_comp_mask;
96 
97 /*
98  * @brief pass this struct to process by the library using setsockopt with
99  * @ref SO_XLIO_RING_ALLOC_LOGIC
100  * to set the allocation logic of this FD when he requests a ring.
101  * @note ring_alloc_logic is a mandatory
102  * @param comp_mask - what fields are read when processing this struct
103  * see @ref xlio_ring_alloc_logic_attr_comp_mask
104  * @param ring_alloc_logic- allocation ratio to use
105  * @param user_idx - when used RING_LOGIC_PER_USER_ID int @ref ring_alloc_logic
106  * this is the user id to define. This lets you define the same ring for
107  * few FD's regardless the interface\thread\core.
108  * @param ingress - RX ring
109  * @param engress - TX ring
110  */
112  uint32_t comp_mask;
113  ring_logic_t ring_alloc_logic;
114  uint32_t user_id;
115  uint32_t ingress : 1;
116  uint32_t engress : 1;
117  uint32_t reserved : 30;
118 };
119 
120 /*
121  * Notification callback for incoming packet on socket
122  * @param fd Socket's file descriptor which this packet refers to
123  * @param iov iovector structure array point holding the packet
124  * received data buffer pointers and size of each buffer
125  * @param iov_sz Size of iov array
126  * @param xlio_info Additional information on the packet and socket
127  * @param context User-defined value provided during callback
128  * registration for each socket
129  *
130  * This callback function should be registered by the library calling
131  * register_recv_callback() in the extended API. It can be unregistered by
132  * setting a NULL function pointer. The library will call the callback to notify
133  * of new incoming packets after the IP & UDP header processing and before
134  * they are queued in the socket's receive queue.
135  * Context of the callback will always be from one of the user's application
136  * threads when calling the following socket APIs: select, poll, epoll, recv,
137  * recvfrom, recvmsg, read, readv.
138  *
139  * Notes:
140  * - The application can call all of the Socket APIs control and send from
141  * within the callback context.
142  * - Packet loss might occur depending on the applications behavior in the
143  * callback context.
144  * - Parameters `iov' and `xlio_info' are only valid until callback context
145  * is returned to the library. User should copy these structures for later use
146  * if working with zero copy logic.
147  */
148 typedef xlio_recv_callback_retval_t (*xlio_recv_callback_t)(int fd, size_t sz_iov,
149  struct iovec iov[],
150  struct xlio_info_t *xlio_info,
151  void *context);
152 
164 typedef uintptr_t xlio_poll_group_t;
165 
172 typedef uintptr_t xlio_socket_t;
173 
198 struct xlio_buf {
199  uint64_t userdata;
200 };
201  // end of xlio_rx group
203 
234 typedef void (*xlio_memory_cb_t)(void *addr, size_t len, size_t hugepage_size);
235 
237 enum {
246 };
247 
275 typedef void (*xlio_socket_event_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, int event,
276  int value);
277 
299 typedef void (*xlio_socket_comp_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq,
300  uintptr_t userdata_op);
301 
321 typedef void (*xlio_socket_rx_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, void *data,
322  size_t len, struct xlio_buf *buf);
323 
342  uintptr_t parent_userdata_sq);
343  // end of xlio_callbacks group
345 
372  unsigned flags;
373  xlio_memory_cb_t memory_cb;
374 
375  /* Optional external user allocator for XLIO buffers. */
376  void *(*memory_alloc)(size_t);
377  void (*memory_free)(void *);
378 };
379  // end of xlio_init group
381 
388 #define XLIO_GROUP_FLAG_SAFE 0x1
390 #define XLIO_GROUP_FLAG_DIRTY 0x2
391 
415  unsigned flags;
416 
417  xlio_socket_event_cb_t socket_event_cb;
418  xlio_socket_comp_cb_t socket_comp_cb;
419  xlio_socket_rx_cb_t socket_rx_cb;
420  xlio_socket_accept_cb_t socket_accept_cb;
421 };
422  // end of xlio_poll_group group
424 
451  unsigned flags;
452  int domain; /* AF_INET or AF_INET6 */
453  xlio_poll_group_t group;
454  uintptr_t userdata_sq;
455 };
456  // end of xlio_socket group
458 
465 #define XLIO_SOCKET_SEND_FLAG_FLUSH 0x1
467 #define XLIO_SOCKET_SEND_FLAG_INLINE 0x2
468 
490  unsigned flags;
491  uint32_t mkey;
492  uintptr_t userdata_op;
493 };
494  // end of xlio_tx group
496  // end of xlio_ultra_api group
498 
499 #endif /* XLIO_TYPES_H */
void(* xlio_socket_event_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, int event, int value)
Socket event callback function.
Definition: xlio_types.h:275
void(* xlio_memory_cb_t)(void *addr, size_t len, size_t hugepage_size)
Memory allocation callback function.
Definition: xlio_types.h:234
void(* xlio_socket_accept_cb_t)(xlio_socket_t sock, xlio_socket_t parent, uintptr_t parent_userdata_sq)
Accept callback function.
Definition: xlio_types.h:341
void(* xlio_socket_rx_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, void *data, size_t len, struct xlio_buf *buf)
Receive data callback function.
Definition: xlio_types.h:321
void(* xlio_socket_comp_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, uintptr_t userdata_op)
Zero-copy completion callback function.
Definition: xlio_types.h:299
@ XLIO_SOCKET_EVENT_ESTABLISHED
Definition: xlio_types.h:239
@ XLIO_SOCKET_EVENT_ERROR
Definition: xlio_types.h:245
@ XLIO_SOCKET_EVENT_CLOSED
Definition: xlio_types.h:243
@ XLIO_SOCKET_EVENT_TERMINATED
Definition: xlio_types.h:241
uintptr_t xlio_poll_group_t
Polling group handle.
Definition: xlio_types.h:164
uintptr_t xlio_socket_t
Socket handle.
Definition: xlio_types.h:172
Buffer descriptor.
Definition: xlio_types.h:198
XLIO initialization attributes.
Definition: xlio_types.h:371
Polling group attributes.
Definition: xlio_types.h:414
Definition: xlio_types.h:73
Definition: xlio_types.h:111
Socket creation attributes.
Definition: xlio_types.h:450
Send operation attributes.
Definition: xlio_types.h:489