mbuf: implement generic format for sched field
[dpdk.git] / lib / librte_eventdev / rte_event_eth_tx_adapter.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation.
3  */
4
5 #ifndef _RTE_EVENT_ETH_TX_ADAPTER_
6 #define _RTE_EVENT_ETH_TX_ADAPTER_
7
8 /**
9  * @file
10  *
11  * RTE Event Ethernet Tx Adapter
12  *
13  * The event ethernet Tx adapter provides configuration and data path APIs
14  * for the ethernet transmit stage of an event driven packet processing
15  * application. These APIs abstract the implementation of the transmit stage
16  * and allow the application to use eventdev PMD support or a common
17  * implementation.
18  *
19  * In the common implementation, the application enqueues mbufs to the adapter
20  * which runs as a rte_service function. The service function dequeues events
21  * from its event port and transmits the mbufs referenced by these events.
22  *
23  * The ethernet Tx event adapter APIs are:
24  *
25  *  - rte_event_eth_tx_adapter_create()
26  *  - rte_event_eth_tx_adapter_create_ext()
27  *  - rte_event_eth_tx_adapter_free()
28  *  - rte_event_eth_tx_adapter_start()
29  *  - rte_event_eth_tx_adapter_stop()
30  *  - rte_event_eth_tx_adapter_queue_add()
31  *  - rte_event_eth_tx_adapter_queue_del()
32  *  - rte_event_eth_tx_adapter_stats_get()
33  *  - rte_event_eth_tx_adapter_stats_reset()
34  *  - rte_event_eth_tx_adapter_enqueue()
35  *  - rte_event_eth_tx_adapter_event_port_get()
36  *  - rte_event_eth_tx_adapter_service_id_get()
37  *
38  * The application creates the adapter using
39  * rte_event_eth_tx_adapter_create() or rte_event_eth_tx_adapter_create_ext().
40  *
41  * The adapter will use the common implementation when the eventdev PMD
42  * does not have the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability.
43  * The common implementation uses an event port that is created using the port
44  * configuration parameter passed to rte_event_eth_tx_adapter_create(). The
45  * application can get the port identifier using
46  * rte_event_eth_tx_adapter_event_port_get() and must link an event queue to
47  * this port.
48  *
49  * If the eventdev PMD has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT
50  * flags set, Tx adapter events should be enqueued using the
51  * rte_event_eth_tx_adapter_enqueue() function, else the application should
52  * use rte_event_enqueue_burst().
53  *
54  * Transmit queues can be added and deleted from the adapter using
55  * rte_event_eth_tx_adapter_queue_add()/del() APIs respectively.
56  *
57  * The application can start and stop the adapter using the
58  * rte_event_eth_tx_adapter_start/stop() calls.
59  *
60  * The common adapter implementation uses an EAL service function as described
61  * before and its execution is controlled using the rte_service APIs. The
62  * rte_event_eth_tx_adapter_service_id_get()
63  * function can be used to retrieve the adapter's service function ID.
64  *
65  * The ethernet port and transmit queue index to transmit the mbuf on are
66  * specified using the mbuf port struct rte_mbuf::hash::txadapter:txq.
67  * The application should use the rte_event_eth_tx_adapter_txq_set()
68  * and rte_event_eth_tx_adapter_txq_get() functions to access the transmit
69  * queue index, using these macros will help with minimizing application
70  * impact due to a change in how the transmit queue index is specified.
71  */
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
77 #include <stdint.h>
78
79 #include <rte_mbuf.h>
80
81 #include "rte_eventdev.h"
82
83 /**
84  * @warning
85  * @b EXPERIMENTAL: this API may change without prior notice
86  *
87  * Adapter configuration structure
88  *
89  * @see rte_event_eth_tx_adapter_create_ext
90  * @see rte_event_eth_tx_adapter_conf_cb
91  */
92 struct rte_event_eth_tx_adapter_conf {
93         uint8_t event_port_id;
94         /**< Event port identifier, the adapter service function dequeues mbuf
95          * events from this port.
96          * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT
97          */
98         uint32_t max_nb_tx;
99         /**< The adapter can return early if it has processed at least
100          * max_nb_tx mbufs. This isn't treated as a requirement; batching may
101          * cause the adapter to process more than max_nb_tx mbufs.
102          */
103 };
104
105 /**
106  * @warning
107  * @b EXPERIMENTAL: this API may change without prior notice
108  *
109  * Function type used for adapter configuration callback. The callback is
110  * used to fill in members of the struct rte_event_eth_tx_adapter_conf, this
111  * callback is invoked when creating a RTE service function based
112  * adapter implementation.
113  *
114  * @param id
115  *  Adapter identifier.
116  * @param dev_id
117  *  Event device identifier.
118  * @param [out] conf
119  *  Structure that needs to be populated by this callback.
120  * @param arg
121  *  Argument to the callback. This is the same as the conf_arg passed to the
122  *  rte_event_eth_tx_adapter_create_ext().
123  *
124  * @return
125  *   - 0: Success
126  *   - <0: Error code on failure
127  */
128 typedef int (*rte_event_eth_tx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
129                                 struct rte_event_eth_tx_adapter_conf *conf,
130                                 void *arg);
131
132 /**
133  * @warning
134  * @b EXPERIMENTAL: this API may change without prior notice
135  *
136  * A structure used to retrieve statistics for an ethernet Tx adapter instance.
137  */
138 struct rte_event_eth_tx_adapter_stats {
139         uint64_t tx_retry;
140         /**< Number of transmit retries */
141         uint64_t tx_packets;
142         /**< Number of packets transmitted */
143         uint64_t tx_dropped;
144         /**< Number of packets dropped */
145 };
146
147 /**
148  * @warning
149  * @b EXPERIMENTAL: this API may change without prior notice
150  *
151  * Create a new ethernet Tx adapter with the specified identifier.
152  *
153  * @param id
154  *  The identifier of the ethernet Tx adapter.
155  * @param dev_id
156  *  The event device identifier.
157  * @param port_config
158  *  Event port configuration, the adapter uses this configuration to
159  *  create an event port if needed.
160  * @return
161  *   - 0: Success
162  *   - <0: Error code on failure
163  */
164 int __rte_experimental
165 rte_event_eth_tx_adapter_create(uint8_t id, uint8_t dev_id,
166                                 struct rte_event_port_conf *port_config);
167
168 /**
169  * @warning
170  * @b EXPERIMENTAL: this API may change without prior notice
171  *
172  * Create a new ethernet Tx adapter with the specified identifier.
173  *
174  * @param id
175  *  The identifier of the ethernet Tx adapter.
176  * @param dev_id
177  *  The event device identifier.
178  * @param conf_cb
179  *  Callback function that initializes members of the
180  *  struct rte_event_eth_tx_adapter_conf struct passed into
181  *  it.
182  * @param conf_arg
183  *  Argument that is passed to the conf_cb function.
184  * @return
185  *   - 0: Success
186  *   - <0: Error code on failure
187  */
188 int __rte_experimental
189 rte_event_eth_tx_adapter_create_ext(uint8_t id, uint8_t dev_id,
190                                 rte_event_eth_tx_adapter_conf_cb conf_cb,
191                                 void *conf_arg);
192
193 /**
194  * @warning
195  * @b EXPERIMENTAL: this API may change without prior notice
196  *
197  * Free an ethernet Tx adapter
198  *
199  * @param id
200  *  Adapter identifier.
201  * @return
202  *   - 0: Success
203  *   - <0: Error code on failure, If the adapter still has Tx queues
204  *      added to it, the function returns -EBUSY.
205  */
206 int __rte_experimental
207 rte_event_eth_tx_adapter_free(uint8_t id);
208
209 /**
210  * @warning
211  * @b EXPERIMENTAL: this API may change without prior notice
212  *
213  * Start ethernet Tx adapter
214  *
215  * @param id
216  *  Adapter identifier.
217  * @return
218  *  - 0: Success, Adapter started correctly.
219  *  - <0: Error code on failure.
220  */
221 int __rte_experimental
222 rte_event_eth_tx_adapter_start(uint8_t id);
223
224 /**
225  * @warning
226  * @b EXPERIMENTAL: this API may change without prior notice
227  *
228  * Stop ethernet Tx adapter
229  *
230  * @param id
231  *  Adapter identifier.
232  * @return
233  *  - 0: Success.
234  *  - <0: Error code on failure.
235  */
236 int __rte_experimental
237 rte_event_eth_tx_adapter_stop(uint8_t id);
238
239 /**
240  * @warning
241  * @b EXPERIMENTAL: this API may change without prior notice
242  *
243  * Add a Tx queue to the adapter.
244  * A queue value of -1 is used to indicate all
245  * queues within the device.
246  *
247  * @param id
248  *  Adapter identifier.
249  * @param eth_dev_id
250  *  Ethernet Port Identifier.
251  * @param queue
252  *  Tx queue index.
253  * @return
254  *  - 0: Success, Queues added successfully.
255  *  - <0: Error code on failure.
256  */
257 int __rte_experimental
258 rte_event_eth_tx_adapter_queue_add(uint8_t id,
259                                 uint16_t eth_dev_id,
260                                 int32_t queue);
261
262 /**
263  * @warning
264  * @b EXPERIMENTAL: this API may change without prior notice
265  *
266  * Delete a Tx queue from the adapter.
267  * A queue value of -1 is used to indicate all
268  * queues within the device, that have been added to this
269  * adapter.
270  *
271  * @param id
272  *  Adapter identifier.
273  * @param eth_dev_id
274  *  Ethernet Port Identifier.
275  * @param queue
276  *  Tx queue index.
277  * @return
278  *  - 0: Success, Queues deleted successfully.
279  *  - <0: Error code on failure.
280  */
281 int __rte_experimental
282 rte_event_eth_tx_adapter_queue_del(uint8_t id,
283                                 uint16_t eth_dev_id,
284                                 int32_t queue);
285
286 /**
287  * @warning
288  * @b EXPERIMENTAL: this API may change without prior notice
289  *
290  * Set Tx queue in the mbuf. This queue is used by the adapter
291  * to transmit the mbuf.
292  *
293  * @param pkt
294  *  Pointer to the mbuf.
295  * @param queue
296  *  Tx queue index.
297  */
298 static __rte_always_inline void __rte_experimental
299 rte_event_eth_tx_adapter_txq_set(struct rte_mbuf *pkt, uint16_t queue)
300 {
301         pkt->hash.txadapter.txq = queue;
302 }
303
304 /**
305  * @warning
306  * @b EXPERIMENTAL: this API may change without prior notice
307  *
308  * Retrieve Tx queue from the mbuf.
309  *
310  * @param pkt
311  *  Pointer to the mbuf.
312  * @return
313  *  Tx queue identifier.
314  *
315  * @see rte_event_eth_tx_adapter_txq_set()
316  */
317 static __rte_always_inline uint16_t __rte_experimental
318 rte_event_eth_tx_adapter_txq_get(struct rte_mbuf *pkt)
319 {
320         return pkt->hash.txadapter.txq;
321 }
322
323 /**
324  * @warning
325  * @b EXPERIMENTAL: this API may change without prior notice
326  *
327  * Retrieve the adapter event port. The adapter creates an event port if
328  * the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT is not set in the
329  * ethernet Tx capabilities of the event device.
330  *
331  * @param id
332  *  Adapter Identifier.
333  * @param[out] event_port_id
334  *  Event port pointer.
335  * @return
336  *   - 0: Success.
337  *   - <0: Error code on failure.
338  */
339 int __rte_experimental
340 rte_event_eth_tx_adapter_event_port_get(uint8_t id, uint8_t *event_port_id);
341
342 /**
343  * Enqueue a burst of events objects or an event object supplied in *rte_event*
344  * structure on an  event device designated by its *dev_id* through the event
345  * port specified by *port_id*. This function is supported if the eventdev PMD
346  * has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability flag set.
347  *
348  * The *nb_events* parameter is the number of event objects to enqueue which are
349  * supplied in the *ev* array of *rte_event* structure.
350  *
351  * The rte_event_eth_tx_adapter_enqueue() function returns the number of
352  * events objects it actually enqueued. A return value equal to *nb_events*
353  * means that all event objects have been enqueued.
354  *
355  * @param dev_id
356  *  The identifier of the device.
357  * @param port_id
358  *  The identifier of the event port.
359  * @param ev
360  *  Points to an array of *nb_events* objects of type *rte_event* structure
361  *  which contain the event object enqueue operations to be processed.
362  * @param nb_events
363  *  The number of event objects to enqueue, typically number of
364  *  rte_event_port_enqueue_depth() available for this port.
365  *
366  * @return
367  *   The number of event objects actually enqueued on the event device. The
368  *   return value can be less than the value of the *nb_events* parameter when
369  *   the event devices queue is full or if invalid parameters are specified in a
370  *   *rte_event*. If the return value is less than *nb_events*, the remaining
371  *   events at the end of ev[] are not consumed and the caller has to take care
372  *   of them, and rte_errno is set accordingly. Possible errno values include:
373  *   - -EINVAL  The port ID is invalid, device ID is invalid, an event's queue
374  *              ID is invalid, or an event's sched type doesn't match the
375  *              capabilities of the destination queue.
376  *   - -ENOSPC  The event port was backpressured and unable to enqueue
377  *              one or more events. This error code is only applicable to
378  *              closed systems.
379  */
380 static inline uint16_t __rte_experimental
381 rte_event_eth_tx_adapter_enqueue(uint8_t dev_id,
382                                 uint8_t port_id,
383                                 struct rte_event ev[],
384                                 uint16_t nb_events)
385 {
386         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
387
388 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
389         if (dev_id >= RTE_EVENT_MAX_DEVS ||
390                 !rte_eventdevs[dev_id].attached) {
391                 rte_errno = -EINVAL;
392                 return 0;
393         }
394
395         if (port_id >= dev->data->nb_ports) {
396                 rte_errno = -EINVAL;
397                 return 0;
398         }
399 #endif
400         return dev->txa_enqueue(dev->data->ports[port_id], ev, nb_events);
401 }
402
403 /**
404  * @warning
405  * @b EXPERIMENTAL: this API may change without prior notice
406  *
407  * Retrieve statistics for an adapter
408  *
409  * @param id
410  *  Adapter identifier.
411  * @param [out] stats
412  *  A pointer to structure used to retrieve statistics for an adapter.
413  * @return
414  *  - 0: Success, statistics retrieved successfully.
415  *  - <0: Error code on failure.
416  */
417 int __rte_experimental
418 rte_event_eth_tx_adapter_stats_get(uint8_t id,
419                                 struct rte_event_eth_tx_adapter_stats *stats);
420
421 /**
422  * @warning
423  * @b EXPERIMENTAL: this API may change without prior notice
424  *
425  * Reset statistics for an adapter.
426  *
427  * @param id
428  *  Adapter identifier.
429  * @return
430  *  - 0: Success, statistics reset successfully.
431  *  - <0: Error code on failure.
432  */
433 int __rte_experimental
434 rte_event_eth_tx_adapter_stats_reset(uint8_t id);
435
436 /**
437  * @warning
438  * @b EXPERIMENTAL: this API may change without prior notice
439  *
440  * Retrieve the service ID of an adapter. If the adapter doesn't use
441  * a rte_service function, this function returns -ESRCH.
442  *
443  * @param id
444  *  Adapter identifier.
445  * @param [out] service_id
446  *  A pointer to a uint32_t, to be filled in with the service id.
447  * @return
448  *  - 0: Success
449  *  - <0: Error code on failure, if the adapter doesn't use a rte_service
450  * function, this function returns -ESRCH.
451  */
452 int __rte_experimental
453 rte_event_eth_tx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
454
455 #ifdef __cplusplus
456 }
457 #endif
458 #endif  /* _RTE_EVENT_ETH_TX_ADAPTER_ */