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