compressdev: add basic device management
[dpdk.git] / lib / librte_compressdev / rte_compressdev_pmd.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017-2018 Intel Corporation
3  */
4
5 #ifndef _RTE_COMPRESSDEV_PMD_H_
6 #define _RTE_COMPRESSDEV_PMD_H_
7
8 /** @file
9  * RTE comp PMD APIs
10  *
11  * @note
12  * These APIs are for comp PMDs only and user applications should not call
13  * them directly.
14  */
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <string.h>
21
22 #include <rte_dev.h>
23 #include <rte_common.h>
24
25 #include "rte_compressdev.h"
26 #include "rte_compressdev_internal.h"
27
28 #define RTE_COMPRESSDEV_PMD_NAME_ARG                    ("name")
29 #define RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG               ("socket_id")
30
31 static const char * const compressdev_pmd_valid_params[] = {
32         RTE_COMPRESSDEV_PMD_NAME_ARG,
33         RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG
34 };
35
36 /**
37  * @internal
38  * Initialisation parameters for comp devices
39  */
40 struct rte_compressdev_pmd_init_params {
41         char name[RTE_COMPRESSDEV_NAME_MAX_LEN];
42         int socket_id;
43 };
44
45 /** Global structure used for maintaining state of allocated comp devices */
46 struct rte_compressdev_global {
47         struct rte_compressdev *devs;   /**< Device information array */
48         struct rte_compressdev_data *data[RTE_COMPRESS_MAX_DEVS];
49         /**< Device private data */
50         uint8_t nb_devs;                /**< Number of devices found */
51         uint8_t max_devs;               /**< Max number of devices */
52 };
53
54 /** Pointer to global array of comp devices */
55 extern struct rte_compressdev *rte_compressdevs;
56 /** Pointer to global comp devices data structure */
57 extern struct rte_compressdev_global *rte_compressdev_globals;
58
59 /**
60  * Get the rte_compressdev structure device pointer for the named device.
61  *
62  * @param name
63  *   Compress device name
64  * @return
65  *   - The rte_compressdev structure pointer for the given device identifier.
66  */
67 struct rte_compressdev * __rte_experimental
68 rte_compressdev_pmd_get_named_dev(const char *name);
69
70 /**
71  * Definitions of all functions exported by a driver through the
72  * the generic structure of type *comp_dev_ops* supplied in the
73  * *rte_compressdev* structure associated with a device.
74  */
75
76 /**
77  * Function used to configure device.
78  *
79  * @param dev
80  *   Compress device
81  * @param config
82  *   Compress device configurations
83  * @return
84  *   Returns 0 on success
85  */
86 typedef int (*compressdev_configure_t)(struct rte_compressdev *dev,
87                 struct rte_compressdev_config *config);
88
89 /**
90  * Function used to start a configured device.
91  *
92  * @param dev
93  *   Compress device
94  * @return
95  *   Returns 0 on success
96  */
97 typedef int (*compressdev_start_t)(struct rte_compressdev *dev);
98
99 /**
100  * Function used to stop a configured device.
101  *
102  * @param dev
103  *   Compress device
104  */
105 typedef void (*compressdev_stop_t)(struct rte_compressdev *dev);
106
107 /**
108  * Function used to close a configured device.
109  *
110  * @param dev
111  *   Compress device
112  * @return
113  * - 0 on success.
114  * - EAGAIN if can't close as device is busy
115  */
116 typedef int (*compressdev_close_t)(struct rte_compressdev *dev);
117
118
119 /**
120  * Function used to get specific information of a device.
121  *
122  * @param dev
123  *   Compress device
124  */
125 typedef void (*compressdev_info_get_t)(struct rte_compressdev *dev,
126                                 struct rte_compressdev_info *dev_info);
127
128 /** comp device operations function pointer table */
129 struct rte_compressdev_ops {
130         compressdev_configure_t dev_configure;  /**< Configure device. */
131         compressdev_start_t dev_start;          /**< Start device. */
132         compressdev_stop_t dev_stop;            /**< Stop device. */
133         compressdev_close_t dev_close;          /**< Close device. */
134
135         compressdev_info_get_t dev_infos_get;   /**< Get device info. */
136 };
137
138 /**
139  * @internal
140  *
141  * Function for internal use by dummy drivers primarily, e.g. ring-based
142  * driver.
143  * Allocates a new compressdev slot for an comp device and returns the pointer
144  * to that slot for the driver to use.
145  *
146  * @param name
147  *   Unique identifier name for each device
148  * @param socket_id
149  *   Socket to allocate resources on
150  * @return
151  *   - Slot in the rte_dev_devices array for a new device;
152  */
153 struct rte_compressdev * __rte_experimental
154 rte_compressdev_pmd_allocate(const char *name, int socket_id);
155
156 /**
157  * @internal
158  *
159  * Function for internal use by dummy drivers primarily, e.g. ring-based
160  * driver.
161  * Release the specified compressdev device.
162  *
163  * @param dev
164  *   Compress device
165  * @return
166  *   - 0 on success, negative on error
167  */
168 int __rte_experimental
169 rte_compressdev_pmd_release_device(struct rte_compressdev *dev);
170
171
172 /**
173  * @internal
174  *
175  * PMD assist function to parse initialisation arguments for comp driver
176  * when creating a new comp PMD device instance.
177  *
178  * PMD driver should set default values for that PMD before calling function,
179  * these default values will be over-written with successfully parsed values
180  * from args string.
181  *
182  * @param params
183  *   Parsed PMD initialisation parameters
184  * @param args
185  *   Input argument string to parse
186  * @return
187  *  - 0 on success
188  *  - errno on failure
189  */
190 int __rte_experimental
191 rte_compressdev_pmd_parse_input_args(
192                 struct rte_compressdev_pmd_init_params *params,
193                 const char *args);
194
195 /**
196  * @internal
197  *
198  * PMD assist function to provide boiler plate code for comp driver to create
199  * and allocate resources for a new comp PMD device instance.
200  *
201  * @param name
202  *   Compress device name
203  * @param device
204  *   Base device instance
205  * @param params
206  *   PMD initialisation parameters
207  * @return
208  *  - comp device instance on success
209  *  - NULL on creation failure
210  */
211 struct rte_compressdev * __rte_experimental
212 rte_compressdev_pmd_create(const char *name,
213                 struct rte_device *device,
214                 size_t private_data_size,
215                 struct rte_compressdev_pmd_init_params *params);
216
217 /**
218  * @internal
219  *
220  * PMD assist function to provide boiler plate code for comp driver to
221  * destroy and free resources associated with a comp PMD device instance.
222  *
223  * @param dev
224  *   Compress device
225  * @return
226  *  - 0 on success
227  *  - errno on failure
228  */
229 int __rte_experimental
230 rte_compressdev_pmd_destroy(struct rte_compressdev *dev);
231
232 #ifdef __cplusplus
233 }
234 #endif
235
236 #endif /* _RTE_COMPRESSDEV_PMD_H_ */