CNDP  22.08.0
pktdev_api.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <cne_common.h>
#include <cne_lport.h>
#include <netdev_funcs.h>
#include <pktmbuf.h>

Go to the source code of this file.

Macros

#define PKTDEV_STARTED   (1 << 1)
 
#define pktdev_admin_state_up(_pid)   pktdev_admin_state_set(_pid, true)
 

Typedefs

typedef uint16_t(* cne_rx_callback_fn) (uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts, uint16_t max_pkts, void *user_param)
 
typedef uint16_t(* cne_tx_callback_fn) (uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts, void *user_param)
 

Functions

CNDP_API uint16_t pktdev_port_count (void)
 
CNDP_API int pktdev_start (uint16_t lport_id)
 
CNDP_API int pktdev_stop (uint16_t lport_id)
 
CNDP_API int pktdev_set_admin_state_up (uint16_t lport_id)
 
CNDP_API int pktdev_set_admin_state_down (uint16_t lport_id)
 
CNDP_API int pktdev_close (uint16_t lport_id)
 
CNDP_API int pktdev_close_all (void)
 
CNDP_API int pktdev_stats_get (uint16_t lport_id, lport_stats_t *stats)
 
CNDP_API int pktdev_stats_reset (uint16_t lport_id)
 
CNDP_API int pktdev_macaddr_get (uint16_t lport_id, struct ether_addr *mac_addr)
 
CNDP_API int pktdev_offloads_get (uint16_t lport_id, struct offloads *off)
 
CNDP_API int pktdev_info_get (uint16_t lport_id, struct pktdev_info *dev_info)
 
CNDP_API int pktdev_get_mtu (uint16_t lport_id, uint16_t *mtu)
 
CNDP_API int pktdev_set_mtu (uint16_t lport_id, uint16_t mtu)
 
CNDP_API int pktdev_get_name_by_port (uint16_t lport_id, char *name, uint32_t len)
 
CNDP_API int pktdev_get_port_by_name (const char *name, uint16_t *lport_id)
 
CNDP_API const char * pktdev_port_name (uint16_t lport_id)
 
CNDP_API int pktdev_is_valid_port (uint16_t lport_id)
 
CNDP_API int pktdev_socket_id (uint16_t lport_id)
 
CNDP_API struct cne_pktdev * pktdev_get (uint16_t lport_id)
 
CNDP_API int pktdev_portid (struct cne_pktdev *dev)
 
CNDP_API int pktdev_port_setup (lport_cfg_t *c)
 
CNDP_API void lport_cfg_dump (FILE *f, lport_cfg_t *c)
 
CNDP_API bool pktdev_admin_state (uint16_t lport_id)
 
CNDP_API int pktdev_admin_state_set (uint16_t lport_id, bool state)
 
CNDP_API void * pktdev_arg_get (uint16_t lport_id)
 
CNDP_API int pktdev_buf_alloc (int lport_id, pktmbuf_t **bufs, uint16_t nb_bufs)
 

Detailed Description

pktdev structures and APIs.

Definition in file pktdev_api.h.

Macro Definition Documentation

◆ PKTDEV_STARTED

#define PKTDEV_STARTED   (1 << 1)

Device state: STARTED(1) / STOPPED(0).

Definition at line 52 of file pktdev_api.h.

◆ pktdev_admin_state_up

#define pktdev_admin_state_up (   _pid)    pktdev_admin_state_set(_pid, true)

Macros to enable/disable admin state of a port.

Definition at line 431 of file pktdev_api.h.

Typedef Documentation

◆ cne_rx_callback_fn

typedef uint16_t(* cne_rx_callback_fn) (uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts, uint16_t max_pkts, void *user_param)

Function type used for RX packet processing packet callbacks.

The callback function is called on RX with a burst of packets that have been received on the given lport and queue.

