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