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