DPDK  18.05.1
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_global *rte_rawdev_globals;
78 extern struct rte_rawdev *rte_rawdevs;
90 static inline struct rte_rawdev *
92 {
93  struct rte_rawdev *dev;
94  unsigned int i;
95 
96  if (name == NULL)
97  return NULL;
98 
99  for (i = 0; i < RTE_RAWDEV_MAX_DEVS; i++) {
100  dev = &rte_rawdevs[i];
101  if ((dev->attached == RTE_RAWDEV_ATTACHED) &&
102  (strcmp(dev->name, name) == 0))
103  return dev;
104  }
105 
106  return NULL;
107 }
108 
118 static inline unsigned
120 {
121  struct rte_rawdev *dev;
122 
123  if (dev_id >= RTE_RAWDEV_MAX_DEVS)
124  return 0;
125 
126  dev = &rte_rawdevs[dev_id];
127  if (dev->attached != RTE_RAWDEV_ATTACHED)
128  return 0;
129  else
130  return 1;
131 }
132 
150 typedef void (*rawdev_info_get_t)(struct rte_rawdev *dev,
151  rte_rawdev_obj_t dev_info);
152 
164 typedef int (*rawdev_configure_t)(const struct rte_rawdev *dev,
165  rte_rawdev_obj_t config);
166 
176 typedef int (*rawdev_start_t)(struct rte_rawdev *dev);
177 
184 typedef void (*rawdev_stop_t)(struct rte_rawdev *dev);
185 
196 typedef int (*rawdev_close_t)(struct rte_rawdev *dev);
197 
207 typedef int (*rawdev_reset_t)(struct rte_rawdev *dev);
208 
220 typedef void (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev,
221  uint16_t queue_id,
222  rte_rawdev_obj_t queue_conf);
223 
237 typedef int (*rawdev_queue_setup_t)(struct rte_rawdev *dev,
238  uint16_t queue_id,
239  rte_rawdev_obj_t queue_conf);
240 
250 typedef int (*rawdev_queue_release_t)(struct rte_rawdev *dev,
251  uint16_t queue_id);
252 
275 typedef int (*rawdev_enqueue_bufs_t)(struct rte_rawdev *dev,
276  struct rte_rawdev_buf **buffers,
277  unsigned int count,
278  rte_rawdev_obj_t context);
279 
300 typedef int (*rawdev_dequeue_bufs_t)(struct rte_rawdev *dev,
301  struct rte_rawdev_buf **buffers,
302  unsigned int count,
303  rte_rawdev_obj_t context);
304 
317 typedef int (*rawdev_dump_t)(struct rte_rawdev *dev, FILE *f);
318 
334 typedef int (*rawdev_get_attr_t)(struct rte_rawdev *dev,
335  const char *attr_name,
336  uint64_t *attr_value);
337 
352 typedef int (*rawdev_set_attr_t)(struct rte_rawdev *dev,
353  const char *attr_name,
354  const uint64_t attr_value);
355 
372 typedef int (*rawdev_xstats_get_t)(const struct rte_rawdev *dev,
373  const unsigned int ids[], uint64_t values[], unsigned int n);
374 
378 typedef int (*rawdev_xstats_reset_t)(struct rte_rawdev *dev,
379  const uint32_t ids[],
380  uint32_t nb_ids);
381 
397 typedef int (*rawdev_xstats_get_names_t)(const struct rte_rawdev *dev,
398  struct rte_rawdev_xstats_name *xstats_names,
399  unsigned int size);
400 
416 typedef uint64_t (*rawdev_xstats_get_by_name_t)(const struct rte_rawdev *dev,
417  const char *name,
418  unsigned int *id);
419 
432 typedef int (*rawdev_firmware_status_get_t)(struct rte_rawdev *dev,
433  rte_rawdev_obj_t status_info);
434 
446 typedef int (*rawdev_firmware_version_get_t)(struct rte_rawdev *dev,
447  rte_rawdev_obj_t version_info);
448 
463 typedef int (*rawdev_firmware_load_t)(struct rte_rawdev *dev,
464  rte_rawdev_obj_t firmware_buf);
465 
478 typedef int (*rawdev_firmware_unload_t)(struct rte_rawdev *dev);
479 
486 typedef int (*rawdev_selftest_t)(void);
487 
502 
509 
515 
516  /* Dump internal information */
518 
523 
532 
541 
543  rawdev_selftest_t dev_selftest;
544 };
545 
559 struct rte_rawdev * __rte_experimental
560 rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size,
561  int socket_id);
562 
571 int __rte_experimental
572 rte_rawdev_pmd_release(struct rte_rawdev *rawdev);
573 
588 struct rte_rawdev * __rte_experimental
589 rte_rawdev_pmd_init(const char *name, size_t dev_private_size,
590  int socket_id);
591 
600 int __rte_experimental
601 rte_rawdev_pmd_uninit(const char *name);
602 
603 #ifdef __cplusplus
604 }
605 #endif
606 
607 #endif /* _RTE_RAWDEV_PMD_H_ */