CNDP  22.08.0
cne_lport.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 _CNE_LPORT_H_
6 #define _CNE_LPORT_H_
7 
14 #include <stdint.h> // for uint16_t, uint32_t
15 #include <sys/types.h>
16 #include <stdbool.h>
17 #include <pktmbuf.h>
18 
19 #include <cne_common.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define LPORT_NAME_LEN 32
26 #define LPORT_FRAME_SIZE 2048
27 #define LPORT_MBUF_OVERHEAD sizeof(struct pkt_buf)
28 #define LPORT_DATA_HEADROOM XDP_PACKET_HEADROOM
29 #define LPORT_DFLT_RX_NUM_DESCS XSK_RING_CONS__DEFAULT_NUM_DESCS
30 #define LPORT_DFLT_TX_NUM_DESCS (XSK_RING_CONS__DEFAULT_NUM_DESCS * 2)
31 #define LPORT_FRAME_SHIFT 11 /* Log2(2048) of LPORT_FRAME_SIZE to avoid a divide */
32 #define LPORT_DFLT_START_QUEUE_IDX 0
33 #define LPORT_DFLT_QUEUE_COUNT 1
34 #define LPORT_RX_BATCH_SIZE 256
35 #define LPORT_TX_BATCH_SIZE 256
36 
37 typedef int (*buf_alloc_t)(void *arg, void **bufs, uint16_t nb_pkts);
38 typedef void (*buf_free_t)(void *arg, void **bufs, uint16_t nb_pkts);
39 typedef void (*buf_set_len_t)(void *buf, int len);
40 typedef void (*buf_set_data_len_t)(void *buf, int len);
41 typedef void (*buf_set_data_t)(void *buf, uint64_t off);
42 typedef void (*buf_reset_t)(void *buf, uint32_t buf_len, size_t headroom);
43 typedef void **(*buf_inc_ptr_t)(void **buf);
44 typedef uint16_t (*buf_get_data_len_t)(void *buf);
45 typedef uint64_t (*buf_get_data_t)(void *buf);
46 typedef uint64_t (*buf_get_addr_t)(void *buf);
47 typedef uint16_t (*buf_rx_burst_t)(void *arg, void **bufs, uint16_t nb_pkts);
48 typedef uint16_t (*buf_tx_burst_t)(void *arg, void **bufs, uint16_t nb_pkts);
49 
50 typedef struct lport_buf_mgmt {
51  buf_alloc_t buf_alloc;
52  buf_free_t buf_free;
53  buf_set_len_t buf_set_len;
54  buf_set_data_len_t buf_set_data_len;
55  buf_set_data_t buf_set_data;
56  buf_reset_t buf_reset;
57  buf_get_data_len_t buf_get_data_len;
58  buf_get_data_t buf_get_data;
59  buf_get_addr_t buf_get_addr;
60  buf_inc_ptr_t buf_inc_ptr;
61  uint32_t frame_size;
62  size_t buf_headroom;
63  size_t pool_header_sz;
64  void *buf_arg;
65  buf_rx_burst_t buf_rx_burst;
66  buf_tx_burst_t buf_tx_burst;
67  bool unaligned_buff;
68 } lport_buf_mgmt_t;
69 
70 typedef struct lport_cfg {
71  char name[LPORT_NAME_LEN];
72  char ifname[LPORT_NAME_LEN];
73  char pmd_name[LPORT_NAME_LEN];
74  uint16_t flags;
75  uint16_t qid;
76  uint32_t bufcnt;
77  uint32_t bufsz;
78  uint32_t rx_nb_desc;
79  uint32_t tx_nb_desc;
80  uint16_t busy_timeout;
81  uint16_t busy_budget;
82  void *addr;
83  char *umem_addr;
84  char *pmd_opts;
85  size_t umem_size;
86  pktmbuf_info_t *pi;
87  void *xsk_uds;
88  lport_buf_mgmt_t buf_mgmt;
89 } lport_cfg_t;
90 
92 #define LPORT_UNPRIVILEGED (1 << 0)
93 #define LPORT_FORCE_WAKEUP (1 << 1)
94 #define LPORT_SKB_MODE (1 << 2)
95 #define LPORT_BUSY_POLLING (1 << 3)
96 #define LPORT_SHARED_UMEM (1 << 4)
97 #define LPORT_USER_MANAGED_BUFFERS (1 << 5)
98 #define LPORT_UMEM_UNALIGNED_BUFFERS (1 << 6)
100 typedef struct lport_stats {
101  uint64_t ipackets;
102  uint64_t opackets;
103  uint64_t ibytes;
104  uint64_t obytes;
105  uint64_t ierrors;
106  uint64_t oerrors;
107  uint64_t imissed;
108  uint64_t odropped;
109  uint64_t rx_invalid;
110  uint64_t tx_invalid;
111  /* RX debug stats */
112  uint64_t rx_ring_empty;
113  uint64_t rx_buf_alloc;
114  uint64_t rx_busypoll_wakeup;
115  uint64_t rx_poll_wakeup;
116  uint64_t rx_rcvd_count;
117  uint64_t rx_burst_called;
118 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
119  uint64_t rx_ring_full;
120  uint64_t rx_fill_ring_empty;
121  uint64_t tx_ring_empty;
122 #endif
123  /* FQ debug stats */
124  uint64_t fq_add_count;
125  uint64_t fq_alloc_failed;
126  uint64_t fq_buf_freed;
127  /* TX debug stats */
128  uint64_t tx_kicks;
129  uint64_t tx_kick_failed;
130  uint64_t tx_kick_again;
131  uint64_t tx_ring_full;
132  uint64_t tx_copied;
133  /* CQ debug stats */
134  uint64_t cq_empty;
135  uint64_t cq_buf_freed;
136 } lport_stats_t;
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* _CNE_LPORT_H_ */
struct lport_cfg lport_cfg_t