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