New upstream version 17.11.1
[deb_dpdk.git] / lib / librte_eal / common / include / rte_eal.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 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_EAL_H_
35 #define _RTE_EAL_H_
36
37 /**
38  * @file
39  *
40  * EAL Configuration API
41  */
42
43 #include <stdint.h>
44 #include <sched.h>
45
46 #include <rte_config.h>
47 #include <rte_per_lcore.h>
48 #include <rte_bus.h>
49
50 #include <rte_pci_dev_feature_defs.h>
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
57
58 /* Maximum thread_name length. */
59 #define RTE_MAX_THREAD_NAME_LEN 16
60
61 /**
62  * The lcore role (used in RTE or not).
63  */
64 enum rte_lcore_role_t {
65         ROLE_RTE,
66         ROLE_OFF,
67         ROLE_SERVICE,
68 };
69
70 /**
71  * The type of process in a linuxapp, multi-process setup
72  */
73 enum rte_proc_type_t {
74         RTE_PROC_AUTO = -1,   /* allow auto-detection of primary/secondary */
75         RTE_PROC_PRIMARY = 0, /* set to zero, so primary is the default */
76         RTE_PROC_SECONDARY,
77
78         RTE_PROC_INVALID
79 };
80
81 /**
82  * The global RTE configuration structure.
83  */
84 struct rte_config {
85         uint32_t master_lcore;       /**< Id of the master lcore */
86         uint32_t lcore_count;        /**< Number of available logical cores. */
87         uint32_t service_lcore_count;/**< Number of available service cores. */
88         enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
89
90         /** Primary or secondary configuration */
91         enum rte_proc_type_t process_type;
92
93         /** PA or VA mapping mode */
94         enum rte_iova_mode iova_mode;
95
96         /**
97          * Pointer to memory configuration, which may be shared across multiple
98          * DPDK instances
99          */
100         struct rte_mem_config *mem_config;
101 } __attribute__((__packed__));
102
103 /**
104  * Get the global configuration structure.
105  *
106  * @return
107  *   A pointer to the global configuration structure.
108  */
109 struct rte_config *rte_eal_get_configuration(void);
110
111 /**
112  * Get a lcore's role.
113  *
114  * @param lcore_id
115  *   The identifier of the lcore.
116  * @return
117  *   The role of the lcore.
118  */
119 enum rte_lcore_role_t rte_eal_lcore_role(unsigned lcore_id);
120
121
122 /**
123  * Get the process type in a multi-process setup
124  *
125  * @return
126  *   The process type
127  */
128 enum rte_proc_type_t rte_eal_process_type(void);
129
130 /**
131  * Request iopl privilege for all RPL.
132  *
133  * This function should be called by pmds which need access to ioports.
134
135  * @return
136  *   - On success, returns 0.
137  *   - On failure, returns -1.
138  */
139 int rte_eal_iopl_init(void);
140
141 /**
142  * Initialize the Environment Abstraction Layer (EAL).
143  *
144  * This function is to be executed on the MASTER lcore only, as soon
145  * as possible in the application's main() function.
146  *
147  * The function finishes the initialization process before main() is called.
148  * It puts the SLAVE lcores in the WAIT state.
149  *
150  * When the multi-partition feature is supported, depending on the
151  * configuration (if CONFIG_RTE_EAL_MAIN_PARTITION is disabled), this
152  * function waits to ensure that the magic number is set before
153  * returning. See also the rte_eal_get_configuration() function. Note:
154  * This behavior may change in the future.
155  *
156  * @param argc
157  *   A non-negative value.  If it is greater than 0, the array members
158  *   for argv[0] through argv[argc] (non-inclusive) shall contain pointers
159  *   to strings.
160  * @param argv
161  *   An array of strings.  The contents of the array, as well as the strings
162  *   which are pointed to by the array, may be modified by this function.
163  * @return
164  *   - On success, the number of parsed arguments, which is greater or
165  *     equal to zero. After the call to rte_eal_init(),
166  *     all arguments argv[x] with x < ret may have been modified by this
167  *     function call and should not be further interpreted by the
168  *     application.  The EAL does not take any ownership of the memory used
169  *     for either the argv array, or its members.
170  *   - On failure, -1 and rte_errno is set to a value indicating the cause
171  *     for failure.  In some instances, the application will need to be
172  *     restarted as part of clearing the issue.
173  *
174  *   Error codes returned via rte_errno:
175  *     EACCES indicates a permissions issue.
176  *
177  *     EAGAIN indicates either a bus or system resource was not available,
178  *            setup may be attempted again.
179  *
180  *     EALREADY indicates that the rte_eal_init function has already been
181  *              called, and cannot be called again.
182  *
183  *     EFAULT indicates the tailq configuration name was not found in
184  *            memory configuration.
185  *
186  *     EINVAL indicates invalid parameters were passed as argv/argc.
187  *
188  *     ENOMEM indicates failure likely caused by an out-of-memory condition.
189  *
190  *     ENODEV indicates memory setup issues.
191  *
192  *     ENOTSUP indicates that the EAL cannot initialize on this system.
193  *
194  *     EPROTO indicates that the PCI bus is either not present, or is not
195  *            readable by the eal.
196  *
197  *     ENOEXEC indicates that a service core failed to launch successfully.
198  */
199 int rte_eal_init(int argc, char **argv);
200
201 /**
202  * Check if a primary process is currently alive
203  *
204  * This function returns true when a primary process is currently
205  * active.
206  *
207  * @param config_file_path
208  *   The config_file_path argument provided should point at the location
209  *   that the primary process will create its config file. If NULL, the default
210  *   config file path is used.
211  *
212  * @return
213  *  - If alive, returns 1.
214  *  - If dead, returns 0.
215  */
216 int rte_eal_primary_proc_alive(const char *config_file_path);
217
218 /**
219  * Usage function typedef used by the application usage function.
220  *
221  * Use this function typedef to define and call rte_set_application_usage_hook()
222  * routine.
223  */
224 typedef void    (*rte_usage_hook_t)(const char * prgname);
225
226 /**
227  * Add application usage routine callout from the eal_usage() routine.
228  *
229  * This function allows the application to include its usage message
230  * in the EAL system usage message. The routine rte_set_application_usage_hook()
231  * needs to be called before the rte_eal_init() routine in the application.
232  *
233  * This routine is optional for the application and will behave as if the set
234  * routine was never called as the default behavior.
235  *
236  * @param usage_func
237  *   The func argument is a function pointer to the application usage routine.
238  *   Called function is defined using rte_usage_hook_t typedef, which is of
239  *   the form void rte_usage_func(const char * prgname).
240  *
241  *   Calling this routine with a NULL value will reset the usage hook routine and
242  *   return the current value, which could be NULL.
243  * @return
244  *   - Returns the current value of the rte_application_usage pointer to allow
245  *     the caller to daisy chain the usage routines if needing more then one.
246  */
247 rte_usage_hook_t
248 rte_set_application_usage_hook(rte_usage_hook_t usage_func);
249
250 /**
251  * macro to get the lock of tailq in mem_config
252  */
253 #define RTE_EAL_TAILQ_RWLOCK         (&rte_eal_get_configuration()->mem_config->qlock)
254
255 /**
256  * macro to get the multiple lock of mempool shared by mutiple-instance
257  */
258 #define RTE_EAL_MEMPOOL_RWLOCK            (&rte_eal_get_configuration()->mem_config->mplock)
259
260 /**
261  * Whether EAL is using huge pages (disabled by --no-huge option).
262  * The no-huge mode cannot be used with UIO poll-mode drivers like igb/ixgbe.
263  * It is useful for NIC drivers (e.g. librte_pmd_mlx4, librte_pmd_vmxnet3) or
264  * crypto drivers (e.g. librte_crypto_nitrox) provided by third-parties such
265  * as 6WIND.
266  *
267  * @return
268  *   Nonzero if hugepages are enabled.
269  */
270 int rte_eal_has_hugepages(void);
271
272 /**
273  * Whether EAL is using PCI bus.
274  * Disabled by --no-pci option.
275  *
276  * @return
277  *   Nonzero if the PCI bus is enabled.
278  */
279 int rte_eal_has_pci(void);
280
281 /**
282  * Whether the EAL was asked to create UIO device.
283  *
284  * @return
285  *   Nonzero if true.
286  */
287 int rte_eal_create_uio_dev(void);
288
289 /**
290  * The user-configured vfio interrupt mode.
291  *
292  * @return
293  *   Interrupt mode configured with the command line,
294  *   RTE_INTR_MODE_NONE by default.
295  */
296 enum rte_intr_mode rte_eal_vfio_intr_mode(void);
297
298 /**
299  * A wrap API for syscall gettid.
300  *
301  * @return
302  *   On success, returns the thread ID of calling process.
303  *   It is always successful.
304  */
305 int rte_sys_gettid(void);
306
307 /**
308  * Get system unique thread id.
309  *
310  * @return
311  *   On success, returns the thread ID of calling process.
312  *   It is always successful.
313  */
314 static inline int rte_gettid(void)
315 {
316         static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;
317         if (RTE_PER_LCORE(_thread_id) == -1)
318                 RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
319         return RTE_PER_LCORE(_thread_id);
320 }
321
322 /**
323  * Get the iova mode
324  *
325  * @return
326  *   enum rte_iova_mode value.
327  */
328 enum rte_iova_mode rte_eal_iova_mode(void);
329
330 /**
331  * Get default pool ops name for mbuf
332  *
333  * @return
334  *   returns default pool ops name.
335  */
336 const char *
337 rte_eal_mbuf_default_mempool_ops(void);
338
339 #ifdef __cplusplus
340 }
341 #endif
342
343 #endif /* _RTE_EAL_H_ */