CNDP  22.08.0
xskdev.h File Reference
#include <poll.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <bpf/xsk.h>
#include <net/if.h>
#include <cne_common.h>
#include <cne_lport.h>
#include <pktmbuf.h>
#include <uds.h>

Go to the source code of this file.

Macros

#define XSKDEV_STATS_FLAG   (1 << 0)
 
#define XSKDEV_RX_FQ_TX_CQ_FLAG   (1 << 1)
 

Functions

CNDP_API xskdev_info_t * xskdev_socket_create (struct lport_cfg *c)
 
CNDP_API void xskdev_socket_destroy (xskdev_info_t *xi)
 
CNDP_API __cne_always_inline uint16_t xskdev_rx_burst (xskdev_info_t *xi, void **bufs, uint16_t nb_pkts)
 
CNDP_API __cne_always_inline uint16_t xskdev_tx_burst (xskdev_info_t *xi, void **bufs, uint16_t nb_pkts)
 
CNDP_API int xskdev_stats_get (xskdev_info_t *xi, lport_stats_t *stats)
 
CNDP_API int xskdev_stats_reset (xskdev_info_t *xi)
 
CNDP_API void xskdev_dump (xskdev_info_t *xi, uint32_t flags)
 
CNDP_API void xskdev_dump_all (uint32_t flags)
 
CNDP_API int xskdev_print_stats (const char *name, lport_stats_t *s, bool dbg_stats)
 
CNDP_API __cne_always_inline void * xskdev_arg_get (xskdev_info_t *xi)
 
CNDP_API __cne_always_inline int xskdev_buf_alloc (xskdev_info_t *xi, void **bufs, uint16_t nb_bufs)
 
CNDP_API __cne_always_inline void xskdev_buf_free (xskdev_info_t *xi, void **bufs, uint16_t nb_bufs)
 
CNDP_API __cne_always_inline void xskdev_buf_set_len (xskdev_info_t *xi, void *buf, int len)
 
CNDP_API __cne_always_inline void xskdev_buf_set_data_len (xskdev_info_t *xi, void *buf, int len)
 
CNDP_API __cne_always_inline void xskdev_buf_set_data (xskdev_info_t *xi, void *buf, uint64_t off)
 
CNDP_API __cne_always_inline uint16_t xskdev_buf_get_data_len (xskdev_info_t *xi, void *buf)
 
CNDP_API __cne_always_inline uint64_t xskdev_buf_get_data (xskdev_info_t *xi, void *buf)
 
CNDP_API __cne_always_inline uint64_t xskdev_buf_get_addr (xskdev_info_t *xi, void *buf)
 
CNDP_API __cne_always_inline void ** xskdev_buf_inc_ptr (xskdev_info_t *xi, void **buf)
 
CNDP_API __cne_always_inline void xskdev_buf_reset (xskdev_info_t *xi, void *buf, uint32_t buf_len, size_t headroom)
 

Detailed Description

CNE XSK low-level abstraction

This file provides a low-level abstraction for applications to XSK APIs.

Definition in file xskdev.h.

Macro Definition Documentation

◆ XSKDEV_STATS_FLAG

#define XSKDEV_STATS_FLAG   (1 << 0)

flag to xskdev_dump() to dump out the stats

Definition at line 60 of file xskdev.h.

◆ XSKDEV_RX_FQ_TX_CQ_FLAG

#define XSKDEV_RX_FQ_TX_CQ_FLAG   (1 << 1)

Flag to dump the RX/FQ/TX/CQ rings/queues

Definition at line 61 of file xskdev.h.

Function Documentation

◆ xskdev_socket_create()

CNDP_API xskdev_info_t* xskdev_socket_create ( struct lport_cfg *  c)

Create a xsk socket helper routine using lport configuration

Parameters
cThe lport configuration structure
Returns
The pointer to the xskdev_info_t structure or NULL on error
Examples
examples/cndpfwd/parse-args.c, and examples/vpp-plugin/cndp/device.c.

◆ xskdev_socket_destroy()

CNDP_API void xskdev_socket_destroy ( xskdev_info_t *  xi)

Close the xsk socket and free resources.

Parameters
xiThe xskdev_info_t structure returned by xskdev_socket_create() routine
Examples
examples/cndpfwd/main.c, and examples/vpp-plugin/cndp/device.c.

◆ xskdev_rx_burst()

CNDP_API __cne_always_inline uint16_t xskdev_rx_burst ( xskdev_info_t *  xi,
void **  bufs,
uint16_t  nb_pkts 
)

Receive packets from the interface

Parameters
xiThe void * type of xskdev_info_t structure
bufsThe list or vector or pktmbufs structures to send on the interface.
nb_pktsThe number of pktmbuf_t pointers in the list or vector bufs
Returns
The number of packet sent to the interface or 0 if RX is empty.
Examples
examples/cndpfwd/acl-func.c, examples/cndpfwd/main.c, and examples/vpp-plugin/cndp/input.c.

Definition at line 168 of file xskdev.h.

◆ xskdev_tx_burst()

CNDP_API __cne_always_inline uint16_t xskdev_tx_burst ( xskdev_info_t *  xi,
void **  bufs,
uint16_t  nb_pkts 
)

Send buffers to be transmitted

Parameters
xiThe void * type of xskdev_info_t structure
bufsThe list or vector or pktmbufs structures to send on the interface.
nb_pktsThe number of pktmbuf_t pointers in the list or vector bufs
Returns
The number of packet sent to the interface or 0 if RX is empty.
Examples
examples/cndpfwd/main.c, and examples/vpp-plugin/cndp/output.c.

Definition at line 186 of file xskdev.h.

