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