New upstream version 18.02
[deb_dpdk.git] / lib / librte_eal / common / 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     32
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_MAX           /**< count of elements */
38 };
39
40 #define RTE_INTR_EVENT_ADD            1UL
41 #define RTE_INTR_EVENT_DEL            2UL
42
43 typedef void (*rte_intr_event_cb_t)(int fd, void *arg);
44
45 struct rte_epoll_data {
46         uint32_t event;               /**< event type */
47         void *data;                   /**< User data */
48         rte_intr_event_cb_t cb_fun;   /**< IN: callback fun */
49         void *cb_arg;                 /**< IN: callback arg */
50 };
51
52 enum {
53         RTE_EPOLL_INVALID = 0,
54         RTE_EPOLL_VALID,
55         RTE_EPOLL_EXEC,
56 };
57
58 /** interrupt epoll event obj, taken by epoll_event.ptr */
59 struct rte_epoll_event {
60         volatile uint32_t status;  /**< OUT: event status */
61         int fd;                    /**< OUT: event fd */
62         int epfd;       /**< OUT: epoll instance the ev associated with */
63         struct rte_epoll_data epdata;
64 };
65
66 /** Handle for interrupts. */
67 struct rte_intr_handle {
68         RTE_STD_C11
69         union {
70                 int vfio_dev_fd;  /**< VFIO device file descriptor */
71                 int uio_cfg_fd;  /**< UIO cfg file desc for uio_pci_generic */
72         };
73         int fd;  /**< interrupt event file descriptor */
74         enum rte_intr_handle_type type;  /**< handle type */
75         uint32_t max_intr;             /**< max interrupt requested */
76         uint32_t nb_efd;               /**< number of available efd(event fd) */
77         uint8_t efd_counter_size;      /**< size of efd counter, used for vdev */
78         int efds[RTE_MAX_RXTX_INTR_VEC_ID];  /**< intr vectors/efds mapping */
79         struct rte_epoll_event elist[RTE_MAX_RXTX_INTR_VEC_ID];
80                                        /**< intr vector epoll event */
81         int *intr_vec;                 /**< intr vector number array */
82 };
83
84 #define RTE_EPOLL_PER_THREAD        -1  /**< to hint using per thread epfd */
85
86 /**
87  * It waits for events on the epoll instance.
88  *
89  * @param epfd
90  *   Epoll instance fd on which the caller wait for events.
91  * @param events
92  *   Memory area contains the events that will be available for the caller.
93  * @param maxevents
94  *   Up to maxevents are returned, must greater than zero.
95  * @param timeout
96  *   Specifying a timeout of -1 causes a block indefinitely.
97  *   Specifying a timeout equal to zero cause to return immediately.
98  * @return
99  *   - On success, returns the number of available event.
100  *   - On failure, a negative value.
101  */
102 int
103 rte_epoll_wait(int epfd, struct rte_epoll_event *events,
104                int maxevents, int timeout);
105
106 /**
107  * It performs control operations on epoll instance referred by the epfd.
108  * It requests that the operation op be performed for the target fd.
109  *
110  * @param epfd
111  *   Epoll instance fd on which the caller perform control operations.
112  * @param op
113  *   The operation be performed for the target fd.
114  * @param fd
115  *   The target fd on which the control ops perform.
116  * @param event
117  *   Describes the object linked to the fd.
118  *   Note: The caller must take care the object deletion after CTL_DEL.
119  * @return
120  *   - On success, zero.
121  *   - On failure, a negative value.
122  */
123 int
124 rte_epoll_ctl(int epfd, int op, int fd,
125               struct rte_epoll_event *event);
126
127 /**
128  * The function returns the per thread epoll instance.
129  *
130  * @return
131  *   epfd the epoll instance referred to.
132  */
133 int
134 rte_intr_tls_epfd(void);
135
136 /**
137  * @param intr_handle
138  *   Pointer to the interrupt handle.
139  * @param epfd
140  *   Epoll instance fd which the intr vector associated to.
141  * @param op
142  *   The operation be performed for the vector.
143  *   Operation type of {ADD, DEL}.
144  * @param vec
145  *   RX intr vector number added to the epoll instance wait list.
146  * @param data
147  *   User raw data.
148  * @return
149  *   - On success, zero.
150  *   - On failure, a negative value.
151  */
152 int
153 rte_intr_rx_ctl(struct rte_intr_handle *intr_handle,
154                 int epfd, int op, unsigned int vec, void *data);
155
156 /**
157  * It deletes registered eventfds.
158  *
159  * @param intr_handle
160  *   Pointer to the interrupt handle.
161  */
162 void
163 rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle);
164
165 /**
166  * It enables the packet I/O interrupt event if it's necessary.
167  * It creates event fd for each interrupt vector when MSIX is used,
168  * otherwise it multiplexes a single event fd.
169  *
170  * @param intr_handle
171  *   Pointer to the interrupt handle.
172  * @param nb_efd
173  *   Number of interrupt vector trying to enable.
174  *   The value 0 is not allowed.
175  * @return
176  *   - On success, zero.
177  *   - On failure, a negative value.
178  */
179 int
180 rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd);
181
182 /**
183  * It disables the packet I/O interrupt event.
184  * It deletes registered eventfds and closes the open fds.
185  *
186  * @param intr_handle
187  *   Pointer to the interrupt handle.
188  */
189 void
190 rte_intr_efd_disable(struct rte_intr_handle *intr_handle);
191
192 /**
193  * The packet I/O interrupt on datapath is enabled or not.
194  *
195  * @param intr_handle
196  *   Pointer to the interrupt handle.
197  */
198 int
199 rte_intr_dp_is_en(struct rte_intr_handle *intr_handle);
200
201 /**
202  * The interrupt handle instance allows other causes or not.
203  * Other causes stand for any none packet I/O interrupts.
204  *
205  * @param intr_handle
206  *   Pointer to the interrupt handle.
207  */
208 int
209 rte_intr_allow_others(struct rte_intr_handle *intr_handle);
210
211 /**
212  * The multiple interrupt vector capability of interrupt handle instance.
213  * It returns zero if no multiple interrupt vector support.
214  *
215  * @param intr_handle
216  *   Pointer to the interrupt handle.
217  */
218 int
219 rte_intr_cap_multiple(struct rte_intr_handle *intr_handle);
220
221 #endif /* _RTE_EAL_INTERRUPTS_H_ */