]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/lib/librte_eventdev/rte_event_eth_rx_adapter.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / lib / librte_eventdev / rte_event_eth_rx_adapter.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation.
3 * All rights reserved.
4 */
5
6 #ifndef _RTE_EVENT_ETH_RX_ADAPTER_
7 #define _RTE_EVENT_ETH_RX_ADAPTER_
8
9 /**
10 * @file
11 *
12 * RTE Event Ethernet Rx Adapter
13 *
14 * An eventdev-based packet processing application enqueues/dequeues mbufs
15 * to/from the event device. Packet flow from the ethernet device to the event
16 * device can be accomplished using either HW or SW mechanisms depending on the
17 * platform and the particular combination of ethernet and event devices. The
18 * event ethernet Rx adapter provides common APIs to configure the packet flow
19 * from the ethernet devices to event devices across both these transfer
20 * mechanisms.
21 *
22 * The adapter uses a EAL service core function for SW based packet transfer
23 * and uses the eventdev PMD functions to configure HW based packet transfer
24 * between the ethernet device and the event device. For SW based packet
25 * transfer, if the mbuf does not have a timestamp set, the adapter adds a
26 * timestamp to the mbuf using rte_get_tsc_cycles(), this provides a more
27 * accurate timestamp as compared to if the application were to set the time
28 * stamp since it avoids event device schedule latency.
29 *
30 * The ethernet Rx event adapter's functions are:
31 * - rte_event_eth_rx_adapter_create_ext()
32 * - rte_event_eth_rx_adapter_create()
33 * - rte_event_eth_rx_adapter_free()
34 * - rte_event_eth_rx_adapter_queue_add()
35 * - rte_event_eth_rx_adapter_queue_del()
36 * - rte_event_eth_rx_adapter_start()
37 * - rte_event_eth_rx_adapter_stop()
38 * - rte_event_eth_rx_adapter_stats_get()
39 * - rte_event_eth_rx_adapter_stats_reset()
40 *
41 * The application creates an ethernet to event adapter using
42 * rte_event_eth_rx_adapter_create_ext() or rte_event_eth_rx_adapter_create()
43 * functions.
44 * The adapter needs to know which ethernet rx queues to poll for mbufs as well
45 * as event device parameters such as the event queue identifier, event
46 * priority and scheduling type that the adapter should use when constructing
47 * events. The rte_event_eth_rx_adapter_queue_add() function is provided for
48 * this purpose.
49 * The servicing weight parameter in the rte_event_eth_rx_adapter_queue_conf
50 * is applicable when the Rx adapter uses a service core function and is
51 * intended to provide application control of the frequency of polling ethernet
52 * device receive queues, for example, the application may want to poll higher
53 * priority queues with a higher frequency but at the same time not starve
54 * lower priority queues completely. If this parameter is zero and the receive
55 * interrupt is enabled when configuring the device, the receive queue is
56 * interrupt driven; else, the queue is assigned a servicing weight of one.
57 *
58 * The application can start/stop the adapter using the
59 * rte_event_eth_rx_adapter_start() and the rte_event_eth_rx_adapter_stop()
60 * functions. If the adapter uses a rte_service function, then the application
61 * is also required to assign a core to the service function and control the
62 * service core using the rte_service APIs. The
63 * rte_event_eth_rx_adapter_service_id_get() function can be used to retrieve
64 * the service function ID of the adapter in this case.
65 *
66 * For SW based packet transfers, i.e., when the
67 * RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT is not set in the adapter's
68 * capabilities flags for a particular ethernet device, the service function
69 * temporarily enqueues mbufs to an event buffer before batch enqueuing these
70 * to the event device. If the buffer fills up, the service function stops
71 * dequeuing packets from the ethernet device. The application may want to
72 * monitor the buffer fill level and instruct the service function to
73 * selectively buffer packets. The application may also use some other
74 * criteria to decide which packets should enter the event device even when
75 * the event buffer fill level is low. The
76 * rte_event_eth_rx_adapter_cb_register() function allows the
77 * application to register a callback that selects which packets to enqueue
78 * to the event device.
79 */
80
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84
85 #include <stdint.h>
86
87 #include <rte_service.h>
88
89 #include "rte_eventdev.h"
90
91 #define RTE_EVENT_ETH_RX_ADAPTER_MAX_INSTANCE 32
92
93 /* struct rte_event_eth_rx_adapter_queue_conf flags definitions */
94 #define RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID 0x1
95 /**< This flag indicates the flow identifier is valid
96 * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
97 */
98
99 /**
100 * Adapter configuration structure that the adapter configuration callback
101 * function is expected to fill out
102 * @see rte_event_eth_rx_adapter_conf_cb
103 */
104 struct rte_event_eth_rx_adapter_conf {
105 uint8_t event_port_id;
106 /**< Event port identifier, the adapter enqueues mbuf events to this
107 * port.
108 */
109 uint32_t max_nb_rx;
110 /**< The adapter can return early if it has processed at least
111 * max_nb_rx mbufs. This isn't treated as a requirement; batching may
112 * cause the adapter to process more than max_nb_rx mbufs.
113 */
114 };
115
116 /**
117 * Function type used for adapter configuration callback. The callback is
118 * used to fill in members of the struct rte_event_eth_rx_adapter_conf, this
119 * callback is invoked when creating a SW service for packet transfer from
120 * ethdev queues to the event device. The SW service is created within the
121 * rte_event_eth_rx_adapter_queue_add() function if SW based packet transfers
122 * from ethdev queues to the event device are required.
123 *
124 * @param id
125 * Adapter identifier.
126 *
127 * @param dev_id
128 * Event device identifier.
129 *
130 * @param [out] conf
131 * Structure that needs to be populated by this callback.
132 *
133 * @param arg
134 * Argument to the callback. This is the same as the conf_arg passed to the
135 * rte_event_eth_rx_adapter_create_ext().
136 */
137 typedef int (*rte_event_eth_rx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
138 struct rte_event_eth_rx_adapter_conf *conf,
139 void *arg);
140
141 /**
142 * Rx queue configuration structure
143 */
144 struct rte_event_eth_rx_adapter_queue_conf {
145 uint32_t rx_queue_flags;
146 /**< Flags for handling received packets
147 * @see RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID
148 */
149 uint16_t servicing_weight;
150 /**< Relative polling frequency of ethernet receive queue when the
151 * adapter uses a service core function for ethernet to event device
152 * transfers. If it is set to zero, the Rx queue is interrupt driven
153 * (unless rx queue interrupts are not enabled for the ethernet
154 * device).
155 */
156 struct rte_event ev;
157 /**<
158 * The values from the following event fields will be used when
159 * queuing mbuf events:
160 * - event_queue_id: Targeted event queue ID for received packets.
161 * - event_priority: Event priority of packets from this Rx queue in
162 * the event queue relative to other events.
163 * - sched_type: Scheduling type for packets from this Rx queue.
164 * - flow_id: If the RTE_ETH_RX_EVENT_ADAPTER_QUEUE_FLOW_ID_VALID bit
165 * is set in rx_queue_flags, this flow_id is used for all
166 * packets received from this queue. Otherwise the flow ID
167 * is set to the RSS hash of the src and dst IPv4/6
168 * addresses.
169 *
170 * The event adapter sets ev.event_type to RTE_EVENT_TYPE_ETHDEV in the
171 * enqueued event.
172 */
173 };
174
175 /**
176 * @warning
177 * @b EXPERIMENTAL: this API may change without prior notice
178 *
179 * A structure used to retrieve statistics for an eth rx adapter instance.
180 */
181 struct rte_event_eth_rx_adapter_stats {
182 uint64_t rx_poll_count;
183 /**< Receive queue poll count */
184 uint64_t rx_packets;
185 /**< Received packet count */
186 uint64_t rx_enq_count;
187 /**< Eventdev enqueue count */
188 uint64_t rx_enq_retry;
189 /**< Eventdev enqueue retry count */
190 uint64_t rx_enq_start_ts;
191 /**< Rx enqueue start timestamp */
192 uint64_t rx_enq_block_cycles;
193 /**< Cycles for which the service is blocked by the event device,
194 * i.e, the service fails to enqueue to the event device.
195 */
196 uint64_t rx_enq_end_ts;
197 /**< Latest timestamp at which the service is unblocked
198 * by the event device. The start, end timestamps and
199 * block cycles can be used to compute the percentage of
200 * cycles the service is blocked by the event device.
201 */
202 uint64_t rx_intr_packets;
203 /**< Received packet count for interrupt mode Rx queues */
204 };
205
206 /**
207 * @warning
208 * @b EXPERIMENTAL: this API may change without prior notice
209 *
210 * Callback function invoked by the SW adapter before it continues
211 * to process packets. The callback is passed the size of the enqueue
212 * buffer in the SW adapter and the occupancy of the buffer. The
213 * callback can use these values to decide which mbufs should be
214 * enqueued to the event device. If the return value of the callback
215 * is less than nb_mbuf then the SW adapter uses the return value to
216 * enqueue enq_mbuf[] to the event device.
217 *
218 * @param eth_dev_id
219 * Port identifier of the Ethernet device.
220 * @param queue_id
221 * Receive queue index.
222 * @param enqueue_buf_size
223 * Total enqueue buffer size.
224 * @param enqueue_buf_count
225 * mbuf count in enqueue buffer.
226 * @param mbuf
227 * mbuf array.
228 * @param nb_mbuf
229 * mbuf count.
230 * @param cb_arg
231 * Callback argument.
232 * @param[out] enq_mbuf
233 * The adapter enqueues enq_mbuf[] if the return value of the
234 * callback is less than nb_mbuf
235 * @return
236 * Returns the number of mbufs should be enqueued to eventdev
237 */
238 typedef uint16_t (*rte_event_eth_rx_adapter_cb_fn)(uint16_t eth_dev_id,
239 uint16_t queue_id,
240 uint32_t enqueue_buf_size,
241 uint32_t enqueue_buf_count,
242 struct rte_mbuf **mbuf,
243 uint16_t nb_mbuf,
244 void *cb_arg,
245 struct rte_mbuf **enq_buf);
246
247 /**
248 * Create a new ethernet Rx event adapter with the specified identifier.
249 *
250 * @param id
251 * The identifier of the ethernet Rx event adapter.
252 *
253 * @param dev_id
254 * The identifier of the device to configure.
255 *
256 * @param conf_cb
257 * Callback function that fills in members of a
258 * struct rte_event_eth_rx_adapter_conf struct passed into
259 * it.
260 *
261 * @param conf_arg
262 * Argument that is passed to the conf_cb function.
263 *
264 * @return
265 * - 0: Success
266 * - <0: Error code on failure
267 */
268 int rte_event_eth_rx_adapter_create_ext(uint8_t id, uint8_t dev_id,
269 rte_event_eth_rx_adapter_conf_cb conf_cb,
270 void *conf_arg);
271
272 /**
273 * Create a new ethernet Rx event adapter with the specified identifier.
274 * This function uses an internal configuration function that creates an event
275 * port. This default function reconfigures the event device with an
276 * additional event port and setups up the event port using the port_config
277 * parameter passed into this function. In case the application needs more
278 * control in configuration of the service, it should use the
279 * rte_event_eth_rx_adapter_create_ext() version.
280 *
281 * @param id
282 * The identifier of the ethernet Rx event adapter.
283 *
284 * @param dev_id
285 * The identifier of the device to configure.
286 *
287 * @param port_config
288 * Argument of type *rte_event_port_conf* that is passed to the conf_cb
289 * function.
290 *
291 * @return
292 * - 0: Success
293 * - <0: Error code on failure
294 */
295 int rte_event_eth_rx_adapter_create(uint8_t id, uint8_t dev_id,
296 struct rte_event_port_conf *port_config);
297
298 /**
299 * Free an event adapter
300 *
301 * @param id
302 * Adapter identifier.
303 *
304 * @return
305 * - 0: Success
306 * - <0: Error code on failure, If the adapter still has Rx queues
307 * added to it, the function returns -EBUSY.
308 */
309 int rte_event_eth_rx_adapter_free(uint8_t id);
310
311 /**
312 * Add receive queue to an event adapter. After a queue has been
313 * added to the event adapter, the result of the application calling
314 * rte_eth_rx_burst(eth_dev_id, rx_queue_id, ..) is undefined.
315 *
316 * @param id
317 * Adapter identifier.
318 *
319 * @param eth_dev_id
320 * Port identifier of Ethernet device.
321 *
322 * @param rx_queue_id
323 * Ethernet device receive queue index.
324 * If rx_queue_id is -1, then all Rx queues configured for
325 * the device are added. If the ethdev Rx queues can only be
326 * connected to a single event queue then rx_queue_id is
327 * required to be -1.
328 * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ
329 *
330 * @param conf
331 * Additional configuration structure of type *rte_event_eth_rx_adapter_conf*
332 *
333 * @return
334 * - 0: Success, Receive queue added correctly.
335 * - <0: Error code on failure.
336 * - (-EIO) device reconfiguration and restart error. The adapter reconfigures
337 * the event device with an additional port if it is required to use a service
338 * function for packet transfer from the ethernet device to the event device.
339 * If the device had been started before this call, this error code indicates
340 * an error in restart following an error in reconfiguration, i.e., a
341 * combination of the two error codes.
342 */
343 int rte_event_eth_rx_adapter_queue_add(uint8_t id,
344 uint16_t eth_dev_id,
345 int32_t rx_queue_id,
346 const struct rte_event_eth_rx_adapter_queue_conf *conf);
347
348 /**
349 * Delete receive queue from an event adapter.
350 *
351 * @param id
352 * Adapter identifier.
353 *
354 * @param eth_dev_id
355 * Port identifier of Ethernet device.
356 *
357 * @param rx_queue_id
358 * Ethernet device receive queue index.
359 * If rx_queue_id is -1, then all Rx queues configured for
360 * the device are deleted. If the ethdev Rx queues can only be
361 * connected to a single event queue then rx_queue_id is
362 * required to be -1.
363 * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ
364 *
365 * @return
366 * - 0: Success, Receive queue deleted correctly.
367 * - <0: Error code on failure.
368 */
369 int rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id,
370 int32_t rx_queue_id);
371
372 /**
373 * Start ethernet Rx event adapter
374 *
375 * @param id
376 * Adapter identifier.
377 *
378 * @return
379 * - 0: Success, Adapter started correctly.
380 * - <0: Error code on failure.
381 *
382 * @note
383 * The eventdev to which the event_eth_rx_adapter is connected needs to
384 * be started before calling rte_event_eth_rx_adapter_start().
385 */
386 int rte_event_eth_rx_adapter_start(uint8_t id);
387
388 /**
389 * Stop ethernet Rx event adapter
390 *
391 * @param id
392 * Adapter identifier.
393 *
394 * @return
395 * - 0: Success, Adapter started correctly.
396 * - <0: Error code on failure.
397 */
398 int rte_event_eth_rx_adapter_stop(uint8_t id);
399
400 /**
401 * @warning
402 * @b EXPERIMENTAL: this API may change without prior notice
403 *
404 * Retrieve statistics for an adapter
405 *
406 * @param id
407 * Adapter identifier.
408 *
409 * @param [out] stats
410 * A pointer to structure used to retrieve statistics for an adapter.
411 *
412 * @return
413 * - 0: Success, retrieved successfully.
414 * - <0: Error code on failure.
415 */
416 int __rte_experimental
417 rte_event_eth_rx_adapter_stats_get(uint8_t id,
418 struct rte_event_eth_rx_adapter_stats *stats);
419
420 /**
421 * Reset statistics for an adapter.
422 *
423 * @param id
424 * Adapter identifier.
425 *
426 * @return
427 * - 0: Success, statistics reset successfully.
428 * - <0: Error code on failure.
429 */
430 int rte_event_eth_rx_adapter_stats_reset(uint8_t id);
431
432 /**
433 * Retrieve the service ID of an adapter. If the adapter doesn't use
434 * a rte_service function, this function returns -ESRCH.
435 *
436 * @param id
437 * Adapter identifier.
438 *
439 * @param [out] service_id
440 * A pointer to a uint32_t, to be filled in with the service id.
441 *
442 * @return
443 * - 0: Success
444 * - <0: Error code on failure, if the adapter doesn't use a rte_service
445 * function, this function returns -ESRCH.
446 */
447 int rte_event_eth_rx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
448
449 /**
450 * @warning
451 * @b EXPERIMENTAL: this API may change without prior notice
452 *
453 * Register callback to process Rx packets, this is supported for
454 * SW based packet transfers.
455 * @see rte_event_eth_rx_cb_fn
456 *
457 * @param id
458 * Adapter identifier.
459 * @param eth_dev_id
460 * Port identifier of Ethernet device.
461 * @param cb_fn
462 * Callback function.
463 * @param cb_arg
464 * Callback arg.
465 * @return
466 * - 0: Success
467 * - <0: Error code on failure.
468 */
469 int __rte_experimental
470 rte_event_eth_rx_adapter_cb_register(uint8_t id,
471 uint16_t eth_dev_id,
472 rte_event_eth_rx_adapter_cb_fn cb_fn,
473 void *cb_arg);
474
475 #ifdef __cplusplus
476 }
477 #endif
478 #endif /* _RTE_EVENT_ETH_RX_ADAPTER_ */