New upstream version 17.08
[deb_dpdk.git] / lib / librte_eal / common / include / rte_eal_interrupts.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_INTERRUPTS_H_
35 #error "don't include this file directly, please include generic <rte_interrupts.h>"
36 #endif
37
38 /**
39  * @file rte_eal_interrupts.h
40  * @internal
41  *
42  * Contains function prototypes exposed by the EAL for interrupt handling by
43  * drivers and other DPDK internal consumers.
44  */
45
46 #ifndef _RTE_EAL_INTERRUPTS_H_
47 #define _RTE_EAL_INTERRUPTS_H_
48
49 #define RTE_MAX_RXTX_INTR_VEC_ID     32
50 #define RTE_INTR_VEC_ZERO_OFFSET      0
51 #define RTE_INTR_VEC_RXTX_OFFSET      1
52
53 /**
54  * The interrupt source type, e.g. UIO, VFIO, ALARM etc.
55  */
56 enum rte_intr_handle_type {
57         RTE_INTR_HANDLE_UNKNOWN = 0,  /**< generic unknown handle */
58         RTE_INTR_HANDLE_UIO,          /**< uio device handle */
59         RTE_INTR_HANDLE_UIO_INTX,     /**< uio generic handle */
60         RTE_INTR_HANDLE_VFIO_LEGACY,  /**< vfio device handle (legacy) */
61         RTE_INTR_HANDLE_VFIO_MSI,     /**< vfio device handle (MSI) */
62         RTE_INTR_HANDLE_VFIO_MSIX,    /**< vfio device handle (MSIX) */
63         RTE_INTR_HANDLE_ALARM,        /**< alarm handle */
64         RTE_INTR_HANDLE_EXT,          /**< external handler */
65         RTE_INTR_HANDLE_VDEV,         /**< virtual device */
66         RTE_INTR_HANDLE_MAX           /**< count of elements */
67 };
68
69 #define RTE_INTR_EVENT_ADD            1UL
70 #define RTE_INTR_EVENT_DEL            2UL
71
72 typedef void (*rte_intr_event_cb_t)(int fd, void *arg);
73
74 struct rte_epoll_data {
75         uint32_t event;               /**< event type */
76         void *data;                   /**< User data */
77         rte_intr_event_cb_t cb_fun;   /**< IN: callback fun */
78         void *cb_arg;                 /**< IN: callback arg */
79 };
80
81 enum {
82         RTE_EPOLL_INVALID = 0,
83         RTE_EPOLL_VALID,
84         RTE_EPOLL_EXEC,
85 };
86
87 /** interrupt epoll event obj, taken by epoll_event.ptr */
88 struct rte_epoll_event {
89         volatile uint32_t status;  /**< OUT: event status */
90         int fd;                    /**< OUT: event fd */
91         int epfd;       /**< OUT: epoll instance the ev associated with */
92         struct rte_epoll_data epdata;
93 };
94
95 /** Handle for interrupts. */
96 struct rte_intr_handle {
97         RTE_STD_C11
98         union {
99                 int vfio_dev_fd;  /**< VFIO device file descriptor */
100                 int uio_cfg_fd;  /**< UIO cfg file desc for uio_pci_generic */
101         };
102         int fd;  /**< interrupt event file descriptor */
103         enum rte_intr_handle_type type;  /**< handle type */
104         uint32_t max_intr;             /**< max interrupt requested */
105         uint32_t nb_efd;               /**< number of available efd(event fd) */
106         uint8_t efd_counter_size;      /**< size of efd counter, used for vdev */
107         int efds[RTE_MAX_RXTX_INTR_VEC_ID];  /**< intr vectors/efds mapping */
108         struct rte_epoll_event elist[RTE_MAX_RXTX_INTR_VEC_ID];
109                                        /**< intr vector epoll event */
110         int *intr_vec;                 /**< intr vector number array */
111 };
112
113 #define RTE_EPOLL_PER_THREAD        -1  /**< to hint using per thread epfd */
114
115 /**
116  * It waits for events on the epoll instance.
117  *
118  * @param epfd
119  *   Epoll instance fd on which the caller wait for events.
120  * @param events
121  *   Memory area contains the events that will be available for the caller.
122  * @param maxevents
123  *   Up to maxevents are returned, must greater than zero.
124  * @param timeout
125  *   Specifying a timeout of -1 causes a block indefinitely.
126  *   Specifying a timeout equal to zero cause to return immediately.
127  * @return
128  *   - On success, returns the number of available event.
129  *   - On failure, a negative value.
130  */
131 int
132 rte_epoll_wait(int epfd, struct rte_epoll_event *events,
133                int maxevents, int timeout);
134
135 /**
136  * It performs control operations on epoll instance referred by the epfd.
137  * It requests that the operation op be performed for the target fd.
138  *
139  * @param epfd
140  *   Epoll instance fd on which the caller perform control operations.
141  * @param op
142  *   The operation be performed for the target fd.
143  * @param fd
144  *   The target fd on which the control ops perform.
145  * @param event
146  *   Describes the object linked to the fd.
147  *   Note: The caller must take care the object deletion after CTL_DEL.
148  * @return
149  *   - On success, zero.
150  *   - On failure, a negative value.
151  */
152 int
153 rte_epoll_ctl(int epfd, int op, int fd,
154               struct rte_epoll_event *event);
155
156 /**
157  * The function returns the per thread epoll instance.
158  *
159  * @return
160  *   epfd the epoll instance referred to.
161  */
162 int
163 rte_intr_tls_epfd(void);
164
165 /**
166  * @param intr_handle
167  *   Pointer to the interrupt handle.
168  * @param epfd
169  *   Epoll instance fd which the intr vector associated to.
170  * @param op
171  *   The operation be performed for the vector.
172  *   Operation type of {ADD, DEL}.
173  * @param vec
174  *   RX intr vector number added to the epoll instance wait list.
175  * @param data
176  *   User raw data.
177  * @return
178  *   - On success, zero.
179  *   - On failure, a negative value.
180  */
181 int
182 rte_intr_rx_ctl(struct rte_intr_handle *intr_handle,
183                 int epfd, int op, unsigned int vec, void *data);
184
185 /**
186  * It deletes registered eventfds.
187  *
188  * @param intr_handle
189  *   Pointer to the interrupt handle.
190  */
191 void
192 rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle);
193
194 /**
195  * It enables the packet I/O interrupt event if it's necessary.
196  * It creates event fd for each interrupt vector when MSIX is used,
197  * otherwise it multiplexes a single event fd.
198  *
199  * @param intr_handle
200  *   Pointer to the interrupt handle.
201  * @param nb_efd
202  *   Number of interrupt vector trying to enable.
203  *   The value 0 is not allowed.
204  * @return
205  *   - On success, zero.
206  *   - On failure, a negative value.
207  */
208 int
209 rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd);
210
211 /**
212  * It disables the packet I/O interrupt event.
213  * It deletes registered eventfds and closes the open fds.
214  *
215  * @param intr_handle
216  *   Pointer to the interrupt handle.
217  */
218 void
219 rte_intr_efd_disable(struct rte_intr_handle *intr_handle);
220
221 /**
222  * The packet I/O interrupt on datapath is enabled or not.
223  *
224  * @param intr_handle
225  *   Pointer to the interrupt handle.
226  */
227 int
228 rte_intr_dp_is_en(struct rte_intr_handle *intr_handle);
229
230 /**
231  * The interrupt handle instance allows other causes or not.
232  * Other causes stand for any none packet I/O interrupts.
233  *
234  * @param intr_handle
235  *   Pointer to the interrupt handle.
236  */
237 int
238 rte_intr_allow_others(struct rte_intr_handle *intr_handle);
239
240 /**
241  * The multiple interrupt vector capability of interrupt handle instance.
242  * It returns zero if no multiple interrupt vector support.
243  *
244  * @param intr_handle
245  *   Pointer to the interrupt handle.
246  */
247 int
248 rte_intr_cap_multiple(struct rte_intr_handle *intr_handle);
249
250 #endif /* _RTE_EAL_INTERRUPTS_H_ */