New upstream version 17.11-rc3
[deb_dpdk.git] / lib / librte_eventdev / rte_eventdev_pmd.h
1 /*
2  *
3  *   Copyright(c) 2016 Cavium, Inc. All rights reserved.
4  *
5  *   Redistribution and use in source and binary forms, with or without
6  *   modification, are permitted provided that the following conditions
7  *   are met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above copyright
12  *       notice, this list of conditions and the following disclaimer in
13  *       the documentation and/or other materials provided with the
14  *       distribution.
15  *     * Neither the name of Cavium, Inc nor the names of its
16  *       contributors may be used to endorse or promote products derived
17  *       from this software without specific prior written permission.
18  *
19  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef _RTE_EVENTDEV_PMD_H_
33 #define _RTE_EVENTDEV_PMD_H_
34
35 /** @file
36  * RTE Event PMD APIs
37  *
38  * @note
39  * These API are from event PMD only and user applications should not call
40  * them directly.
41  */
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 #include <string.h>
48
49 #include <rte_common.h>
50 #include <rte_dev.h>
51 #include <rte_log.h>
52 #include <rte_malloc.h>
53
54 #include "rte_eventdev.h"
55
56 /* Logging Macros */
57 #define RTE_EDEV_LOG_ERR(...) \
58         RTE_LOG(ERR, EVENTDEV, \
59                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
60                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
61
62 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
63 #define RTE_EDEV_LOG_DEBUG(...) \
64         RTE_LOG(DEBUG, EVENTDEV, \
65                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
66                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
67 #else
68 #define RTE_EDEV_LOG_DEBUG(...) (void)0
69 #endif
70
71 /* Macros to check for valid device */
72 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
73         if (!rte_event_pmd_is_valid_dev((dev_id))) { \
74                 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
75                 return retval; \
76         } \
77 } while (0)
78
79 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
80         if (!rte_event_pmd_is_valid_dev((dev_id))) { \
81                 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
82                 return; \
83         } \
84 } while (0)
85
86 #define RTE_EVENT_ETH_RX_ADAPTER_SW_CAP \
87                 ((RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) | \
88                         (RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ))
89
90 /**< Ethernet Rx adapter cap to return If the packet transfers from
91  * the ethdev to eventdev use a SW service function
92  */
93
94 #define RTE_EVENTDEV_DETACHED  (0)
95 #define RTE_EVENTDEV_ATTACHED  (1)
96
97 struct rte_eth_dev;
98
99 /** Global structure used for maintaining state of allocated event devices */
100 struct rte_eventdev_global {
101         uint8_t nb_devs;        /**< Number of devices found */
102 };
103
104 extern struct rte_eventdev_global *rte_eventdev_globals;
105 /** Pointer to global event devices data structure. */
106 extern struct rte_eventdev *rte_eventdevs;
107 /** The pool of rte_eventdev structures. */
108
109 /**
110  * Get the rte_eventdev structure device pointer for the named device.
111  *
112  * @param name
113  *   device name to select the device structure.
114  *
115  * @return
116  *   - The rte_eventdev structure pointer for the given device ID.
117  */
118 static inline struct rte_eventdev *
119 rte_event_pmd_get_named_dev(const char *name)
120 {
121         struct rte_eventdev *dev;
122         unsigned int i;
123
124         if (name == NULL)
125                 return NULL;
126
127         for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
128                 dev = &rte_eventdevs[i];
129                 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
130                                 (strcmp(dev->data->name, name) == 0))
131                         return dev;
132         }
133
134         return NULL;
135 }
136
137 /**
138  * Validate if the event device index is valid attached event device.
139  *
140  * @param dev_id
141  *   Event device index.
142  *
143  * @return
144  *   - If the device index is valid (1) or not (0).
145  */
146 static inline unsigned
147 rte_event_pmd_is_valid_dev(uint8_t dev_id)
148 {
149         struct rte_eventdev *dev;
150
151         if (dev_id >= RTE_EVENT_MAX_DEVS)
152                 return 0;
153
154         dev = &rte_eventdevs[dev_id];
155         if (dev->attached != RTE_EVENTDEV_ATTACHED)
156                 return 0;
157         else
158                 return 1;
159 }
160
161 /**
162  * Definitions of all functions exported by a driver through the
163  * the generic structure of type *event_dev_ops* supplied in the
164  * *rte_eventdev* structure associated with a device.
165  */
166
167 /**
168  * Get device information of a device.
169  *
170  * @param dev
171  *   Event device pointer
172  * @param dev_info
173  *   Event device information structure
174  *
175  * @return
176  *   Returns 0 on success
177  */
178 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
179                 struct rte_event_dev_info *dev_info);
180
181 /**
182  * Configure a device.
183  *
184  * @param dev
185  *   Event device pointer
186  *
187  * @return
188  *   Returns 0 on success
189  */
190 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
191
192 /**
193  * Start a configured device.
194  *
195  * @param dev
196  *   Event device pointer
197  *
198  * @return
199  *   Returns 0 on success
200  */
201 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
202
203 /**
204  * Stop a configured device.
205  *
206  * @param dev
207  *   Event device pointer
208  */
209 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
210
211 /**
212  * Close a configured device.
213  *
214  * @param dev
215  *   Event device pointer
216  *
217  * @return
218  * - 0 on success
219  * - (-EAGAIN) if can't close as device is busy
220  */
221 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
222
223 /**
224  * Retrieve the default event queue configuration.
225  *
226  * @param dev
227  *   Event device pointer
228  * @param queue_id
229  *   Event queue index
230  * @param[out] queue_conf
231  *   Event queue configuration structure
232  *
233  */
234 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
235                 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
236
237 /**
238  * Setup an event queue.
239  *
240  * @param dev
241  *   Event device pointer
242  * @param queue_id
243  *   Event queue index
244  * @param queue_conf
245  *   Event queue configuration structure
246  *
247  * @return
248  *   Returns 0 on success.
249  */
250 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
251                 uint8_t queue_id,
252                 const struct rte_event_queue_conf *queue_conf);
253
254 /**
255  * Release resources allocated by given event queue.
256  *
257  * @param dev
258  *   Event device pointer
259  * @param queue_id
260  *   Event queue index
261  *
262  */
263 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
264                 uint8_t queue_id);
265
266 /**
267  * Retrieve the default event port configuration.
268  *
269  * @param dev
270  *   Event device pointer
271  * @param port_id
272  *   Event port index
273  * @param[out] port_conf
274  *   Event port configuration structure
275  *
276  */
277 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
278                 uint8_t port_id, struct rte_event_port_conf *port_conf);
279
280 /**
281  * Setup an event port.
282  *
283  * @param dev
284  *   Event device pointer
285  * @param port_id
286  *   Event port index
287  * @param port_conf
288  *   Event port configuration structure
289  *
290  * @return
291  *   Returns 0 on success.
292  */
293 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
294                 uint8_t port_id,
295                 const struct rte_event_port_conf *port_conf);
296
297 /**
298  * Release memory resources allocated by given event port.
299  *
300  * @param port
301  *   Event port pointer
302  *
303  */
304 typedef void (*eventdev_port_release_t)(void *port);
305
306 /**
307  * Link multiple source event queues to destination event port.
308  *
309  * @param dev
310  *   Event device pointer
311  * @param port
312  *   Event port pointer
313  * @param link
314  *   Points to an array of *nb_links* event queues to be linked
315  *   to the event port.
316  * @param priorities
317  *   Points to an array of *nb_links* service priorities associated with each
318  *   event queue link to event port.
319  * @param nb_links
320  *   The number of links to establish
321  *
322  * @return
323  *   Returns 0 on success.
324  *
325  */
326 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
327                 const uint8_t queues[], const uint8_t priorities[],
328                 uint16_t nb_links);
329
330 /**
331  * Unlink multiple source event queues from destination event port.
332  *
333  * @param dev
334  *   Event device pointer
335  * @param port
336  *   Event port pointer
337  * @param queues
338  *   An array of *nb_unlinks* event queues to be unlinked from the event port.
339  * @param nb_unlinks
340  *   The number of unlinks to establish
341  *
342  * @return
343  *   Returns 0 on success.
344  *
345  */
346 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
347                 uint8_t queues[], uint16_t nb_unlinks);
348
349 /**
350  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
351  *
352  * @param dev
353  *   Event device pointer
354  * @param ns
355  *   Wait time in nanosecond
356  * @param[out] timeout_ticks
357  *   Value for the *timeout_ticks* parameter in rte_event_dequeue() function
358  *
359  * @return
360  *   Returns 0 on success.
361  *
362  */
363 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
364                 uint64_t ns, uint64_t *timeout_ticks);
365
366 /**
367  * Dump internal information
368  *
369  * @param dev
370  *   Event device pointer
371  * @param f
372  *   A pointer to a file for output
373  *
374  */
375 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
376
377 /**
378  * Retrieve a set of statistics from device
379  *
380  * @param dev
381  *   Event device pointer
382  * @param ids
383  *   The stat ids to retrieve
384  * @param values
385  *   The returned stat values
386  * @param n
387  *   The number of id values and entries in the values array
388  * @return
389  *   The number of stat values successfully filled into the values array
390  */
391 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
392                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
393                 const unsigned int ids[], uint64_t values[], unsigned int n);
394
395 /**
396  * Resets the statistic values in xstats for the device, based on mode.
397  */
398 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
399                 enum rte_event_dev_xstats_mode mode,
400                 int16_t queue_port_id,
401                 const uint32_t ids[],
402                 uint32_t nb_ids);
403
404 /**
405  * Get names of extended stats of an event device
406  *
407  * @param dev
408  *   Event device pointer
409  * @param xstats_names
410  *   Array of name values to be filled in
411  * @param size
412  *   Number of values in the xstats_names array
413  * @return
414  *   When size >= the number of stats, return the number of stat values filled
415  *   into the array.
416  *   When size < the number of available stats, return the number of stats
417  *   values, and do not fill in any data into xstats_names.
418  */
419 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
420                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
421                 struct rte_event_dev_xstats_name *xstats_names,
422                 unsigned int *ids, unsigned int size);
423
424 /**
425  * Get value of one stats and optionally return its id
426  *
427  * @param dev
428  *   Event device pointer
429  * @param name
430  *   The name of the stat to retrieve
431  * @param id
432  *   Pointer to an unsigned int where we store the stat-id for future reference.
433  *   This pointer may be null if the id is not required.
434  * @return
435  *   The value of the stat, or (uint64_t)-1 if the stat is not found.
436  *   If the stat is not found, the id value will be returned as (unsigned)-1,
437  *   if id pointer is non-NULL
438  */
439 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
440                 const char *name, unsigned int *id);
441
442
443 /**
444  * Retrieve the event device's ethdev Rx adapter capabilities for the
445  * specified ethernet port
446  *
447  * @param dev
448  *   Event device pointer
449  *
450  * @param eth_dev
451  *   Ethernet device pointer
452  *
453  * @param[out] caps
454  *   A pointer to memory filled with Rx event adapter capabilities.
455  *
456  * @return
457  *   - 0: Success, driver provides Rx event adapter capabilities for the
458  *      ethernet device.
459  *   - <0: Error code returned by the driver function.
460  *
461  */
462 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
463                                         (const struct rte_eventdev *dev,
464                                         const struct rte_eth_dev *eth_dev,
465                                         uint32_t *caps);
466
467 struct rte_event_eth_rx_adapter_queue_conf *queue_conf;
468
469 /**
470  * Add ethernet Rx queues to event device. This callback is invoked if
471  * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
472  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
473  *
474  * @param dev
475  *   Event device pointer
476  *
477  * @param eth_dev
478  *   Ethernet device pointer
479  *
480  * @param rx_queue_id
481  *   Ethernet device receive queue index
482  *
483  * @param queue_conf
484  *  Additional configuration structure
485
486  * @return
487  *   - 0: Success, ethernet receive queue added successfully.
488  *   - <0: Error code returned by the driver function.
489  *
490  */
491 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
492                 const struct rte_eventdev *dev,
493                 const struct rte_eth_dev *eth_dev,
494                 int32_t rx_queue_id,
495                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
496
497 /**
498  * Delete ethernet Rx queues from event device. This callback is invoked if
499  * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
500  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
501  *
502  * @param dev
503  *   Event device pointer
504  *
505  * @param eth_dev
506  *   Ethernet device pointer
507  *
508  * @param rx_queue_id
509  *   Ethernet device receive queue index
510  *
511  * @return
512  *   - 0: Success, ethernet receive queue deleted successfully.
513  *   - <0: Error code returned by the driver function.
514  *
515  */
516 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
517                                         (const struct rte_eventdev *dev,
518                                         const struct rte_eth_dev *eth_dev,
519                                         int32_t rx_queue_id);
520
521 /**
522  * Start ethernet Rx adapter. This callback is invoked if
523  * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
524  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
525  * from eth_port_id have been added to the event device.
526  *
527  * @param dev
528  *   Event device pointer
529  *
530  * @param eth_dev
531  *   Ethernet device pointer
532  *
533  * @return
534  *   - 0: Success, ethernet Rx adapter started successfully.
535  *   - <0: Error code returned by the driver function.
536  */
537 typedef int (*eventdev_eth_rx_adapter_start_t)
538                                         (const struct rte_eventdev *dev,
539                                         const struct rte_eth_dev *eth_dev);
540
541 /**
542  * Stop ethernet Rx adapter. This callback is invoked if
543  * the caps returned from eventdev_eth_rx_adapter_caps_get(..,eth_port_id)
544  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
545  * from eth_port_id have been added to the event device.
546  *
547  * @param dev
548  *   Event device pointer
549  *
550  * @param eth_dev
551  *   Ethernet device pointer
552  *
553  * @return
554  *   - 0: Success, ethernet Rx adapter stopped successfully.
555  *   - <0: Error code returned by the driver function.
556  */
557 typedef int (*eventdev_eth_rx_adapter_stop_t)
558                                         (const struct rte_eventdev *dev,
559                                         const struct rte_eth_dev *eth_dev);
560
561 struct rte_event_eth_rx_adapter_stats *stats;
562
563 /**
564  * Retrieve ethernet Rx adapter statistics.
565  *
566  * @param dev
567  *   Event device pointer
568  *
569  * @param eth_dev
570  *   Ethernet device pointer
571  *
572  * @param[out] stats
573  *   Pointer to stats structure
574  *
575  * @return
576  *   Return 0 on success.
577  */
578
579 typedef int (*eventdev_eth_rx_adapter_stats_get)
580                         (const struct rte_eventdev *dev,
581                         const struct rte_eth_dev *eth_dev,
582                         struct rte_event_eth_rx_adapter_stats *stats);
583 /**
584  * Reset ethernet Rx adapter statistics.
585  *
586  * @param dev
587  *   Event device pointer
588  *
589  * @param eth_dev
590  *   Ethernet device pointer
591  *
592  * @return
593  *   Return 0 on success.
594  */
595 typedef int (*eventdev_eth_rx_adapter_stats_reset)
596                         (const struct rte_eventdev *dev,
597                         const struct rte_eth_dev *eth_dev);
598
599 /** Event device operations function pointer table */
600 struct rte_eventdev_ops {
601         eventdev_info_get_t dev_infos_get;      /**< Get device info. */
602         eventdev_configure_t dev_configure;     /**< Configure device. */
603         eventdev_start_t dev_start;             /**< Start device. */
604         eventdev_stop_t dev_stop;               /**< Stop device. */
605         eventdev_close_t dev_close;             /**< Close device. */
606
607         eventdev_queue_default_conf_get_t queue_def_conf;
608         /**< Get default queue configuration. */
609         eventdev_queue_setup_t queue_setup;
610         /**< Set up an event queue. */
611         eventdev_queue_release_t queue_release;
612         /**< Release an event queue. */
613
614         eventdev_port_default_conf_get_t port_def_conf;
615         /**< Get default port configuration. */
616         eventdev_port_setup_t port_setup;
617         /**< Set up an event port. */
618         eventdev_port_release_t port_release;
619         /**< Release an event port. */
620
621         eventdev_port_link_t port_link;
622         /**< Link event queues to an event port. */
623         eventdev_port_unlink_t port_unlink;
624         /**< Unlink event queues from an event port. */
625         eventdev_dequeue_timeout_ticks_t timeout_ticks;
626         /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
627         eventdev_dump_t dump;
628         /* Dump internal information */
629
630         eventdev_xstats_get_t xstats_get;
631         /**< Get extended device statistics. */
632         eventdev_xstats_get_names_t xstats_get_names;
633         /**< Get names of extended stats. */
634         eventdev_xstats_get_by_name xstats_get_by_name;
635         /**< Get one value by name. */
636         eventdev_xstats_reset_t xstats_reset;
637         /**< Reset the statistics values in xstats. */
638
639         eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
640         /**< Get ethernet Rx adapter capabilities */
641         eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
642         /**< Add Rx queues to ethernet Rx adapter */
643         eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
644         /**< Delete Rx queues from ethernet Rx adapter */
645         eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
646         /**< Start ethernet Rx adapter */
647         eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
648         /**< Stop ethernet Rx adapter */
649         eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
650         /**< Get ethernet Rx stats */
651         eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
652         /**< Reset ethernet Rx stats */
653 };
654
655 /**
656  * Allocates a new eventdev slot for an event device and returns the pointer
657  * to that slot for the driver to use.
658  *
659  * @param name
660  *   Unique identifier name for each device
661  * @param socket_id
662  *   Socket to allocate resources on.
663  * @return
664  *   - Slot in the rte_dev_devices array for a new device;
665  */
666 struct rte_eventdev *
667 rte_event_pmd_allocate(const char *name, int socket_id);
668
669 /**
670  * Release the specified eventdev device.
671  *
672  * @param eventdev
673  * The *eventdev* pointer is the address of the *rte_eventdev* structure.
674  * @return
675  *   - 0 on success, negative on error
676  */
677 int
678 rte_event_pmd_release(struct rte_eventdev *eventdev);
679
680 #ifdef __cplusplus
681 }
682 #endif
683
684 #endif /* _RTE_EVENTDEV_PMD_H_ */