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