DPDK  19.08.2
rte_rawdev_pmd.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017 NXP
3  */
4 
5 #ifndef _RTE_RAWDEV_PMD_H_
6 #define _RTE_RAWDEV_PMD_H_
7 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <string.h>
24 
25 #include <rte_dev.h>
26 #include <rte_malloc.h>
27 #include <rte_log.h>
28 #include <rte_common.h>
29 
30 #include "rte_rawdev.h"
31 
32 extern int librawdev_logtype;
33 
34 /* Logging Macros */
35 #define RTE_RDEV_LOG(level, fmt, args...) \
36  rte_log(RTE_LOG_ ## level, librawdev_logtype, "%s(): " fmt "\n", \
37  __func__, ##args)
38 
39 #define RTE_RDEV_ERR(fmt, args...) \
40  RTE_RDEV_LOG(ERR, fmt, ## args)
41 #define RTE_RDEV_DEBUG(fmt, args...) \
42  RTE_RDEV_LOG(DEBUG, fmt, ## args)
43 #define RTE_RDEV_INFO(fmt, args...) \
44  RTE_RDEV_LOG(INFO, fmt, ## args)
45 
46 
47 /* Macros to check for valid device */
48 #define RTE_RAWDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
49  if (!rte_rawdev_pmd_is_valid_dev((dev_id))) { \
50  RTE_RDEV_ERR("Invalid dev_id=%d", dev_id); \
51  return retval; \
52  } \
53 } while (0)
54 
55 #define RTE_RAWDEV_VALID_DEVID_OR_RET(dev_id) do { \
56  if (!rte_rawdev_pmd_is_valid_dev((dev_id))) { \
57  RTE_RDEV_ERR("Invalid dev_id=%d", dev_id); \
58  return; \
59  } \
60 } while (0)
61 
62 #define RTE_RAWDEV_DETACHED (0)
63 #define RTE_RAWDEV_ATTACHED (1)
64 
65 /* Global structure used for maintaining state of allocated raw devices.
66  *
67  * TODO: Can be expanded to <type of raw device>:<count> in future.
68  * Applications should be able to select from a number of type of raw
69  * devices which were detected or attached to this DPDK instance.
70  */
71 struct rte_rawdev_global {
73  uint16_t nb_devs;
74 };
75 
76 extern struct rte_rawdev *rte_rawdevs;
88 static inline struct rte_rawdev *
90 {
91  struct rte_rawdev *dev;
92  unsigned int i;
93 
94  if (name == NULL)
95  return NULL;
96 
97  for (i = 0; i < RTE_RAWDEV_MAX_DEVS; i++) {
98  dev = &rte_rawdevs[i];
99  if ((dev->attached == RTE_RAWDEV_ATTACHED) &&
100  (strcmp(dev->name, name) == 0))
101  return dev;
102  }
103 
104  return NULL;
105 }
106 
116 static inline unsigned
118 {
119  struct rte_rawdev *dev;
120 
121  if (dev_id >= RTE_RAWDEV_MAX_DEVS)
122  return 0;
123 
124  dev = &rte_rawdevs[dev_id];
125  if (dev->attached != RTE_RAWDEV_ATTACHED)
126  return 0;
127  else
128  return 1;
129 }
130 
148 typedef void (*rawdev_info_get_t)(struct rte_rawdev *dev,
149  rte_rawdev_obj_t dev_info);
150 
162 typedef int (*rawdev_configure_t)(const struct rte_rawdev *dev,
163  rte_rawdev_obj_t config);
164 
174 typedef int (*rawdev_start_t)(struct rte_rawdev *dev);
175 
182 typedef void (*rawdev_stop_t)(struct rte_rawdev *dev);
183 
194 typedef int (*rawdev_close_t)(struct rte_rawdev *dev);
195 
205 typedef int (*rawdev_reset_t)(struct rte_rawdev *dev);
206 
218 typedef void (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev,
219  uint16_t queue_id,
220  rte_rawdev_obj_t queue_conf);
221 
235 typedef int (*rawdev_queue_setup_t)(struct rte_rawdev *dev,
236  uint16_t queue_id,
237  rte_rawdev_obj_t queue_conf);
238 
248 typedef int (*rawdev_queue_release_t)(struct rte_rawdev *dev,
249  uint16_t queue_id);
250 
267 typedef uint16_t (*rawdev_queue_count_t)(struct rte_rawdev *dev);
268 
291 typedef int (*rawdev_enqueue_bufs_t)(struct rte_rawdev *dev,
292  struct rte_rawdev_buf **buffers,
293  unsigned int count,
294  rte_rawdev_obj_t context);
295 
316 typedef int (*rawdev_dequeue_bufs_t)(struct rte_rawdev *dev,
317  struct rte_rawdev_buf **buffers,
318  unsigned int count,
319  rte_rawdev_obj_t context);
320 
333 typedef int (*rawdev_dump_t)(struct rte_rawdev *dev, FILE *f);
334 
350 typedef int (*rawdev_get_attr_t)(struct rte_rawdev *dev,
351  const char *attr_name,
352  uint64_t *attr_value);
353 
368 typedef int (*rawdev_set_attr_t)(struct rte_rawdev *dev,
369  const char *attr_name,
370  const uint64_t attr_value);
371 
388 typedef int (*rawdev_xstats_get_t)(const struct rte_rawdev *dev,
389  const unsigned int ids[], uint64_t values[], unsigned int n);
390 
394 typedef int (*rawdev_xstats_reset_t)(struct rte_rawdev *dev,
395  const uint32_t ids[],
396  uint32_t nb_ids);
397 
413 typedef int (*rawdev_xstats_get_names_t)(const struct rte_rawdev *dev,
414  struct rte_rawdev_xstats_name *xstats_names,
415  unsigned int size);
416 
432 typedef uint64_t (*rawdev_xstats_get_by_name_t)(const struct rte_rawdev *dev,
433  const char *name,
434  unsigned int *id);
435 
448 typedef int (*rawdev_firmware_status_get_t)(struct rte_rawdev *dev,
449  rte_rawdev_obj_t status_info);
450 
462 typedef int (*rawdev_firmware_version_get_t)(struct rte_rawdev *dev,
463  rte_rawdev_obj_t version_info);
464 
479 typedef int (*rawdev_firmware_load_t)(struct rte_rawdev *dev,
480  rte_rawdev_obj_t firmware_buf);
481 
494 typedef int (*rawdev_firmware_unload_t)(struct rte_rawdev *dev);
495 
502 typedef int (*rawdev_selftest_t)(uint16_t dev_id);
503 
518 
527 
533 
534  /* Dump internal information */
536 
541 
550 
559 
561  rawdev_selftest_t dev_selftest;
562 };
563 
579 struct rte_rawdev *
580 rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size,
581  int socket_id);
582 
591 int
592 rte_rawdev_pmd_release(struct rte_rawdev *rawdev);
593 
608 struct rte_rawdev *
609 rte_rawdev_pmd_init(const char *name, size_t dev_private_size,
610  int socket_id);
611 
620 int
621 rte_rawdev_pmd_uninit(const char *name);
622 
623 #ifdef __cplusplus
624 }
625 #endif
626 
627 #endif /* _RTE_RAWDEV_PMD_H_ */
int(* rawdev_xstats_get_t)(const struct rte_rawdev *dev, const unsigned int ids[], uint64_t values[], unsigned int n)
rawdev_reset_t dev_reset
int(* rawdev_set_attr_t)(struct rte_rawdev *dev, const char *attr_name, const uint64_t attr_value)
rawdev_dequeue_bufs_t dequeue_bufs
rawdev_xstats_get_t xstats_get
int(* rawdev_get_attr_t)(struct rte_rawdev *dev, const char *attr_name, uint64_t *attr_value)
int(* rawdev_start_t)(struct rte_rawdev *dev)
int(* rawdev_configure_t)(const struct rte_rawdev *dev, rte_rawdev_obj_t config)
rawdev_info_get_t dev_info_get
static unsigned rte_rawdev_pmd_is_valid_dev(uint8_t dev_id)
void(* rawdev_info_get_t)(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info)
int rte_rawdev_pmd_uninit(const char *name)
int(* rawdev_xstats_reset_t)(struct rte_rawdev *dev, const uint32_t ids[], uint32_t nb_ids)
int rte_rawdev_pmd_release(struct rte_rawdev *rawdev)
int(* rawdev_firmware_version_get_t)(struct rte_rawdev *dev, rte_rawdev_obj_t version_info)
struct rte_rawdev * rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size, int socket_id)
rawdev_firmware_version_get_t firmware_version_get
rawdev_xstats_reset_t xstats_reset
int(* rawdev_queue_release_t)(struct rte_rawdev *dev, uint16_t queue_id)
rawdev_queue_conf_get_t queue_def_conf
int(* rawdev_firmware_load_t)(struct rte_rawdev *dev, rte_rawdev_obj_t firmware_buf)
rawdev_configure_t dev_configure
int(* rawdev_dequeue_bufs_t)(struct rte_rawdev *dev, struct rte_rawdev_buf **buffers, unsigned int count, rte_rawdev_obj_t context)
rawdev_start_t dev_start
int(* rawdev_selftest_t)(uint16_t dev_id)
rawdev_queue_count_t queue_count
int(* rawdev_firmware_unload_t)(struct rte_rawdev *dev)
int(* rawdev_queue_setup_t)(struct rte_rawdev *dev, uint16_t queue_id, rte_rawdev_obj_t queue_conf)
uint16_t(* rawdev_queue_count_t)(struct rte_rawdev *dev)
struct rte_rawdev * rte_rawdev_pmd_init(const char *name, size_t dev_private_size, int socket_id)
int(* rawdev_close_t)(struct rte_rawdev *dev)
rawdev_xstats_get_by_name_t xstats_get_by_name
rawdev_firmware_load_t firmware_load
int(* rawdev_xstats_get_names_t)(const struct rte_rawdev *dev, struct rte_rawdev_xstats_name *xstats_names, unsigned int size)
uint64_t(* rawdev_xstats_get_by_name_t)(const struct rte_rawdev *dev, const char *name, unsigned int *id)
rawdev_set_attr_t attr_set
rawdev_queue_release_t queue_release
void(* rawdev_stop_t)(struct rte_rawdev *dev)
rawdev_queue_setup_t queue_setup
rawdev_xstats_get_names_t xstats_get_names
rawdev_get_attr_t attr_get
int(* rawdev_reset_t)(struct rte_rawdev *dev)
rawdev_firmware_status_get_t firmware_status_get
rawdev_enqueue_bufs_t enqueue_bufs
int(* rawdev_firmware_status_get_t)(struct rte_rawdev *dev, rte_rawdev_obj_t status_info)
static struct rte_rawdev * rte_rawdev_pmd_get_named_dev(const char *name)
rawdev_close_t dev_close
void(* rawdev_queue_conf_get_t)(struct rte_rawdev *dev, uint16_t queue_id, rte_rawdev_obj_t queue_conf)
rawdev_stop_t dev_stop
int(* rawdev_enqueue_bufs_t)(struct rte_rawdev *dev, struct rte_rawdev_buf **buffers, unsigned int count, rte_rawdev_obj_t context)
int(* rawdev_dump_t)(struct rte_rawdev *dev, FILE *f)
rawdev_dump_t dump
rawdev_firmware_unload_t firmware_unload