CNDP  22.08.0
pktdev_api.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation.
3  */
4 
5 #ifndef __PKTDEV_API_H
6 #define __PKTDEV_API_H
7 
14 #include <stdbool.h> // for bool, false, true
15 #include <stdint.h> // for uint16_t
16 #include <stdio.h> // for NULL, FILE
17 
18 #include <cne_common.h> // for CNDP_API
19 #include <cne_lport.h> // for lport_cfg_t, lport_stats_t
20 #include <netdev_funcs.h> // for struct offloads
21 #include <pktmbuf.h> // for pktmbuf_t
22 
23 struct ether_addr;
24 struct cne_pktdev;
25 struct pktdev_info;
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 enum {
32  CFG_CREATE_NONE = 0,
33  CFG_CREATE_RX,
34  CFG_CREATE_TX,
35  CFG_CREATE_MASK,
36  CFG_SHARE_MEMPOOL,
37 };
38 
39 /* Macros to check for invalid function pointers */
40 #define FUNC_PTR_OR_ERR_RET(func, retval) \
41  do { \
42  if ((func) == NULL) \
43  return retval; \
44  } while (0)
45 
46 #define FUNC_PTR_OR_RET(func) \
47  do { \
48  if ((func) == NULL) \
49  return; \
50  } while (0)
51 
52 #define PKTDEV_STARTED (1 << 1)
74 typedef uint16_t (*cne_rx_callback_fn)(uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts,
75  uint16_t max_pkts, void *user_param);
76 
95 typedef uint16_t (*cne_tx_callback_fn)(uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts,
96  void *user_param);
97 
104 CNDP_API uint16_t pktdev_port_count(void);
105 
122 CNDP_API int pktdev_start(uint16_t lport_id);
123 
134 CNDP_API int pktdev_stop(uint16_t lport_id);
135 
148 CNDP_API int pktdev_set_admin_state_up(uint16_t lport_id);
149 
162 CNDP_API int pktdev_set_admin_state_down(uint16_t lport_id);
163 
175 CNDP_API int pktdev_close(uint16_t lport_id);
176 
183 CNDP_API int pktdev_close_all(void);
184 
202 CNDP_API int pktdev_stats_get(uint16_t lport_id, lport_stats_t *stats);
203 
215 CNDP_API int pktdev_stats_reset(uint16_t lport_id);
216 
230 CNDP_API int pktdev_macaddr_get(uint16_t lport_id, struct ether_addr *mac_addr);
231 
245 CNDP_API int pktdev_offloads_get(uint16_t lport_id, struct offloads *off);
246 
275 CNDP_API int pktdev_info_get(uint16_t lport_id, struct pktdev_info *dev_info);
276 
288 CNDP_API int pktdev_get_mtu(uint16_t lport_id, uint16_t *mtu);
289 
307 CNDP_API int pktdev_set_mtu(uint16_t lport_id, uint16_t mtu);
308 
321 CNDP_API int pktdev_get_name_by_port(uint16_t lport_id, char *name, uint32_t len);
322 
333 CNDP_API int pktdev_get_port_by_name(const char *name, uint16_t *lport_id);
334 
343 CNDP_API const char *pktdev_port_name(uint16_t lport_id);
344 
353 CNDP_API int pktdev_is_valid_port(uint16_t lport_id);
354 
363 CNDP_API int pktdev_socket_id(uint16_t lport_id);
364 
373 CNDP_API struct cne_pktdev *pktdev_get(uint16_t lport_id);
374 
383 CNDP_API int pktdev_portid(struct cne_pktdev *dev);
384 
395 
404 CNDP_API void lport_cfg_dump(FILE *f, lport_cfg_t *c);
405 
414 CNDP_API bool pktdev_admin_state(uint16_t lport_id);
415 
426 CNDP_API int pktdev_admin_state_set(uint16_t lport_id, bool state);
427 
431 #define pktdev_admin_state_up(_pid) pktdev_admin_state_set(_pid, true)
432 #define pktdev_admin_state_down(_pid) pktdev_admin_state_set(_pid, false)
433 
442 CNDP_API void *pktdev_arg_get(uint16_t lport_id);
443 
456 CNDP_API int pktdev_buf_alloc(int lport_id, pktmbuf_t **bufs, uint16_t nb_bufs);
457 
458 #ifdef __cplusplus
459 }
460 #endif
461 
462 #endif /* __PKTDEV_API_H */
struct lport_cfg lport_cfg_t
CNDP_API int pktdev_macaddr_get(uint16_t lport_id, struct ether_addr *mac_addr)
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 struct cne_pktdev * pktdev_get(uint16_t lport_id)
CNDP_API int pktdev_close_all(void)
CNDP_API int pktdev_buf_alloc(int lport_id, pktmbuf_t **bufs, uint16_t nb_bufs)
CNDP_API int pktdev_set_admin_state_up(uint16_t lport_id)
CNDP_API int pktdev_set_mtu(uint16_t lport_id, uint16_t mtu)
CNDP_API int pktdev_close(uint16_t lport_id)
CNDP_API int pktdev_socket_id(uint16_t lport_id)
CNDP_API int pktdev_offloads_get(uint16_t lport_id, struct offloads *off)
CNDP_API int pktdev_start(uint16_t lport_id)
CNDP_API int pktdev_info_get(uint16_t lport_id, struct pktdev_info *dev_info)
CNDP_API const char * pktdev_port_name(uint16_t lport_id)
uint16_t(* cne_tx_callback_fn)(uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts, void *user_param)
Definition: pktdev_api.h:95
CNDP_API int pktdev_portid(struct cne_pktdev *dev)
CNDP_API int pktdev_stats_get(uint16_t lport_id, lport_stats_t *stats)
CNDP_API int pktdev_admin_state_set(uint16_t lport_id, bool state)
CNDP_API int pktdev_stop(uint16_t lport_id)
CNDP_API int pktdev_is_valid_port(uint16_t lport_id)
CNDP_API void * pktdev_arg_get(uint16_t lport_id)
CNDP_API int pktdev_stats_reset(uint16_t lport_id)
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_set_admin_state_down(uint16_t lport_id)
CNDP_API int pktdev_get_mtu(uint16_t lport_id, uint16_t *mtu)
CNDP_API int pktdev_port_setup(lport_cfg_t *c)
uint16_t(* cne_rx_callback_fn)(uint16_t lport_id, pktmbuf_t *pkts[], uint16_t nb_pkts, uint16_t max_pkts, void *user_param)
Definition: pktdev_api.h:74
CNDP_API uint16_t pktdev_port_count(void)