1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #ifndef _RTE_INTERRUPTS_H_ 6 #define _RTE_INTERRUPTS_H_ 7 8 #include <rte_common.h> 9 #include <rte_compat.h> 10 11 /** 12 * @file 13 * 14 * The RTE interrupt interface provides functions to register/unregister 15 * callbacks for a specific interrupt. 16 */ 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 /** Interrupt handle */ 23 struct rte_intr_handle; 24 25 /** Function to be registered for the specific interrupt */ 26 typedef void (*rte_intr_callback_fn)(void *cb_arg); 27 28 /** 29 * Function to call after a callback is unregistered. 30 * Can be used to close fd and free cb_arg. 31 */ 32 typedef void (*rte_intr_unregister_callback_fn)(struct rte_intr_handle *intr_handle, 33 void *cb_arg); 34 35 #include "rte_eal_interrupts.h" 36 37 /** 38 * It registers the callback for the specific interrupt. Multiple 39 * callbacks can be registered at the same time. 40 * @param intr_handle 41 * Pointer to the interrupt handle. 42 * @param cb 43 * callback address. 44 * @param cb_arg 45 * address of parameter for callback. 46 * 47 * @return 48 * - On success, zero. 49 * - On failure, a negative value. 50 */ 51 int rte_intr_callback_register(const struct rte_intr_handle *intr_handle, 52 rte_intr_callback_fn cb, void *cb_arg); 53 54 /** 55 * It unregisters the callback according to the specified interrupt handle. 56 * 57 * @param intr_handle 58 * pointer to the interrupt handle. 59 * @param cb 60 * callback address. 61 * @param cb_arg 62 * address of parameter for callback, (void *)-1 means to remove all 63 * registered which has the same callback address. 64 * 65 * @return 66 * - On success, return the number of callback entities removed. 67 * - On failure, a negative value. 68 */ 69 int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle, 70 rte_intr_callback_fn cb, void *cb_arg); 71 72 /** 73 * Unregister the callback according to the specified interrupt handle, 74 * after it's no longer active. Fail if source is not active. 75 * 76 * @param intr_handle 77 * pointer to the interrupt handle. 78 * @param cb_fn 79 * callback address. 80 * @param cb_arg 81 * address of parameter for callback, (void *)-1 means to remove all 82 * registered which has the same callback address. 83 * @param ucb_fn 84 * callback to call before cb is unregistered (optional). 85 * can be used to close fd and free cb_arg. 86 * 87 * @return 88 * - On success, return the number of callback entities marked for remove. 89 * - On failure, a negative value. 90 */ 91 __rte_experimental 92 int 93 rte_intr_callback_unregister_pending(const struct rte_intr_handle *intr_handle, 94 rte_intr_callback_fn cb_fn, void *cb_arg, 95 rte_intr_unregister_callback_fn ucb_fn); 96 97 /** 98 * @warning 99 * @b EXPERIMENTAL: this API may change without prior notice 100 * 101 * Loop until rte_intr_callback_unregister() succeeds. 102 * After a call to this function, 103 * the callback provided by the specified interrupt handle is unregistered. 104 * 105 * @param intr_handle 106 * pointer to the interrupt handle. 107 * @param cb 108 * callback address. 109 * @param cb_arg 110 * address of parameter for callback, (void *)-1 means to remove all 111 * registered which has the same callback address. 112 * 113 * @return 114 * - On success, return the number of callback entities removed. 115 * - On failure, a negative value. 116 */ 117 __rte_experimental 118 int 119 rte_intr_callback_unregister_sync(const struct rte_intr_handle *intr_handle, 120 rte_intr_callback_fn cb, void *cb_arg); 121 122 /** 123 * It enables the interrupt for the specified handle. 124 * 125 * @param intr_handle 126 * pointer to the interrupt handle. 127 * 128 * @return 129 * - On success, zero. 130 * - On failure, a negative value. 131 */ 132 int rte_intr_enable(const struct rte_intr_handle *intr_handle); 133 134 /** 135 * It disables the interrupt for the specified handle. 136 * 137 * @param intr_handle 138 * pointer to the interrupt handle. 139 * 140 * @return 141 * - On success, zero. 142 * - On failure, a negative value. 143 */ 144 int rte_intr_disable(const struct rte_intr_handle *intr_handle); 145 146 /** 147 * @warning 148 * @b EXPERIMENTAL: this API may change without prior notice 149 * 150 * It acknowledges an interrupt raised for the specified handle. 151 * 152 * This function should be called at the end of each interrupt handler either 153 * from application or driver, so that currently raised interrupt is acked and 154 * further new interrupts are raised. 155 * 156 * @param intr_handle 157 * pointer to the interrupt handle. 158 * 159 * @return 160 * - On success, zero. 161 * - On failure, a negative value. 162 */ 163 __rte_experimental 164 int rte_intr_ack(const struct rte_intr_handle *intr_handle); 165 166 #ifdef __cplusplus 167 } 168 #endif 169 170 #endif 171