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-2026 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 
32  uint32_t rate; /* rate limit in Kbps */
33  uint32_t max_burst_sz; /* maximum burst size in bytes */
34  uint16_t typical_pkt_sz; /* typical packet size in bytes */
35 };
36 
37 typedef enum {
38  RING_LOGIC_PER_INTERFACE = 0,
39  RING_LOGIC_PER_IP = 1,
40  RING_LOGIC_PER_SOCKET = 10,
41  RING_LOGIC_PER_USER_ID = 11,
42  RING_LOGIC_PER_THREAD = 20,
43  RING_LOGIC_PER_CORE = 30,
44  RING_LOGIC_PER_CORE_ATTACH_THREADS = 31,
45  RING_LOGIC_PER_OBJECT = 32,
46  RING_LOGIC_LAST
47 } ring_logic_t;
48 
49 typedef enum {
50  XLIO_RING_ALLOC_MASK_RING_USER_ID = (1 << 0),
51  XLIO_RING_ALLOC_MASK_RING_INGRESS = (1 << 1),
52  XLIO_RING_ALLOC_MASK_RING_ENGRESS = (1 << 2),
53 } xlio_ring_alloc_logic_attr_comp_mask;
54 
55 /*
56  * @brief pass this struct to process by the library using setsockopt with
57  * @ref SO_XLIO_RING_ALLOC_LOGIC
58  * to set the allocation logic of this FD when he requests a ring.
59  * @note ring_alloc_logic is a mandatory
60  * @param comp_mask - what fields are read when processing this struct
61  * see @ref xlio_ring_alloc_logic_attr_comp_mask
62  * @param ring_alloc_logic- allocation ratio to use
63  * @param user_idx - when used RING_LOGIC_PER_USER_ID int @ref ring_alloc_logic
64  * this is the user id to define. This lets you define the same ring for
65  * few FD's regardless the interface\thread\core.
66  * @param ingress - RX ring
67  * @param engress - TX ring
68  */
70  uint32_t comp_mask;
71  ring_logic_t ring_alloc_logic;
72  uint32_t user_id;
73  uint32_t ingress : 1;
74  uint32_t engress : 1;
75  uint32_t reserved : 30;
76 };
77 
89 typedef uintptr_t xlio_poll_group_t;
90 
97 typedef uintptr_t xlio_socket_t;
98 
123 struct xlio_buf {
124  uint64_t userdata;
125 };
126  // end of xlio_rx group
128 
159 typedef void (*xlio_memory_cb_t)(void *addr, size_t len, size_t hugepage_size);
160 
162 enum {
171 };
172 
200 typedef void (*xlio_socket_event_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, int event,
201  int value);
202 
224 typedef void (*xlio_socket_comp_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq,
225  uintptr_t userdata_op);
226 
246 typedef void (*xlio_socket_rx_cb_t)(xlio_socket_t sock, uintptr_t userdata_sq, void *data,
247  size_t len, struct xlio_buf *buf);
248 
267  uintptr_t parent_userdata_sq);
268  // end of xlio_callbacks group
270 
297  unsigned flags;
298  xlio_memory_cb_t memory_cb;
299 
300  /* Optional external user allocator for XLIO buffers. */
301  void *(*memory_alloc)(size_t);
302  void (*memory_free)(void *);
303 };
304  // end of xlio_init group
306 
313 #define XLIO_GROUP_FLAG_SAFE 0x1
315 #define XLIO_GROUP_FLAG_DIRTY 0x2
316 
340  unsigned flags;
341 
342  xlio_socket_event_cb_t socket_event_cb;
343  xlio_socket_comp_cb_t socket_comp_cb;
344  xlio_socket_rx_cb_t socket_rx_cb;
345  xlio_socket_accept_cb_t socket_accept_cb;
346 };
347  // end of xlio_poll_group group
349 
376  unsigned flags;
377  int domain; /* AF_INET or AF_INET6 */
378  xlio_poll_group_t group;
379  uintptr_t userdata_sq;
380 };
381  // end of xlio_socket group
383 
390 #define XLIO_SOCKET_SEND_FLAG_FLUSH 0x1
392 #define XLIO_SOCKET_SEND_FLAG_INLINE 0x2
393 
415  unsigned flags;
416  uint32_t mkey;
417  uintptr_t userdata_op;
418 };
419  // end of xlio_tx group
421  // end of xlio_ultra_api group
423 
424 #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:200
void(* xlio_memory_cb_t)(void *addr, size_t len, size_t hugepage_size)
Memory allocation callback function.
Definition: xlio_types.h:159
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:266
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:246
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:224
@ XLIO_SOCKET_EVENT_ESTABLISHED
Definition: xlio_types.h:164
@ XLIO_SOCKET_EVENT_ERROR
Definition: xlio_types.h:170
@ XLIO_SOCKET_EVENT_CLOSED
Definition: xlio_types.h:168
@ XLIO_SOCKET_EVENT_TERMINATED
Definition: xlio_types.h:166
uintptr_t xlio_poll_group_t
Polling group handle.
Definition: xlio_types.h:89
uintptr_t xlio_socket_t
Socket handle.
Definition: xlio_types.h:97
Buffer descriptor.
Definition: xlio_types.h:123
XLIO initialization attributes.
Definition: xlio_types.h:296
Polling group attributes.
Definition: xlio_types.h:339
Definition: xlio_types.h:31
Definition: xlio_types.h:69
Socket creation attributes.
Definition: xlio_types.h:375
Send operation attributes.
Definition: xlio_types.h:414