Parameters
lport_idThe Ethernet lport on which RX is being performed.
pktsThe burst of packets that have just been received.
nb_pktsThe number of packets in the burst pointed to by "pkts".
max_pktsThe max number of packets that can be stored in the "pkts" array.
user_paramThe arbitrary user parameter passed in by the application when the callback was originally configured.
Returns
The number of packets returned to the user.

Definition at line 74 of file pktdev_api.h.

◆ cne_tx_callback_fn

typedef uint16_t(* cne_tx_callback_fn) (uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts, void *user_param)

Function type used for TX packet processing packet callbacks.

The callback function is called on TX with a burst of packets immediately before the packets are put onto the hardware queue for transmission.

Parameters
lport_idThe Ethernet lport on which TX is being performed.
pktsThe burst of packets that are about to be transmitted.
nb_pktsThe number of packets in the burst pointed to by "pkts".
user_paramThe arbitrary user parameter passed in by the application when the callback was originally configured.
Returns
The number of packets to be written to the NIC.

Definition at line 95 of file pktdev_api.h.

Function Documentation

◆ pktdev_port_count()

CNDP_API uint16_t pktdev_port_count ( void  )

Get the number of lports which are usable for the application.

Returns
The count of available Ethernet devices.
Examples
examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, and examples/l3fwd-graph/fwd.c.

◆ pktdev_start()

CNDP_API int pktdev_start ( uint16_t  lport_id)

Start an Ethernet device.

The device start step is the last one and consists of setting the configured offload features and in starting the transmit and the receive units of the device.

On success, all basic functions exported by the Ethernet API (link status, receive/transmit, and so on) can be invoked.

Parameters
lport_idThe lport identifier of the Ethernet device.
Returns
  • 0: Success, Ethernet device started.
  • <0: Error code of the driver device start function.

◆ pktdev_stop()

CNDP_API int pktdev_stop ( uint16_t  lport_id)

Stop an Ethernet device. The device can be restarted with a call to pktdev_start()

Parameters
lport_idThe lport identifier of the Ethernet device.
Returns
  • 0: Success, Ethernet device stopped.
  • <0: Error code of the driver device stop function.

◆ pktdev_set_admin_state_up()

CNDP_API int pktdev_set_admin_state_up ( uint16_t  lport_id)

Set admin state to UP

Set admin state up will re-enable the stream functionality after it is previously set down.

Parameters
lport_idThe lport identifier of the Ethernet device.
Returns
  • 0: Success, Admni state linked up.
  • <0: Error code of the driver admin state up function.

◆ pktdev_set_admin_state_down()

CNDP_API int pktdev_set_admin_state_down ( uint16_t  lport_id)

Set admin state to DOWN

The stream functionality will be disabled if success, and it can be re-enabled with a call to pktdev_set_admin_state_up()

Parameters
lport_idThe lport identifier of the Ethernet device.
Returns
0 on success or -1 on error

◆ pktdev_close()

CNDP_API int pktdev_close ( uint16_t  lport_id)

Close a stopped Ethernet device. The device cannot be restarted!

The function frees all lport resources if the driver supports the flag PKTDEV_DEV_CLOSE_REMOVE.

Parameters
lport_idThe lport identifier of the Ethernet device.
Returns
0 on success or -EINVAL on invalid lport_id or not configured.
Examples
examples/cndpfwd/main.c, examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, examples/dlb_test/dlb_test.c, and examples/l3fwd-graph/fwd.c.

◆ pktdev_close_all()

CNDP_API int pktdev_close_all ( void  )

Close all devices

Returns
0 on success or -EINVAL on error from pktdev_close().

◆ pktdev_stats_get()

CNDP_API int pktdev_stats_get ( uint16_t  lport_id,
lport_stats_t *  stats 
)

Retrieve the general I/O statistics of an Ethernet device.

Parameters
lport_idThe lport identifier of the Ethernet device.
statsA pointer to a structure of type lport_stats to be filled with the values of device counters for the following set of statistics:
  • ipackets with the total of successfully received packets.
  • opackets with the total of successfully transmitted packets.
  • ibytes with the total of successfully received bytes.
  • obytes with the total of successfully transmitted bytes.
  • ierrors with the total of erroneous received packets.
  • oerrors with the total of failed transmitted packets.
