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