eal: simplify meson build of common directory
[dpdk.git] / lib / librte_eal / common / include / rte_eal.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 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 #include <time.h>
17
18 #include <rte_config.h>
19 #include <rte_compat.h>
20 #include <rte_per_lcore.h>
21 #include <rte_bus.h>
22
23 #include <rte_pci_dev_feature_defs.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
30
31 /* Maximum thread_name length. */
32 #define RTE_MAX_THREAD_NAME_LEN 16
33
34 /**
35  * The lcore role (used in RTE or not).
36  */
37 enum rte_lcore_role_t {
38         ROLE_RTE,
39         ROLE_OFF,
40         ROLE_SERVICE,
41 };
42
43 /**
44  * The type of process in a linux, multi-process setup
45  */
46 enum rte_proc_type_t {
47         RTE_PROC_AUTO = -1,   /* allow auto-detection of primary/secondary */
48         RTE_PROC_PRIMARY = 0, /* set to zero, so primary is the default */
49         RTE_PROC_SECONDARY,
50
51         RTE_PROC_INVALID
52 };
53
54 /**
55  * Get the process type in a multi-process setup
56  *
57  * @return
58  *   The process type
59  */
60 enum rte_proc_type_t rte_eal_process_type(void);
61
62 /**
63  * Request iopl privilege for all RPL.
64  *
65  * This function should be called by pmds which need access to ioports.
66
67  * @return
68  *   - On success, returns 0.
69  *   - On failure, returns -1.
70  */
71 int rte_eal_iopl_init(void);
72
73 /**
74  * Initialize the Environment Abstraction Layer (EAL).
75  *
76  * This function is to be executed on the MASTER lcore only, as soon
77  * as possible in the application's main() function.
78  *
79  * The function finishes the initialization process before main() is called.
80  * It puts the SLAVE lcores in the WAIT state.
81  *
82  * When the multi-partition feature is supported, depending on the
83  * configuration (if CONFIG_RTE_EAL_MAIN_PARTITION is disabled), this
84  * function waits to ensure that the magic number is set before
85  * returning. See also the rte_eal_get_configuration() function. Note:
86  * This behavior may change in the future.
87  *
88  * @param argc
89  *   A non-negative value.  If it is greater than 0, the array members
90  *   for argv[0] through argv[argc] (non-inclusive) shall contain pointers
91  *   to strings.
92  * @param argv
93  *   An array of strings.  The contents of the array, as well as the strings
94  *   which are pointed to by the array, may be modified by this function.
95  * @return
96  *   - On success, the number of parsed arguments, which is greater or
97  *     equal to zero. After the call to rte_eal_init(),
98  *     all arguments argv[x] with x < ret may have been modified by this
99  *     function call and should not be further interpreted by the
100  *     application.  The EAL does not take any ownership of the memory used
101  *     for either the argv array, or its members.
102  *   - On failure, -1 and rte_errno is set to a value indicating the cause
103  *     for failure.  In some instances, the application will need to be
104  *     restarted as part of clearing the issue.
105  *
106  *   Error codes returned via rte_errno:
107  *     EACCES indicates a permissions issue.
108  *
109  *     EAGAIN indicates either a bus or system resource was not available,
110  *            setup may be attempted again.
111  *
112  *     EALREADY indicates that the rte_eal_init function has already been
113  *              called, and cannot be called again.
114  *
115  *     EFAULT indicates the tailq configuration name was not found in
116  *            memory configuration.
117  *
118  *     EINVAL indicates invalid parameters were passed as argv/argc.
119  *
120  *     ENOMEM indicates failure likely caused by an out-of-memory condition.
121  *
122  *     ENODEV indicates memory setup issues.
123  *
124  *     ENOTSUP indicates that the EAL cannot initialize on this system.
125  *
126  *     EPROTO indicates that the PCI bus is either not present, or is not
127  *            readable by the eal.
128  *
129  *     ENOEXEC indicates that a service core failed to launch successfully.
130  */
131 int rte_eal_init(int argc, char **argv);
132
133 /**
134  * Clean up the Environment Abstraction Layer (EAL)
135  *
136  * This function must be called to release any internal resources that EAL has
137  * allocated during rte_eal_init(). After this call, no DPDK function calls may
138  * be made. It is expected that common usage of this function is to call it
139  * just before terminating the process.
140  *
141  * @return 0 Successfully released all internal EAL resources
142  * @return -EFAULT There was an error in releasing all resources.
143  */
144 int rte_eal_cleanup(void);
145
146 /**
147  * Check if a primary process is currently alive
148  *
149  * This function returns true when a primary process is currently
150  * active.
151  *
152  * @param config_file_path
153  *   The config_file_path argument provided should point at the location
154  *   that the primary process will create its config file. If NULL, the default
155  *   config file path is used.
156  *
157  * @return
158  *  - If alive, returns 1.
159  *  - If dead, returns 0.
160  */
161 int rte_eal_primary_proc_alive(const char *config_file_path);
162
163 #define RTE_MP_MAX_FD_NUM       8    /* The max amount of fds */
164 #define RTE_MP_MAX_NAME_LEN     64   /* The max length of action name */
165 #define RTE_MP_MAX_PARAM_LEN    256  /* The max length of param */
166 struct rte_mp_msg {
167         char name[RTE_MP_MAX_NAME_LEN];
168         int len_param;
169         int num_fds;
170         uint8_t param[RTE_MP_MAX_PARAM_LEN];
171         int fds[RTE_MP_MAX_FD_NUM];
172 };
173
174 struct rte_mp_reply {
175         int nb_sent;
176         int nb_received;
177         struct rte_mp_msg *msgs; /* caller to free */
178 };
179
180 /**
181  * Action function typedef used by other components.
182  *
183  * As we create  socket channel for primary/secondary communication, use
184  * this function typedef to register action for coming messages.
185  *
186  * @note When handling IPC request callbacks, the reply must be sent even in
187  *   cases of error handling. Simply returning success or failure will *not*
188  *   send a response to the requestor.
189  *   Implementation of error signalling mechanism is up to the application.
190  *
191  * @note No memory allocations should take place inside the callback.
192  */
193 typedef int (*rte_mp_t)(const struct rte_mp_msg *msg, const void *peer);
194
195 /**
196  * Asynchronous reply function typedef used by other components.
197  *
198  * As we create socket channel for primary/secondary communication, use
199  * this function typedef to register action for coming responses to asynchronous
200  * requests.
201  *
202  * @note When handling IPC request callbacks, the reply must be sent even in
203  *   cases of error handling. Simply returning success or failure will *not*
204  *   send a response to the requestor.
205  *   Implementation of error signalling mechanism is up to the application.
206  *
207  * @note No memory allocations should take place inside the callback.
208  */
209 typedef int (*rte_mp_async_reply_t)(const struct rte_mp_msg *request,
210                 const struct rte_mp_reply *reply);
211
212 /**
213  * @warning
214  * @b EXPERIMENTAL: this API may change without prior notice
215  *
216  * Register an action function for primary/secondary communication.
217  *
218  * Call this function to register an action, if the calling component wants
219  * to response the messages from the corresponding component in its primary
220  * process or secondary processes.
221  *
222  * @note IPC may be unsupported in certain circumstances, so caller should check
223  *    for ENOTSUP error.
224  *
225  * @param name
226  *   The name argument plays as the nonredundant key to find the action.
227  *
228  * @param action
229  *   The action argument is the function pointer to the action function.
230  *
231  * @return
232  *  - 0 on success.
233  *  - (<0) on failure.
234  */
235 __rte_experimental
236 int
237 rte_mp_action_register(const char *name, rte_mp_t action);
238
239 /**
240  * @warning
241  * @b EXPERIMENTAL: this API may change without prior notice
242  *
243  * Unregister an action function for primary/secondary communication.
244  *
245  * Call this function to unregister an action  if the calling component does
246  * not want to response the messages from the corresponding component in its
247  * primary process or secondary processes.
248  *
249  * @note IPC may be unsupported in certain circumstances, so caller should check
250  *    for ENOTSUP error.
251  *
252  * @param name
253  *   The name argument plays as the nonredundant key to find the action.
254  *
255  */
256 __rte_experimental
257 void
258 rte_mp_action_unregister(const char *name);
259
260 /**
261  * @warning
262  * @b EXPERIMENTAL: this API may change without prior notice
263  *
264  * Send a message to the peer process.
265  *
266  * This function will send a message which will be responded by the action
267  * identified by name in the peer process.
268  *
269  * @param msg
270  *   The msg argument contains the customized message.
271  *
272  * @return
273  *  - On success, return 0.
274  *  - On failure, return -1, and the reason will be stored in rte_errno.
275  */
276 __rte_experimental
277 int
278 rte_mp_sendmsg(struct rte_mp_msg *msg);
279
280 /**
281  * @warning
282  * @b EXPERIMENTAL: this API may change without prior notice
283  *
284  * Send a request to the peer process and expect a reply.
285  *
286  * This function sends a request message to the peer process, and will
287  * block until receiving reply message from the peer process.
288  *
289  * @note The caller is responsible to free reply->replies.
290  *
291  * @note This API must not be used inside memory-related or IPC callbacks, and
292  *   no memory allocations should take place inside such callback.
293  *
294  * @note IPC may be unsupported in certain circumstances, so caller should check
295  *    for ENOTSUP error.
296  *
297  * @param req
298  *   The req argument contains the customized request message.
299  *
300  * @param reply
301  *   The reply argument will be for storing all the replied messages;
302  *   the caller is responsible for free reply->msgs.
303  *
304  * @param ts
305  *   The ts argument specifies how long we can wait for the peer(s) to reply.
306  *
307  * @return
308  *  - On success, return 0.
309  *  - On failure, return -1, and the reason will be stored in rte_errno.
310  */
311 __rte_experimental
312 int
313 rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
314                const struct timespec *ts);
315
316 /**
317  * @warning
318  * @b EXPERIMENTAL: this API may change without prior notice
319  *
320  * Send a request to the peer process and expect a reply in a separate callback.
321  *
322  * This function sends a request message to the peer process, and will not
323  * block. Instead, reply will be received in a separate callback.
324  *
325  * @note IPC may be unsupported in certain circumstances, so caller should check
326  *    for ENOTSUP error.
327  *
328  * @param req
329  *   The req argument contains the customized request message.
330  *
331  * @param ts
332  *   The ts argument specifies how long we can wait for the peer(s) to reply.
333  *
334  * @param clb
335  *   The callback to trigger when all responses for this request have arrived.
336  *
337  * @return
338  *  - On success, return 0.
339  *  - On failure, return -1, and the reason will be stored in rte_errno.
340  */
341 __rte_experimental
342 int
343 rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
344                 rte_mp_async_reply_t clb);
345
346 /**
347  * @warning
348  * @b EXPERIMENTAL: this API may change without prior notice
349  *
350  * Send a reply to the peer process.
351  *
352  * This function will send a reply message in response to a request message
353  * received previously.
354  *
355  * @note When handling IPC request callbacks, the reply must be sent even in
356  *   cases of error handling. Simply returning success or failure will *not*
357  *   send a response to the requestor.
358  *   Implementation of error signalling mechanism is up to the application.
359  *
360  * @param msg
361  *   The msg argument contains the customized message.
362  *
363  * @param peer
364  *   The peer argument is the pointer to the peer socket path.
365  *
366  * @return
367  *  - On success, return 0.
368  *  - On failure, return -1, and the reason will be stored in rte_errno.
369  */
370 __rte_experimental
371 int
372 rte_mp_reply(struct rte_mp_msg *msg, const char *peer);
373
374 /**
375  * Usage function typedef used by the application usage function.
376  *
377  * Use this function typedef to define and call rte_set_application_usage_hook()
378  * routine.
379  */
380 typedef void    (*rte_usage_hook_t)(const char * prgname);
381
382 /**
383  * Add application usage routine callout from the eal_usage() routine.
384  *
385  * This function allows the application to include its usage message
386  * in the EAL system usage message. The routine rte_set_application_usage_hook()
387  * needs to be called before the rte_eal_init() routine in the application.
388  *
389  * This routine is optional for the application and will behave as if the set
390  * routine was never called as the default behavior.
391  *
392  * @param usage_func
393  *   The func argument is a function pointer to the application usage routine.
394  *   Called function is defined using rte_usage_hook_t typedef, which is of
395  *   the form void rte_usage_func(const char * prgname).
396  *
397  *   Calling this routine with a NULL value will reset the usage hook routine and
398  *   return the current value, which could be NULL.
399  * @return
400  *   - Returns the current value of the rte_application_usage pointer to allow
401  *     the caller to daisy chain the usage routines if needing more then one.
402  */
403 rte_usage_hook_t
404 rte_set_application_usage_hook(rte_usage_hook_t usage_func);
405
406 /**
407  * Whether EAL is using huge pages (disabled by --no-huge option).
408  * The no-huge mode is not compatible with all drivers or features.
409  *
410  * @return
411  *   Nonzero if hugepages are enabled.
412  */
413 int rte_eal_has_hugepages(void);
414
415 /**
416  * Whether EAL is using PCI bus.
417  * Disabled by --no-pci option.
418  *
419  * @return
420  *   Nonzero if the PCI bus is enabled.
421  */
422 int rte_eal_has_pci(void);
423
424 /**
425  * Whether the EAL was asked to create UIO device.
426  *
427  * @return
428  *   Nonzero if true.
429  */
430 int rte_eal_create_uio_dev(void);
431
432 /**
433  * The user-configured vfio interrupt mode.
434  *
435  * @return
436  *   Interrupt mode configured with the command line,
437  *   RTE_INTR_MODE_NONE by default.
438  */
439 enum rte_intr_mode rte_eal_vfio_intr_mode(void);
440
441 /**
442  * A wrap API for syscall gettid.
443  *
444  * @return
445  *   On success, returns the thread ID of calling process.
446  *   It is always successful.
447  */
448 int rte_sys_gettid(void);
449
450 /**
451  * Get system unique thread id.
452  *
453  * @return
454  *   On success, returns the thread ID of calling process.
455  *   It is always successful.
456  */
457 static inline int rte_gettid(void)
458 {
459         static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;
460         if (RTE_PER_LCORE(_thread_id) == -1)
461                 RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
462         return RTE_PER_LCORE(_thread_id);
463 }
464
465 /**
466  * Get the iova mode
467  *
468  * @return
469  *   enum rte_iova_mode value.
470  */
471 enum rte_iova_mode rte_eal_iova_mode(void);
472
473 /**
474  * Get user provided pool ops name for mbuf
475  *
476  * @return
477  *   returns user provided pool ops name.
478  */
479 const char *
480 rte_eal_mbuf_user_pool_ops(void);
481
482 /**
483  * Get the runtime directory of DPDK
484  *
485  * @return
486  *  The runtime directory path of DPDK
487  */
488 const char *
489 rte_eal_get_runtime_dir(void);
490
491 #ifdef __cplusplus
492 }
493 #endif
494
495 #endif /* _RTE_EAL_H_ */