rawdev: remove remaining experimental tags
[dpdk.git] / lib / librte_rawdev / rte_rawdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017 NXP
3  */
4
5 #ifndef _RTE_RAWDEV_H_
6 #define _RTE_RAWDEV_H_
7
8 /**
9  * @file rte_rawdev.h
10  *
11  * Generic device abstraction APIs.
12  *
13  * This API allow applications to configure and use generic devices having
14  * no specific type already available in DPDK.
15  */
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include <rte_common.h>
22 #include <rte_memory.h>
23 #include <rte_errno.h>
24
25 /* Rawdevice object - essentially a void to be typecast by implementation */
26 typedef void *rte_rawdev_obj_t;
27
28 /**
29  * Get the total number of raw devices that have been successfully
30  * initialised.
31  *
32  * @return
33  *   The total number of usable raw devices.
34  */
35 uint8_t
36 rte_rawdev_count(void);
37
38 /**
39  * Get the device identifier for the named raw device.
40  *
41  * @param name
42  *   Raw device name to select the raw device identifier.
43  *
44  * @return
45  *   Returns raw device identifier on success.
46  *   - <0: Failure to find named raw device.
47  */
48 uint16_t
49 rte_rawdev_get_dev_id(const char *name);
50
51 /**
52  * Return the NUMA socket to which a device is connected.
53  *
54  * @param dev_id
55  *   The identifier of the device.
56  * @return
57  *   The NUMA socket id to which the device is connected or
58  *   a default of zero if the socket could not be determined.
59  *   -(-EINVAL)  dev_id value is out of range.
60  */
61 int
62 rte_rawdev_socket_id(uint16_t dev_id);
63
64 /**
65  * Raw device information forward declaration
66  */
67 struct rte_rawdev_info;
68
69 /**
70  * Retrieve the contextual information of a raw device.
71  *
72  * @param dev_id
73  *   The identifier of the device.
74  *
75  * @param[out] dev_info
76  *   A pointer to a structure of type *rte_rawdev_info* to be filled with the
77  *   contextual information of the device.
78  *
79  * @return
80  *   - 0: Success, driver updates the contextual information of the raw device
81  *   - <0: Error code returned by the driver info get function.
82  *
83  */
84 int
85 rte_rawdev_info_get(uint16_t dev_id, struct rte_rawdev_info *dev_info);
86
87 /**
88  * Configure a raw device.
89  *
90  * This function must be invoked first before any other function in the
91  * API. This function can also be re-invoked when a device is in the
92  * stopped state.
93  *
94  * The caller may use rte_rawdev_info_get() to get the capability of each
95  * resources available for this raw device.
96  *
97  * @param dev_id
98  *   The identifier of the device to configure.
99  * @param dev_conf
100  *   The raw device configuration structure encapsulated into rte_rawdev_info
101  *   object.
102  *   It is assumed that the opaque object has enough information which the
103  *   driver/implementation can use to configure the device. It is also assumed
104  *   that once the configuration is done, a `queue_id` type field can be used
105  *   to refer to some arbitrary internal representation of a queue.
106  *
107  * @return
108  *   - 0: Success, device configured.
109  *   - <0: Error code returned by the driver configuration function.
110  */
111 int
112 rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf);
113
114
115 /**
116  * Retrieve the current configuration information of a raw queue designated
117  * by its *queue_id* from the raw driver for a raw device.
118  *
119  * This function intended to be used in conjunction with rte_raw_queue_setup()
120  * where caller needs to set up the queue by overriding few default values.
121  *
122  * @param dev_id
123  *   The identifier of the device.
124  * @param queue_id
125  *   The index of the raw queue to get the configuration information.
126  *   The value must be in the range [0, nb_raw_queues - 1]
127  *   previously supplied to rte_rawdev_configure().
128  * @param[out] queue_conf
129  *   The pointer to the default raw queue configuration data.
130  * @return
131  *   - 0: Success, driver updates the default raw queue configuration data.
132  *   - <0: Error code returned by the driver info get function.
133  *
134  * @see rte_raw_queue_setup()
135  *
136  */
137 int
138 rte_rawdev_queue_conf_get(uint16_t dev_id,
139                           uint16_t queue_id,
140                           rte_rawdev_obj_t queue_conf);
141
142 /**
143  * Allocate and set up a raw queue for a raw device.
144  *
145  * @param dev_id
146  *   The identifier of the device.
147  * @param queue_id
148  *   The index of the raw queue to setup. The value must be in the range
149  *   [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure().
150  * @param queue_conf
151  *   The pointer to the configuration data to be used for the raw queue.
152  *   NULL value is allowed, in which case default configuration used.
153  *
154  * @see rte_rawdev_queue_conf_get()
155  *
156  * @return
157  *   - 0: Success, raw queue correctly set up.
158  *   - <0: raw queue configuration failed
159  */
160 int
161 rte_rawdev_queue_setup(uint16_t dev_id,
162                        uint16_t queue_id,
163                        rte_rawdev_obj_t queue_conf);
164
165 /**
166  * Release and deallocate a raw queue from a raw device.
167  *
168  * @param dev_id
169  *   The identifier of the device.
170  * @param queue_id
171  *   The index of the raw queue to release. The value must be in the range
172  *   [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure().
173  *
174  * @see rte_rawdev_queue_conf_get()
175  *
176  * @return
177  *   - 0: Success, raw queue released.
178  *   - <0: raw queue configuration failed
179  */
180 int
181 rte_rawdev_queue_release(uint16_t dev_id, uint16_t queue_id);
182
183 /**
184  * Get the number of raw queues on a specific raw device
185  *
186  * @param dev_id
187  *   Raw device identifier.
188  * @return
189  *   - The number of configured raw queues
190  */
191 uint16_t
192 rte_rawdev_queue_count(uint16_t dev_id);
193
194 /**
195  * Start a raw device.
196  *
197  * The device start step is the last one and consists of setting the raw
198  * queues to start accepting the raws and schedules to raw ports.
199  *
200  * On success, all basic functions exported by the API (raw enqueue,
201  * raw dequeue and so on) can be invoked.
202  *
203  * @param dev_id
204  *   Raw device identifier
205  * @return
206  *   - 0: Success, device started.
207  *   < 0: Failure
208  */
209 int
210 rte_rawdev_start(uint16_t dev_id);
211
212 /**
213  * Stop a raw device. The device can be restarted with a call to
214  * rte_rawdev_start()
215  *
216  * @param dev_id
217  *   Raw device identifier.
218  */
219 void
220 rte_rawdev_stop(uint16_t dev_id);
221
222 /**
223  * Close a raw device. The device cannot be restarted after this call.
224  *
225  * @param dev_id
226  *   Raw device identifier
227  *
228  * @return
229  *  - 0 on successfully closing device
230  *  - <0 on failure to close device
231  *  - (-EAGAIN) if device is busy
232  */
233 int
234 rte_rawdev_close(uint16_t dev_id);
235
236 /**
237  * Reset a raw device.
238  * This is different from cycle of rte_rawdev_start->rte_rawdev_stop in the
239  * sense similar to hard or soft reset.
240  *
241  * @param dev_id
242  *   Raw device identifiers
243  * @return
244  *   0 for successful reset,
245  *  !0 for failure in resetting
246  */
247 int
248 rte_rawdev_reset(uint16_t dev_id);
249
250 #define RTE_RAWDEV_NAME_MAX_LEN (64)
251 /**< @internal Max length of name of raw PMD */
252
253
254
255 /** @internal
256  * The data structure associated with each raw device.
257  * It is a placeholder for PMD specific data, encapsulating only information
258  * related to framework.
259  */
260 struct rte_rawdev {
261         /**< Socket ID where memory is allocated */
262         int socket_id;
263         /**< Device ID for this instance */
264         uint16_t dev_id;
265         /**< Functions exported by PMD */
266         const struct rte_rawdev_ops *dev_ops;
267         /**< Device info. supplied during device initialization */
268         struct rte_device *device;
269         /**< Driver info. supplied by probing */
270         const char *driver_name;
271
272         RTE_STD_C11
273         /**< Flag indicating the device is attached */
274         uint8_t attached : 1;
275         /**< Device state: STARTED(1)/STOPPED(0) */
276         uint8_t started : 1;
277
278         /**< PMD-specific private data */
279         rte_rawdev_obj_t dev_private;
280         /**< Device name */
281         char name[RTE_RAWDEV_NAME_MAX_LEN];
282 } __rte_cache_aligned;
283
284 /** @internal The pool of rte_rawdev structures. */
285 extern struct rte_rawdev *rte_rawdevs;
286
287
288 struct rte_rawdev_info {
289         /**< Name of driver handling this device */
290         const char *driver_name;
291         /**< Device encapsulation */
292         struct rte_device *device;
293         /**< Socket ID where memory is allocated */
294         int socket_id;
295         /**< PMD-specific private data */
296         rte_rawdev_obj_t dev_private;
297 };
298
299 struct rte_rawdev_buf {
300         /**< Opaque buffer reference */
301         void *buf_addr;
302 };
303
304 /**
305  * Dump internal information about *dev_id* to the FILE* provided in *f*.
306  *
307  * @param dev_id
308  *   The identifier of the device.
309  *
310  * @param f
311  *   A pointer to a file for output
312  *
313  * @return
314  *   - 0: on success
315  *   - <0: on failure.
316  */
317 int
318 rte_rawdev_dump(uint16_t dev_id, FILE *f);
319
320 /**
321  * Get an attribute value from implementation.
322  * Attribute is an opaque handle agreed upon between application and PMD.
323  *
324  * Implementations are expected to maintain an array of attribute-value pairs
325  * based on application calls. Memory management for this structure is
326  * shared responsibility of implementation and application.
327  *
328  * @param dev_id
329  *   The identifier of the device to configure.
330  * @param attr_name
331  *   Opaque object representing an attribute in implementation.
332  * @param attr_value [out]
333  *   Opaque response to the attribute value. In case of error, this remains
334  *   untouched. This is double pointer of void type.
335  * @return
336  *   0 for success
337  *  !0 Error; attr_value remains untouched in case of error.
338  */
339 int
340 rte_rawdev_get_attr(uint16_t dev_id,
341                     const char *attr_name,
342                     uint64_t *attr_value);
343
344 /**
345  * Set an attribute value.
346  * Attribute is an opaque handle agreed upon between application and PMD.
347  *
348  * @param dev_id
349  *   The identifier of the device to configure.
350  * @param attr_name
351  *   Opaque object representing an attribute in implementation.
352  * @param attr_value
353  *   Value of the attribute represented by attr_name
354  * @return
355  *   0 for success
356  *  !0 Error
357  */
358 int
359 rte_rawdev_set_attr(uint16_t dev_id,
360                     const char *attr_name,
361                     const uint64_t attr_value);
362
363 /**
364  * Enqueue a stream of buffers to the device.
365  *
366  * Rather than specifying a queue, this API passes along an opaque object
367  * to the driver implementation. That object can be a queue or any other
368  * contextual information necessary for the device to enqueue buffers.
369  *
370  * @param dev_id
371  *   The identifier of the device to configure.
372  * @param buffers
373  *   Collection of buffers for enqueuing
374  * @param count
375  *   Count of buffers to enqueue
376  * @param context
377  *   Opaque context information.
378  * @return
379  *   >=0 for buffers enqueued
380  *  !0 for failure.
381  *  Whether partial enqueue is failure or success is defined between app
382  *  and driver implementation.
383  */
384 int
385 rte_rawdev_enqueue_buffers(uint16_t dev_id,
386                            struct rte_rawdev_buf **buffers,
387                            unsigned int count,
388                            rte_rawdev_obj_t context);
389
390 /**
391  * Dequeue a stream of buffers from the device.
392  *
393  * Rather than specifying a queue, this API passes along an opaque object
394  * to the driver implementation. That object can be a queue or any other
395  * contextual information necessary for the device to dequeue buffers.
396  *
397  * Application should have allocated enough space to store `count` response
398  * buffers.
399  * Releasing buffers dequeued is responsibility of the application.
400  *
401  * @param dev_id
402  *   The identifier of the device to configure.
403  * @param buffers
404  *   Collection of buffers dequeued
405  * @param count
406  *   Max buffers expected to be dequeued
407  * @param context
408  *   Opaque context information.
409  * @return
410  *   >=0 for buffers dequeued
411  *  !0 for failure.
412  *  Whether partial enqueue is failure or success is defined between app
413  *  and driver implementation.
414  */
415 int
416 rte_rawdev_dequeue_buffers(uint16_t dev_id,
417                            struct rte_rawdev_buf **buffers,
418                            unsigned int count,
419                            rte_rawdev_obj_t context);
420
421 /** Maximum name length for extended statistics counters */
422 #define RTE_RAW_DEV_XSTATS_NAME_SIZE 64
423
424 /**
425  * A name-key lookup element for extended statistics.
426  *
427  * This structure is used to map between names and ID numbers
428  * for extended ethdev statistics.
429  */
430 struct rte_rawdev_xstats_name {
431         char name[RTE_RAW_DEV_XSTATS_NAME_SIZE];
432 };
433
434 /**
435  * Retrieve names of extended statistics of a raw device.
436  *
437  * @param dev_id
438  *   The identifier of the raw device.
439  * @param[out] xstats_names
440  *   Block of memory to insert names into. Must be at least size in capacity.
441  *   If set to NULL, function returns required capacity.
442  * @param size
443  *   Capacity of xstats_names (number of names).
444  * @return
445  *   - positive value lower or equal to size: success. The return value
446  *     is the number of entries filled in the stats table.
447  *   - positive value higher than size: error, the given statistics table
448  *     is too small. The return value corresponds to the size that should
449  *     be given to succeed. The entries in the table are not valid and
450  *     shall not be used by the caller.
451  *   - negative value on error:
452  *        -ENODEV for invalid *dev_id*
453  *        -ENOTSUP if the device doesn't support this function.
454  */
455 int
456 rte_rawdev_xstats_names_get(uint16_t dev_id,
457                             struct rte_rawdev_xstats_name *xstats_names,
458                             unsigned int size);
459
460 /**
461  * Retrieve extended statistics of a raw device.
462  *
463  * @param dev_id
464  *   The identifier of the device.
465  * @param ids
466  *   The id numbers of the stats to get. The ids can be got from the stat
467  *   position in the stat list from rte_rawdev_get_xstats_names(), or
468  *   by using rte_rawdev_get_xstats_by_name()
469  * @param[out] values
470  *   The values for each stats request by ID.
471  * @param n
472  *   The number of stats requested
473  * @return
474  *   - positive value: number of stat entries filled into the values array
475  *   - negative value on error:
476  *        -ENODEV for invalid *dev_id*
477  *        -ENOTSUP if the device doesn't support this function.
478  */
479 int
480 rte_rawdev_xstats_get(uint16_t dev_id,
481                       const unsigned int ids[],
482                       uint64_t values[],
483                       unsigned int n);
484
485 /**
486  * Retrieve the value of a single stat by requesting it by name.
487  *
488  * @param dev_id
489  *   The identifier of the device
490  * @param name
491  *   The stat name to retrieve
492  * @param[out] id
493  *   If non-NULL, the numerical id of the stat will be returned, so that further
494  *   requests for the stat can be got using rte_rawdev_xstats_get, which will
495  *   be faster as it doesn't need to scan a list of names for the stat.
496  *   If the stat cannot be found, the id returned will be (unsigned)-1.
497  * @return
498  *   - positive value or zero: the stat value
499  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
500  */
501 uint64_t
502 rte_rawdev_xstats_by_name_get(uint16_t dev_id,
503                               const char *name,
504                               unsigned int *id);
505
506 /**
507  * Reset the values of the xstats of the selected component in the device.
508  *
509  * @param dev_id
510  *   The identifier of the device
511  * @param ids
512  *   Selects specific statistics to be reset. When NULL, all statistics
513  *   will be reset. If non-NULL, must point to array of at least
514  *   *nb_ids* size.
515  * @param nb_ids
516  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
517  * @return
518  *   - zero: successfully reset the statistics to zero
519  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
520  */
521 int
522 rte_rawdev_xstats_reset(uint16_t dev_id,
523                         const uint32_t ids[],
524                         uint32_t nb_ids);
525
526 /**
527  * Get Firmware status of the device..
528  * Returns a memory allocated by driver/implementation containing status
529  * information block. It is responsibility of caller to release the buffer.
530  *
531  * @param dev_id
532  *   Raw device identifier
533  * @param status_info
534  *   Pointer to status information area. Caller is responsible for releasing
535  *   the memory associated.
536  * @return
537  *   0 for success,
538  *  !0 for failure, `status_info` argument state is undefined
539  */
540 int
541 rte_rawdev_firmware_status_get(uint16_t dev_id,
542                                rte_rawdev_obj_t status_info);
543
544 /**
545  * Get Firmware version of the device.
546  * Returns a memory allocated by driver/implementation containing version
547  * information block. It is responsibility of caller to release the buffer.
548  *
549  * @param dev_id
550  *   Raw device identifier
551  * @param version_info
552  *   Pointer to version information area. Caller is responsible for releasing
553  *   the memory associated.
554  * @return
555  *   0 for success,
556  *  !0 for failure, `version_info` argument state is undefined
557  */
558 int
559 rte_rawdev_firmware_version_get(uint16_t dev_id,
560                                 rte_rawdev_obj_t version_info);
561
562 /**
563  * Load firmware on the device.
564  * TODO: In future, methods like directly flashing from file too can be
565  * supported.
566  *
567  * @param dev_id
568  *   Raw device identifier
569  * @param firmware_image
570  *   Pointer to buffer containing image binary data
571  * @return
572  *   0 for successful load
573  *  !0 for failure to load the provided image, or image incorrect.
574  */
575 int
576 rte_rawdev_firmware_load(uint16_t dev_id, rte_rawdev_obj_t firmware_image);
577
578 /**
579  * Unload firmware from the device.
580  *
581  * @param dev_id
582  *   Raw device identifiers
583  * @return
584  *   0 for successful Unload
585  *  !0 for failure in unloading
586  */
587 int
588 rte_rawdev_firmware_unload(uint16_t dev_id);
589
590 /**
591  * Trigger the rawdev self test.
592  *
593  * @param dev_id
594  *   The identifier of the device
595  * @return
596  *   - 0: Selftest successful
597  *   - -ENOTSUP if the device doesn't support selftest
598  *   - other values < 0 on failure.
599  */
600 int
601 rte_rawdev_selftest(uint16_t dev_id);
602
603 #ifdef __cplusplus
604 }
605 #endif
606
607 #endif /* _RTE_RAWDEV_H_ */