00bcc19b6de321515b8887a053d21796441075c9
[dpdk.git] / lib / eal / include / rte_eal_interrupts.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef _RTE_INTERRUPTS_H_
6 #error "don't include this file directly, please include generic <rte_interrupts.h>"
7 #endif
8
9 /**
10  * @file rte_eal_interrupts.h
11  * @internal
12  *
13  * Contains function prototypes exposed by the EAL for interrupt handling by
14  * drivers and other DPDK internal consumers.
15  */
16
17 #ifndef _RTE_EAL_INTERRUPTS_H_
18 #define _RTE_EAL_INTERRUPTS_H_
19
20 #define RTE_MAX_RXTX_INTR_VEC_ID      512
21 #define RTE_INTR_VEC_ZERO_OFFSET      0
22 #define RTE_INTR_VEC_RXTX_OFFSET      1
23
24 /**
25  * The interrupt source type, e.g. UIO, VFIO, ALARM etc.
26  */
27 enum rte_intr_handle_type {
28         RTE_INTR_HANDLE_UNKNOWN = 0,  /**< generic unknown handle */
29         RTE_INTR_HANDLE_UIO,          /**< uio device handle */
30         RTE_INTR_HANDLE_UIO_INTX,     /**< uio generic handle */
31         RTE_INTR_HANDLE_VFIO_LEGACY,  /**< vfio device handle (legacy) */
32         RTE_INTR_HANDLE_VFIO_MSI,     /**< vfio device handle (MSI) */
33         RTE_INTR_HANDLE_VFIO_MSIX,    /**< vfio device handle (MSIX) */
34         RTE_INTR_HANDLE_ALARM,        /**< alarm handle */
35         RTE_INTR_HANDLE_EXT,          /**< external handler */
36         RTE_INTR_HANDLE_VDEV,         /**< virtual device */
37         RTE_INTR_HANDLE_DEV_EVENT,    /**< device event handle */
38         RTE_INTR_HANDLE_VFIO_REQ,     /**< VFIO request handle */
39         RTE_INTR_HANDLE_MAX           /**< count of elements */
40 };
41
42 #define RTE_INTR_EVENT_ADD            1UL
43 #define RTE_INTR_EVENT_DEL            2UL
44
45 typedef void (*rte_intr_event_cb_t)(int fd, void *arg);
46
47 struct rte_epoll_data {
48         uint32_t event;               /**< event type */
49         void *data;                   /**< User data */
50         rte_intr_event_cb_t cb_fun;   /**< IN: callback fun */
51         void *cb_arg;                 /**< IN: callback arg */
52 };
53
54 enum {
55         RTE_EPOLL_INVALID = 0,
56         RTE_EPOLL_VALID,
57         RTE_EPOLL_EXEC,
58 };
59
60 /** interrupt epoll event obj, taken by epoll_event.ptr */
61 struct rte_epoll_event {
62         uint32_t status;           /**< OUT: event status */
63         int fd;                    /**< OUT: event fd */
64         int epfd;       /**< OUT: epoll instance the ev associated with */
65         struct rte_epoll_data epdata;
66 };
67
68 /** Handle for interrupts. */
69 struct rte_intr_handle {
70         RTE_STD_C11
71         union {
72                 struct {
73                         RTE_STD_C11
74                         union {
75                                 /** VFIO device file descriptor */
76                                 int vfio_dev_fd;
77                                 /** UIO cfg file desc for uio_pci_generic */
78                                 int uio_cfg_fd;
79                         };
80                         int fd; /**< interrupt event file descriptor */
81                 };
82                 void *handle; /**< device driver handle (Windows) */
83         };
84         enum rte_intr_handle_type type;  /**< handle type */
85         uint32_t max_intr;             /**< max interrupt requested */
86         uint32_t nb_efd;               /**< number of available efd(event fd) */
87         uint8_t efd_counter_size;      /**< size of efd counter, used for vdev */
88         int efds[RTE_MAX_RXTX_INTR_VEC_ID];  /**< intr vectors/efds mapping */
89         struct rte_epoll_event elist[RTE_MAX_RXTX_INTR_VEC_ID];
90                                        /**< intr vector epoll event */
91         int *intr_vec;                 /**< intr vector number array */
92 };
93
94 #define RTE_EPOLL_PER_THREAD        -1  /**< to hint using per thread epfd */
95
96 /**
97  * It waits for events on the epoll instance.
98  * Retries if signal received.
99  *
100  * @param epfd
101  *   Epoll instance fd on which the caller wait for events.
102  * @param events
103  *   Memory area contains the events that will be available for the caller.
104  * @param maxevents
105  *   Up to maxevents are returned, must greater than zero.
106  * @param timeout
107  *   Specifying a timeout of -1 causes a block indefinitely.
108  *   Specifying a timeout equal to zero cause to return immediately.
109  * @return
110  *   - On success, returns the number of available event.
111  *   - On failure, a negative value.
112  */
113 int
114 rte_epoll_wait(int epfd, struct rte_epoll_event *events,
115                int maxevents, int timeout);
116
117 /**
118  * It waits for events on the epoll instance.
119  * Does not retry if signal received.
120  *
121  * @param epfd
122  *   Epoll instance fd on which the caller wait for events.
123  * @param events
124  *   Memory area contains the events that will be available for the caller.
125  * @param maxevents
126  *   Up to maxevents are returned, must greater than zero.
127  * @param timeout
128  *   Specifying a timeout of -1 causes a block indefinitely.
129  *   Specifying a timeout equal to zero cause to return immediately.
130  * @return
131  *   - On success, returns the number of available event.
132  *   - On failure, a negative value.
133  */
134 __rte_experimental
135 int
136 rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events,
137                int maxevents, int timeout);
138
139 /**
140  * It performs control operations on epoll instance referred by the epfd.
141  * It requests that the operation op be performed for the target fd.
142  *
143  * @param epfd
144  *   Epoll instance fd on which the caller perform control operations.
145  * @param op
146  *   The operation be performed for the target fd.
147  * @param fd
148  *   The target fd on which the control ops perform.
149  * @param event
150  *   Describes the object linked to the fd.
151  *   Note: The caller must take care the object deletion after CTL_DEL.
152  * @return
153  *   - On success, zero.
154  *   - On failure, a negative value.
155  */
156 int
157 rte_epoll_ctl(int epfd, int op, int fd,
158               struct rte_epoll_event *event);
159
160 /**
161  * The function returns the per thread epoll instance.
162  *
163  * @return
164  *   epfd the epoll instance referred to.
165  */
166 int
167 rte_intr_tls_epfd(void);
168
169 /**
170  * @param intr_handle
171  *   Pointer to the interrupt handle.
172  * @param epfd
173  *   Epoll instance fd which the intr vector associated to.
174  * @param op
175  *   The operation be performed for the vector.
176  *   Operation type of {ADD, DEL}.
177  * @param vec
178  *   RX intr vector number added to the epoll instance wait list.
179  * @param data
180  *   User raw data.
181  * @return
182  *   - On success, zero.
183  *   - On failure, a negative value.
184  */
185 int
186 rte_intr_rx_ctl(struct rte_intr_handle *intr_handle,
187                 int epfd, int op, unsigned int vec, void *data);
188
189 /**
190  * It deletes registered eventfds.
191  *
192  * @param intr_handle
193  *   Pointer to the interrupt handle.
194  */
195 void
196 rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle);
197
198 /**
199  * It enables the packet I/O interrupt event if it's necessary.
200  * It creates event fd for each interrupt vector when MSIX is used,
201  * otherwise it multiplexes a single event fd.
202  *
203  * @param intr_handle
204  *   Pointer to the interrupt handle.
205  * @param nb_efd
206  *   Number of interrupt vector trying to enable.
207  *   The value 0 is not allowed.
208  * @return
209  *   - On success, zero.
210  *   - On failure, a negative value.
211  */
212 int
213 rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd);
214
215 /**
216  * It disables the packet I/O interrupt event.
217  * It deletes registered eventfds and closes the open fds.
218  *
219  * @param intr_handle
220  *   Pointer to the interrupt handle.
221  */
222 void
223 rte_intr_efd_disable(struct rte_intr_handle *intr_handle);
224
225 /**
226  * The packet I/O interrupt on datapath is enabled or not.
227  *
228  * @param intr_handle
229  *   Pointer to the interrupt handle.
230  */
231 int
232 rte_intr_dp_is_en(struct rte_intr_handle *intr_handle);
233
234 /**
235  * The interrupt handle instance allows other causes or not.
236  * Other causes stand for any none packet I/O interrupts.
237  *
238  * @param intr_handle
239  *   Pointer to the interrupt handle.
240  */
241 int
242 rte_intr_allow_others(struct rte_intr_handle *intr_handle);
243
244 /**
245  * The multiple interrupt vector capability of interrupt handle instance.
246  * It returns zero if no multiple interrupt vector support.
247  *
248  * @param intr_handle
249  *   Pointer to the interrupt handle.
250  */
251 int
252 rte_intr_cap_multiple(struct rte_intr_handle *intr_handle);
253
254 /**
255  * @warning
256  * @b EXPERIMENTAL: this API may change without prior notice
257  *
258  * @internal
259  * Check if currently executing in interrupt context
260  *
261  * @return
262  *  - non zero in case of interrupt context
263  *  - zero in case of process context
264  */
265 __rte_experimental
266 int
267 rte_thread_is_intr(void);
268
269 #endif /* _RTE_EAL_INTERRUPTS_H_ */