1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef _RTE_INTERRUPTS_H_
6 #define _RTE_INTERRUPTS_H_
10 #include <rte_bitops.h>
11 #include <rte_common.h>
12 #include <rte_compat.h>
13 #include <rte_epoll.h>
18 * The RTE interrupt interface provides functions to register/unregister
19 * callbacks for a specific interrupt.
26 /** Interrupt handle */
27 struct rte_intr_handle;
29 /** Interrupt instance allocation flags
30 * @see rte_intr_instance_alloc
33 /** Interrupt instance will not be shared between primary and secondary processes. */
34 #define RTE_INTR_INSTANCE_F_PRIVATE UINT32_C(0)
35 /** Interrupt instance will be shared between primary and secondary processes. */
36 #define RTE_INTR_INSTANCE_F_SHARED RTE_BIT32(0)
38 /** Function to be registered for the specific interrupt */
39 typedef void (*rte_intr_callback_fn)(void *cb_arg);
42 * Function to call after a callback is unregistered.
43 * Can be used to close fd and free cb_arg.
45 typedef void (*rte_intr_unregister_callback_fn)(struct rte_intr_handle *intr_handle,
48 #include "rte_eal_interrupts.h"
51 * It registers the callback for the specific interrupt. Multiple
52 * callbacks can be registered at the same time.
54 * Pointer to the interrupt handle.
58 * address of parameter for callback.
62 * - On failure, a negative value.
64 int rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
65 rte_intr_callback_fn cb, void *cb_arg);
68 * It unregisters the callback according to the specified interrupt handle.
71 * pointer to the interrupt handle.
75 * address of parameter for callback, (void *)-1 means to remove all
76 * registered which has the same callback address.
79 * - On success, return the number of callback entities removed.
80 * - On failure, a negative value.
82 int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
83 rte_intr_callback_fn cb, void *cb_arg);
86 * Unregister the callback according to the specified interrupt handle,
87 * after it's no longer active. Fail if source is not active.
90 * pointer to the interrupt handle.
94 * address of parameter for callback, (void *)-1 means to remove all
95 * registered which has the same callback address.
97 * callback to call before cb is unregistered (optional).
98 * can be used to close fd and free cb_arg.
101 * - On success, return the number of callback entities marked for remove.
102 * - On failure, a negative value.
106 rte_intr_callback_unregister_pending(const struct rte_intr_handle *intr_handle,
107 rte_intr_callback_fn cb_fn, void *cb_arg,
108 rte_intr_unregister_callback_fn ucb_fn);
112 * @b EXPERIMENTAL: this API may change without prior notice
114 * Loop until rte_intr_callback_unregister() succeeds.
115 * After a call to this function,
116 * the callback provided by the specified interrupt handle is unregistered.
119 * pointer to the interrupt handle.
123 * address of parameter for callback, (void *)-1 means to remove all
124 * registered which has the same callback address.
127 * - On success, return the number of callback entities removed.
128 * - On failure, a negative value.
132 rte_intr_callback_unregister_sync(const struct rte_intr_handle *intr_handle,
133 rte_intr_callback_fn cb, void *cb_arg);
136 * It enables the interrupt for the specified handle.
139 * pointer to the interrupt handle.
142 * - On success, zero.
143 * - On failure, a negative value.
145 int rte_intr_enable(const struct rte_intr_handle *intr_handle);
148 * It disables the interrupt for the specified handle.
151 * pointer to the interrupt handle.
154 * - On success, zero.
155 * - On failure, a negative value.
157 int rte_intr_disable(const struct rte_intr_handle *intr_handle);
161 * @b EXPERIMENTAL: this API may change without prior notice
163 * It acknowledges an interrupt raised for the specified handle.
165 * This function should be called at the end of each interrupt handler either
166 * from application or driver, so that currently raised interrupt is acked and
167 * further new interrupts are raised.
170 * pointer to the interrupt handle.
173 * - On success, zero.
174 * - On failure, a negative value.
177 int rte_intr_ack(const struct rte_intr_handle *intr_handle);
181 * @b EXPERIMENTAL: this API may change without prior notice
183 * Check if currently executing in interrupt context
186 * - non zero in case of interrupt context
187 * - zero in case of process context
191 rte_thread_is_intr(void);
195 * @b EXPERIMENTAL: this API may change without prior notice
197 * It allocates memory for interrupt instance. API takes flag as an argument
198 * which define from where memory should be allocated i.e. using DPDK memory
199 * management library APIs or normal heap allocation.
200 * Default memory allocation for event fds and event list array is done which
201 * can be realloced later based on size of MSIX interrupts supported by a PCI
204 * This function should be called from application or driver, before calling
205 * any of the interrupt APIs.
208 * See RTE_INTR_INSTANCE_F_* flags definitions.
211 * - On success, address of interrupt handle.
212 * - On failure, NULL.
215 struct rte_intr_handle *
216 rte_intr_instance_alloc(uint32_t flags);
220 * @b EXPERIMENTAL: this API may change without prior notice
222 * This API is used to free the memory allocated for interrupt handle
226 * Interrupt handle address.
231 rte_intr_instance_free(struct rte_intr_handle *intr_handle);
235 * @b EXPERIMENTAL: this API may change without prior notice
237 * This API is used to set the fd field of interrupt handle with user provided
241 * pointer to the interrupt handle.
243 * file descriptor value provided by user.
246 * - On success, zero.
247 * - On failure, a negative value and rte_errno is set.
251 rte_intr_fd_set(struct rte_intr_handle *intr_handle, int fd);
255 * @b EXPERIMENTAL: this API may change without prior notice
257 * Returns the fd field of the given interrupt handle instance.
260 * pointer to the interrupt handle.
263 * - On success, fd field.
264 * - On failure, a negative value.
268 rte_intr_fd_get(const struct rte_intr_handle *intr_handle);
272 * @b EXPERIMENTAL: this API may change without prior notice
274 * This API is used to set the type field of interrupt handle with user provided
278 * pointer to the interrupt handle.
283 * - On success, zero.
284 * - On failure, a negative value and rte_errno is set.
288 rte_intr_type_set(struct rte_intr_handle *intr_handle,
289 enum rte_intr_handle_type type);
293 * @b EXPERIMENTAL: this API may change without prior notice
295 * Returns the type field of the given interrupt handle instance.
298 * pointer to the interrupt handle.
301 * - On success, interrupt type
302 * - On failure, RTE_INTR_HANDLE_UNKNOWN.
305 enum rte_intr_handle_type
306 rte_intr_type_get(const struct rte_intr_handle *intr_handle);
310 * The function returns the per thread epoll instance.
313 * epfd the epoll instance referred to.
317 rte_intr_tls_epfd(void);
322 * Pointer to the interrupt handle.
324 * Epoll instance fd which the intr vector associated to.
326 * The operation be performed for the vector.
327 * Operation type of {ADD, DEL}.
329 * RX intr vector number added to the epoll instance wait list.
333 * - On success, zero.
334 * - On failure, a negative value.
338 rte_intr_rx_ctl(struct rte_intr_handle *intr_handle,
339 int epfd, int op, unsigned int vec, void *data);
343 * It deletes registered eventfds.
346 * Pointer to the interrupt handle.
350 rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle);
354 * It enables the packet I/O interrupt event if it's necessary.
355 * It creates event fd for each interrupt vector when MSIX is used,
356 * otherwise it multiplexes a single event fd.
359 * Pointer to the interrupt handle.
361 * Number of interrupt vector trying to enable.
362 * The value 0 is not allowed.
364 * - On success, zero.
365 * - On failure, a negative value.
369 rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd);
373 * It disables the packet I/O interrupt event.
374 * It deletes registered eventfds and closes the open fds.
377 * Pointer to the interrupt handle.
381 rte_intr_efd_disable(struct rte_intr_handle *intr_handle);
385 * The packet I/O interrupt on datapath is enabled or not.
388 * Pointer to the interrupt handle.
392 rte_intr_dp_is_en(struct rte_intr_handle *intr_handle);
396 * The interrupt handle instance allows other causes or not.
397 * Other causes stand for any none packet I/O interrupts.
400 * Pointer to the interrupt handle.
404 rte_intr_allow_others(struct rte_intr_handle *intr_handle);
408 * The multiple interrupt vector capability of interrupt handle instance.
409 * It returns zero if no multiple interrupt vector support.
412 * Pointer to the interrupt handle.
416 rte_intr_cap_multiple(struct rte_intr_handle *intr_handle);
420 * Creates a clone of src by allocating a new handle and copying src content.
423 * Source interrupt handle to be cloned.
426 * - On success, address of interrupt handle.
427 * - On failure, NULL.
430 struct rte_intr_handle *
431 rte_intr_instance_dup(const struct rte_intr_handle *src);
435 * This API is used to set the device fd field of interrupt handle with user
436 * provided dev fd. Device fd corresponds to VFIO device fd or UIO config fd.
439 * pointer to the interrupt handle.
444 * - On success, zero.
445 * - On failure, a negative value and rte_errno is set.
449 rte_intr_dev_fd_set(struct rte_intr_handle *intr_handle, int fd);
453 * Returns the device fd field of the given interrupt handle instance.
456 * pointer to the interrupt handle.
459 * - On success, dev fd.
460 * - On failure, a negative value and rte_errno is set.
464 rte_intr_dev_fd_get(const struct rte_intr_handle *intr_handle);
468 * This API is used to set the max intr field of interrupt handle with user
469 * provided max intr value.
472 * pointer to the interrupt handle.
477 * - On success, zero.
478 * - On failure, a negative value and rte_errno is set.
482 rte_intr_max_intr_set(struct rte_intr_handle *intr_handle, int max_intr);
486 * Returns the max intr field of the given interrupt handle instance.
489 * pointer to the interrupt handle.
492 * - On success, max intr.
493 * - On failure, a negative value and rte_errno is set.
497 rte_intr_max_intr_get(const struct rte_intr_handle *intr_handle);
501 * This API is used to set the number of event fd field of interrupt handle
502 * with user provided available event file descriptor value.
505 * pointer to the interrupt handle.
510 * - On success, zero.
511 * - On failure, a negative value and rte_errno is set.
515 rte_intr_nb_efd_set(struct rte_intr_handle *intr_handle, int nb_efd);
519 * Returns the number of available event fd field of the given interrupt handle
523 * pointer to the interrupt handle.
526 * - On success, nb_efd
527 * - On failure, a negative value and rte_errno is set.
531 rte_intr_nb_efd_get(const struct rte_intr_handle *intr_handle);
535 * Returns the number of interrupt vector field of the given interrupt handle
536 * instance. This field is to configured on device probe time, and based on
537 * this value efds and elist arrays are dynamically allocated. By default
538 * this value is set to RTE_MAX_RXTX_INTR_VEC_ID.
539 * For eg. in case of PCI device, its msix size is queried and efds/elist
540 * arrays are allocated accordingly.
543 * pointer to the interrupt handle.
546 * - On success, nb_intr
547 * - On failure, a negative value and rte_errno is set.
551 rte_intr_nb_intr_get(const struct rte_intr_handle *intr_handle);
555 * This API is used to set the event fd counter size field of interrupt handle
556 * with user provided efd counter size.
559 * pointer to the interrupt handle.
560 * @param efd_counter_size
561 * size of efd counter.
564 * - On success, zero.
565 * - On failure, a negative value and rte_errno is set.
569 rte_intr_efd_counter_size_set(struct rte_intr_handle *intr_handle,
570 uint8_t efd_counter_size);
574 * Returns the event fd counter size field of the given interrupt handle
578 * pointer to the interrupt handle.
581 * - On success, efd_counter_size
582 * - On failure, a negative value and rte_errno is set.
586 rte_intr_efd_counter_size_get(const struct rte_intr_handle *intr_handle);
590 * This API is used to set the event fd array index with the given fd.
593 * pointer to the interrupt handle.
595 * efds array index to be set
600 * - On success, zero.
601 * - On failure, a negative value and rte_errno is set.
605 rte_intr_efds_index_set(struct rte_intr_handle *intr_handle, int index, int fd);
609 * Returns the fd value of event fds array at a given index.
612 * pointer to the interrupt handle.
614 * efds array index to be returned
618 * - On failure, a negative value and rte_errno is set.
622 rte_intr_efds_index_get(const struct rte_intr_handle *intr_handle, int index);
626 * This API is used to set the epoll event object array index with the given
630 * pointer to the interrupt handle.
632 * elist array index to be set
634 * epoll event instance of struct rte_epoll_event
637 * - On success, zero.
638 * - On failure, a negative value and rte_errno is set.
642 rte_intr_elist_index_set(struct rte_intr_handle *intr_handle, int index,
643 struct rte_epoll_event elist);
647 * Returns the address of epoll event instance from elist array at a given
651 * pointer to the interrupt handle.
653 * elist array index to be returned
656 * - On success, elist
657 * - On failure, a negative value and rte_errno is set.
660 struct rte_epoll_event *
661 rte_intr_elist_index_get(struct rte_intr_handle *intr_handle, int index);
665 * Allocates the memory of interrupt vector list array, with size defining the
666 * number of elements required in the array.
669 * pointer to the interrupt handle.
671 * Name assigned to the allocation, or NULL.
673 * Number of element required in the array.
677 * - On failure, a negative value and rte_errno is set.
681 rte_intr_vec_list_alloc(struct rte_intr_handle *intr_handle, const char *name,
686 * Sets the vector value at given index of interrupt vector list field of given
690 * pointer to the interrupt handle.
692 * intr_vec array index to be set
694 * Interrupt vector value.
698 * - On failure, a negative value and rte_errno is set.
702 rte_intr_vec_list_index_set(struct rte_intr_handle *intr_handle, int index,
707 * Returns the vector value at the given index of interrupt vector list array.
710 * pointer to the interrupt handle.
712 * intr_vec array index to be returned
715 * - On success, interrupt vector
716 * - On failure, a negative value and rte_errno is set.
720 rte_intr_vec_list_index_get(const struct rte_intr_handle *intr_handle,
725 * Frees the memory allocated for interrupt vector list array.
728 * pointer to the interrupt handle.
732 * - On failure, a negative value and rte_errno is set.
736 rte_intr_vec_list_free(struct rte_intr_handle *intr_handle);
740 * This API returns the Windows handle of the given interrupt instance.
743 * pointer to the interrupt handle.
746 * - On success, Windows handle.
747 * - On failure, NULL.
751 rte_intr_instance_windows_handle_get(struct rte_intr_handle *intr_handle);
755 * This API set the Windows handle for the given interrupt instance.
758 * pointer to the interrupt handle.
759 * @param windows_handle
760 * Windows handle to be set.
764 * - On failure, a negative value and rte_errno is set.
768 rte_intr_instance_windows_handle_set(struct rte_intr_handle *intr_handle,
769 void *windows_handle);