Returns
Zero if successful. Non-zero otherwise.
Examples
examples/cndpfwd/stats.c, examples/cnet-graph/stats.c, examples/cnet-quic/stats.c, examples/dlb_test/stats.c, and examples/l3fwd-graph/stats.c.

◆ pktdev_stats_reset()

CNDP_API int pktdev_stats_reset ( uint16_t  lport_id)

Reset the general I/O statistics of an Ethernet device.

Parameters
lport_idThe lport identifier of the Ethernet device.
Returns
  • (0) if device notified to reset stats.
  • (-ENOTSUP) if hardware doesn't support.
  • (-ENODEV) if lport_id invalid.
  • (<0): Error code of the driver stats reset function.

◆ pktdev_macaddr_get()

CNDP_API int pktdev_macaddr_get ( uint16_t  lport_id,
struct ether_addr mac_addr 
)

Retrieve the Ethernet address of an Ethernet device.

Parameters
lport_idThe lport identifier of the Ethernet device.
mac_addrA pointer to a structure of type ether_addr to be filled with the Ethernet address of the Ethernet device.
Returns
  • (0) if successful
  • (-ENODEV) if lport_id invalid.
  • (-EINVAL) if mac_addr invalid.
Examples
examples/l3fwd-graph/fwd.c.

◆ pktdev_offloads_get()

CNDP_API int pktdev_offloads_get ( uint16_t  lport_id,
struct offloads off 
)

Retrieve the offloads configuration of a netdevice.

Parameters
lport_idThe lport identifier of the Ethernet device.
offA pointer to a structure of type struct offloads to be filled with the offloads configuration of the netdevice
Returns
  • (0) if successful
  • (-ENODEV) if lport_id invalid.
  • (-EINVAL) if off invalid.

◆ pktdev_info_get()

CNDP_API int pktdev_info_get ( uint16_t  lport_id,
struct pktdev_info dev_info 
)

Retrieve the contextual information of an Ethernet device.

As part of this function, a number of of fields in dev_info will be initialized as follows:

device = dev->device min_mtu = CNE_ETHER_MIN_MTU max_mtu = UINT16_MAX

The following fields will be populated if support for dev_infos_get() exists for the device and the cne_pktdev 'dev' has been populated successfully with a call to it:

driver_name = dev->device->driver->name nb_rx_queues = dev->data->nb_rx_queues nb_tx_queues = dev->data->nb_tx_queues

Parameters
lport_idThe lport identifier of the Ethernet device.
dev_infoA pointer to a structure of type pktdev_info to be filled with the contextual information of the Ethernet device.
Returns
  • (0) if successful.
  • (-ENOTSUP) if support for dev_infos_get() does not exist for the device.
  • (-ENODEV) if lport_id invalid.

◆ pktdev_get_mtu()

CNDP_API int pktdev_get_mtu ( uint16_t  lport_id,
uint16_t *  mtu 
)

Retrieve the MTU of an Ethernet device.

Parameters
lport_idThe lport identifier of the Ethernet device.
mtuA pointer to a uint16_t where the retrieved MTU is to be stored.
Returns
  • (0) if successful.
  • (-ENODEV) if lport_id invalid.

◆ pktdev_set_mtu()

CNDP_API int pktdev_set_mtu ( uint16_t  lport_id,
uint16_t  mtu 
)

Change the MTU of an Ethernet device.

Parameters
lport_idThe lport identifier of the Ethernet device.
mtuA uint16_t for the MTU to be applied.
Returns
  • (0) if successful.
  • (-ENOTSUP) if operation is not supported.
  • (-ENODEV) if lport_id invalid.
  • (-EIO) if device is removed.
  • (-EINVAL) if mtu invalid, validation of mtu can occur within pktdev_set_mtu if dev_infos_get is supported by the device or when the mtu is set using dev->dev_ops->mtu_set.
  • (-EBUSY) if operation is not allowed when the lport is running