◆ xskdev_stats_get()

CNDP_API int xskdev_stats_get ( xskdev_info_t *  xi,
lport_stats_t *  stats 
)

Get the stats for the interface

Parameters
xiThe xskdev_info_t structure pointer
statsThe lport stats structure to fill in
Returns
0 on success or -1 on error
Examples
examples/cndpfwd/stats.c.

◆ xskdev_stats_reset()

CNDP_API int xskdev_stats_reset ( xskdev_info_t *  xi)

Reset or clear the stats for an interface

Parameters
xiThe xskdev_info_t structure pointer
Returns
0 on success or -1 on error.

◆ xskdev_dump()

CNDP_API void xskdev_dump ( xskdev_info_t *  xi,
uint32_t  flags 
)

Debug routine to dump out information about xskdev data

Parameters
xiThe xskdev_info_t structure pointer
flagsFlags used to control the amount of information dumped.

◆ xskdev_dump_all()

CNDP_API void xskdev_dump_all ( uint32_t  flags)

Debug routine dump all of the xskdev interfaces.

Parameters
flagsFlags used to control the amount of information dumped.

◆ xskdev_print_stats()

CNDP_API int xskdev_print_stats ( const char *  name,
lport_stats_t *  s,
bool  dbg_stats 
)

Print the port statistics information.

Parameters
nameA name used to identify the port.
sThe pointer to the port statistics
dbg_statsPrint debug statistics if true.
Returns
0 on success or -1 on error

◆ xskdev_arg_get()

CNDP_API __cne_always_inline void* xskdev_arg_get ( xskdev_info_t *  xi)

Return the internal buffer management argument pointer.

Parameters
xiThe xskdev_info_t structure pointer.
Returns
The void * used for buffer allocation and free routines.

Definition at line 254 of file xskdev.h.

◆ xskdev_buf_alloc()

CNDP_API __cne_always_inline int xskdev_buf_alloc ( xskdev_info_t *  xi,
void **  bufs,
uint16_t  nb_bufs 
)

Allocate the number of buffers requested.

Parameters
xiThe pointer to the xskdev_info structure.
bufsThe array of buffer pointers to store the allocated buffers.
nb_bufsThe max number of buffers pointers to allocate.
Returns
The number of bufs allocated in the bufs array.

Definition at line 272 of file xskdev.h.

◆ xskdev_buf_free()

CNDP_API __cne_always_inline void xskdev_buf_free ( xskdev_info_t *  xi,
void **  bufs,
uint16_t  nb_bufs 
)

Free the number of buffers listed in the bufs array.

Parameters
xiThe pointer to the xskdev_info struct.
bufsThe array of buf pointers to free.
nb_bufsThe max number of xbuf pointers to free in the array.

Definition at line 288 of file xskdev.h.

◆ xskdev_buf_set_len()

CNDP_API __cne_always_inline void xskdev_buf_set_len ( xskdev_info_t *  xi,
void *  buf,
int  len 
)

Set the buffer Length.

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer to set the length of.
lenThe length to set the buffer length to.

Definition at line 305 of file xskdev.h.

◆ xskdev_buf_set_data_len()

CNDP_API __cne_always_inline void xskdev_buf_set_data_len ( xskdev_info_t *  xi,
void *  buf,
int  len 
)

Set the buffer data Length.

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer to set the data length of.
lenThe length to set the buffer data length to.

Definition at line 322 of file xskdev.h.

◆ xskdev_buf_set_data()

CNDP_API __cne_always_inline void xskdev_buf_set_data ( xskdev_info_t *  xi,
void *  buf,
uint64_t  off 
)

Set the buffer data pointer

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer to set the data pointer of.
offThe offset to set the data pointer to.

Definition at line 338 of file xskdev.h.

◆ xskdev_buf_get_data_len()

CNDP_API __cne_always_inline uint16_t xskdev_buf_get_data_len ( xskdev_info_t *  xi,
void *  buf 
)

Get the buffer data length.

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer to get the data length of.
Returns
The data length of the buffer.

Definition at line 354 of file xskdev.h.

◆ xskdev_buf_get_data()

CNDP_API __cne_always_inline uint64_t xskdev_buf_get_data ( xskdev_info_t *  xi,
void *  buf 
)

Get the buffer data pointer.

Parameters
xiThe pointer to the xskdev_info struct.
bufThe array of xbuf pointers to free.
Returns
The address of the data pointer.

Definition at line 370 of file xskdev.h.

◆ xskdev_buf_get_addr()

CNDP_API __cne_always_inline uint64_t xskdev_buf_get_addr ( xskdev_info_t *  xi,
void *  buf 
)

Get the virtual address of the segment buffer.

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer to get the address of.
Returns
The the virtual address of the segment buffer.

Definition at line 386 of file xskdev.h.

◆ xskdev_buf_inc_ptr()

CNDP_API __cne_always_inline void** xskdev_buf_inc_ptr ( xskdev_info_t *  xi,
void **  buf 
)

Increment the buffer array pointer

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer ptr to increment.

Definition at line 400 of file xskdev.h.

◆ xskdev_buf_reset()

CNDP_API __cne_always_inline void xskdev_buf_reset ( xskdev_info_t *  xi,
void *  buf,
uint32_t  buf_len,
size_t  headroom 
)

Reset a buffer.

Parameters
xiThe pointer to the xskdev_info struct.
bufThe buffer to reset.
buf_lenThe max data length able to be contained in the buffer. If the buffer is 2K and it contains a mbuf like header then buf_len = (2K - sizeof(mbuf)).
headroomThe buffer headroom to offset the data pointer by (if needed).

Definition at line 420 of file xskdev.h.