CNDP  22.08.0
pktdev.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_H
6 #define __PKTDEV_H
7 
8 #include <cne_common.h>
9 #include <errno.h> // for EINVAL, ENOTSUP
10 #include <stddef.h> // for NULL
11 #include <stdint.h> // for uint16_t, uint32_t, uint64_t, uint8_t
12 #include <x86intrin.h> // _mm_shuffle_xxx
13 #include <mempool.h> // for mempool_t
14 #include <pktmbuf.h> // for pktmbuf_t
15 #include <emmintrin.h> // for _mm_loadu_si128, _mm_set_epi8, _mm_storeu_s...
16 #include <stdbool.h> // for bool
17 #include <tmmintrin.h> // for _mm_shuffle_epi8
18 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define PKTDEV_FOREACH(x) for (int x = 0; x < CNE_MAX_ETHPORTS; x++)
29 
35 #define PKTDEV_FALLBACK_RX_RINGSIZE 512
36 #define PKTDEV_FALLBACK_TX_RINGSIZE 512
37 #define PKTDEV_FALLBACK_RX_NBQUEUES 1
38 #define PKTDEV_FALLBACK_TX_NBQUEUES 1
39 #define PKTDEV_ADMIN_STATE_DOWN 0xFFFF
40 
41 #include <cne_lport.h>
42 
49  uint16_t nb_desc;
51 
57  uint16_t nb_desc;
59 
66  uint16_t burst_size;
67  uint16_t ring_size;
68 };
69 
79 struct pktdev_info {
80  const char *driver_name;
81  unsigned int if_index;
83  bool admin_state;
84  uint16_t min_mtu;
85  uint16_t max_mtu;
86  uint32_t min_rx_bufsize;
87  uint32_t max_rx_pktlen;
88  uint32_t min_tx_bufsize;
89  uint8_t hash_key_size;
91  uint32_t speed_capa;
97  uint64_t dev_capa;
98 } __cne_cache_aligned;
99 
100 #include <pktdev_api.h> // for pktdev_admin_state
101 #include <pktdev_core.h> // for cne_pktdev, pktdev_data, pktdev_devices
102 
103 #include "cne_common.h" // for CNE_MAX_ETHPORTS, __cne_cache_min_aligned
104 #include "cne_log.h" // for CNE_LOG_ERR
105 
106 // IWYU pragma: no_forward_declare cne_mempool
107 
182 static inline uint16_t
183 pktdev_rx_burst(uint16_t lport_id, pktmbuf_t **rx_pkts, const uint16_t nb_pkts)
184 {
185  struct cne_pktdev *dev = &pktdev_devices[lport_id];
186  uint16_t nb_rx;
187 
188 #ifdef PKTDEV_DEBUG
189  if (dev->rx_pkt_burst == NULL)
190  return 0;
191 #endif
192 
193  /* Check packet stream status */
194  if (!pktdev_admin_state(lport_id)) {
195  CNE_DEBUG("Packet stream is disabled for '%d'\n", lport_id);
196  return PKTDEV_ADMIN_STATE_DOWN;
197  }
198 
199  nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queue, rx_pkts, nb_pkts);
200 
201  return nb_rx;
202 }
203 
257 static inline uint16_t
258 pktdev_tx_burst(uint16_t lport_id, pktmbuf_t **tx_pkts, uint16_t nb_pkts)
259 {
260  struct cne_pktdev *dev;
261 
262 #ifdef PKTDEV_DEBUG
263  if (lport_id >= CNE_MAX_ETHPORTS)
264  return 0;
265 #endif
266 
267  dev = &pktdev_devices[lport_id];
268 
269 #ifdef PKTDEV_DEBUG
270  if (dev->tx_pkt_burst == NULL)
271  return 0;
272 #endif
273 
274  /* Check packet stream status */
275  if (!pktdev_admin_state(lport_id)) {
276  CNE_DEBUG("Packet stream is disabled for '%d'\n", lport_id);
277  return PKTDEV_ADMIN_STATE_DOWN;
278  }
279 
280  return (*dev->tx_pkt_burst)(dev->data->tx_queue, tx_pkts, nb_pkts);
281 }
282 
329 static inline uint16_t
330 pktdev_tx_prepare(uint16_t lport_id, pktmbuf_t **tx_pkts, uint16_t nb_pkts)
331 {
332  struct cne_pktdev *dev;
333 
334  dev = &pktdev_devices[lport_id];
335 
336  if (!dev->tx_pkt_prepare)
337  return nb_pkts;
338 
339  return (*dev->tx_pkt_prepare)(dev->data->tx_queue, tx_pkts, nb_pkts);
340 }
341 
350 static inline void
351 pktdev_mac_swap(void *data)
352 {
358  __m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6);
359 
360  __m128i hdr = _mm_loadu_si128((const __m128i_u *)data);
361  hdr = _mm_shuffle_epi8(hdr, shfl_msk);
362  _mm_storeu_si128((__m128i_u *)data, hdr);
363 }
364 
365 #ifdef __cplusplus
366 }
367 #endif
368 
369 #endif /* __PKTDEV_H */
#define __cne_cache_min_aligned
Definition: cne_common.h:382
void mempool_t
Definition: mempool.h:45
static uint16_t pktdev_tx_burst(uint16_t lport_id, pktmbuf_t **tx_pkts, uint16_t nb_pkts)
Definition: pktdev.h:258
static uint16_t pktdev_tx_prepare(uint16_t lport_id, pktmbuf_t **tx_pkts, uint16_t nb_pkts)
Definition: pktdev.h:330
static uint16_t pktdev_rx_burst(uint16_t lport_id, pktmbuf_t **rx_pkts, const uint16_t nb_pkts)
Definition: pktdev.h:183
static void pktdev_mac_swap(void *data)
Definition: pktdev.h:351
CNDP_API bool pktdev_admin_state(uint16_t lport_id)
unsigned int if_index
Definition: pktdev.h:81
uint32_t min_tx_bufsize
Definition: pktdev.h:88
struct pktdev_portconf default_rxportconf
Definition: pktdev.h:93
uint64_t dev_capa
Definition: pktdev.h:97
uint32_t min_rx_bufsize
Definition: pktdev.h:86
bool admin_state
Definition: pktdev.h:83
struct pktdev_portconf default_txportconf
Definition: pktdev.h:95
uint32_t max_rx_pktlen
Definition: pktdev.h:87
uint16_t max_mtu
Definition: pktdev.h:85
uint16_t min_mtu
Definition: pktdev.h:84
const char * driver_name
Definition: pktdev.h:80
uint8_t hash_key_size
Definition: pktdev.h:89
uint32_t speed_capa
Definition: pktdev.h:91
uint16_t burst_size
Definition: pktdev.h:66
uint16_t ring_size
Definition: pktdev.h:67
mempool_t * mp
Definition: pktdev.h:48
uint16_t nb_desc
Definition: pktdev.h:49
uint16_t nb_desc
Definition: pktdev.h:57