◆ pktdev_get_name_by_port()

CNDP_API int pktdev_get_name_by_port ( uint16_t  lport_id,
char *  name,
uint32_t  len 
)

Get the lport name by lport id

Parameters
lport_idThe lport id or index into the pktdev_devices array
namePointer to a string array to put the name, will be null terminated.
lenLength of the name buffer pointer
Returns
0 on success or -1 on error

◆ pktdev_get_port_by_name()

CNDP_API int pktdev_get_port_by_name ( const char *  name,
uint16_t *  lport_id 
)

Get lport id by name of lport

Parameters
namePointer to lport name string
lport_idPointer to uint16_t value to return lport id
Returns
0 on success or -1 on error

◆ pktdev_port_name()

CNDP_API const char* pktdev_port_name ( uint16_t  lport_id)

Return constructed lport name from lport id

Parameters
lport_idThe lport id to create lport name
Returns
NULL on error or pointer to lport name string

◆ pktdev_is_valid_port()

CNDP_API int pktdev_is_valid_port ( uint16_t  lport_id)

Test if lport is a valid lport id

Parameters
lport_idThe lport id to test
Returns
1 if lport id is valid or zero on not-valid
Examples
examples/l3fwd-graph/fwd.c.

◆ pktdev_socket_id()

CNDP_API int pktdev_socket_id ( uint16_t  lport_id)

return socket id of the lport

Parameters
lport_idThe lport to access for socket id
Returns
-1 on error or socket id value

◆ pktdev_get()

CNDP_API struct cne_pktdev* pktdev_get ( uint16_t  lport_id)

Return the pktdev_devices[lport_id] pointer

Parameters
lport_idThe lport id to use to locate cne_pktdev structure
Returns
NULL on error or pointer to pktdev_devices[]

◆ pktdev_portid()

CNDP_API int pktdev_portid ( struct cne_pktdev *  dev)

Returns the pktdev lportid index

Parameters
devPointer to a valid pktdev_devices structure.
Returns
The lportid or index of the device structure or -1 on error

◆ pktdev_port_setup()

CNDP_API int pktdev_port_setup ( lport_cfg_t c)

Port setup helper routine to simplify bring up a lport using the defaults

Parameters
cThe structure to use for setting up the lport. See the structure and driver docs to see how this structure is used.
Returns
The lport number or -1 on error
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

◆ lport_cfg_dump()

CNDP_API void lport_cfg_dump ( FILE *  f,
lport_cfg_t c 
)

Dump out a lport_cfg_t structure.

Parameters
fThe FILE descriptor to use or NULL for stdout.
cThe lport_cfg_t pointer

◆ pktdev_admin_state()

CNDP_API bool pktdev_admin_state ( uint16_t  lport_id)

Get the packet stream state flag for the given lport.

Parameters
lport_idThe lport id to use to locate cne_pktdev structure
Returns
pkt_admin_state

◆ pktdev_admin_state_set()

CNDP_API int pktdev_admin_state_set ( uint16_t  lport_id,
bool  state 
)

Set the packet stream state flag for the given lport.

Parameters
lport_idThe lport id to use to locate cne_pktdev structure
statePacket stream state flag
Returns
Zero on success or -1 on error

◆ pktdev_arg_get()

CNDP_API void* pktdev_arg_get ( uint16_t  lport_id)

Get the argument value for alloc/free routines.

Parameters
lport_idThe lport ID value.
Returns
The argument value is returned.

◆ pktdev_buf_alloc()

CNDP_API int pktdev_buf_alloc ( int  lport_id,
pktmbuf_t **  bufs,
uint16_t  nb_bufs 
)

Allocate a set of buffers using the user supplied allocate/free routines

Parameters
lport_idThe lport ID value
bufsThe array of buffer pointers to be allocated.
nb_bufsThe number of buffers to be allocated
Returns
The number of buffers allocated or -1 on error
Examples
examples/cndpfwd/main.c, and examples/cnet-quic/quic-cli.c.