raw/ifpga/base: fix SPI transaction
[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 MASTER 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 SLAVE 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 0 Successfully released all internal EAL resources
134  * @return -EFAULT There was an error in releasing all resources.
135  */
136 int rte_eal_cleanup(void);
137
138 /**
139  * Check if a primary process is currently alive
140  *
141  * This function returns true when a primary process is currently
142  * active.
143  *
144  * @param config_file_path
145  *   The config_file_path argument provided should point at the location
146  *   that the primary process will create its config file. If NULL, the default
147  *   config file path is used.
148  *
149  * @return
150  *  - If alive, returns 1.
151  *  - If dead, returns 0.
152  */
153 int rte_eal_primary_proc_alive(const char *config_file_path);
154
155 /**
156  * Disable multiprocess.
157  *
158  * This function can be called to indicate that multiprocess won't be used for
159  * the rest of the application life.
160  *
161  * @return
162  *   - true if called from a primary process that had no secondary processes
163  *     attached,
164  *   - false, otherwise.
165  */
166 __rte_experimental
167 bool rte_mp_disable(void);
168
169 #define RTE_MP_MAX_FD_NUM       8    /* The max amount of fds */
170 #define RTE_MP_MAX_NAME_LEN     64   /* The max length of action name */
171 #define RTE_MP_MAX_PARAM_LEN    256  /* The max length of param */
172 struct rte_mp_msg {
173         char name[RTE_MP_MAX_NAME_LEN];
174         int len_param;
175         int num_fds;
176         uint8_t param[RTE_MP_MAX_PARAM_LEN];
177         int fds[RTE_MP_MAX_FD_NUM];
178 };
179
180 struct rte_mp_reply {
181         int nb_sent;
182         int nb_received;
183         struct rte_mp_msg *msgs; /* caller to free */
184 };
185
186 /**
187  * Action function typedef used by other components.
188  *
189  * As we create  socket channel for primary/secondary communication, use
190  * this function typedef to register action for coming messages.
191  *
192  * @note When handling IPC request callbacks, the reply must be sent even in
193  *   cases of error handling. Simply returning success or failure will *not*
194  *   send a response to the requestor.
195  *   Implementation of error signalling mechanism is up to the application.
196  *
197  * @note No memory allocations should take place inside the callback.
198  */
199 typedef int (*rte_mp_t)(const struct rte_mp_msg *msg, const void *peer);
200
201 /**
202  * Asynchronous reply function typedef used by other components.
203  *
204  * As we create socket channel for primary/secondary communication, use
205  * this function typedef to register action for coming responses to asynchronous
206  * requests.
207  *
208  * @note When handling IPC request callbacks, the reply must be sent even in
209  *   cases of error handling. Simply returning success or failure will *not*
210  *   send a response to the requestor.
211  *   Implementation of error signalling mechanism is up to the application.
212  *
213  * @note No memory allocations should take place inside the callback.
214  */
215 typedef int (*rte_mp_async_reply_t)(const struct rte_mp_msg *request,
216                 const struct rte_mp_reply *reply);
217
218 /**
219  * @warning
220  * @b EXPERIMENTAL: this API may change without prior notice
221  *
222  * Register an action function for primary/secondary communication.
223  *
224  * Call this function to register an action, if the calling component wants
225  * to response the messages from the corresponding component in its primary
226  * process or secondary processes.
227  *
228  * @note IPC may be unsupported in certain circumstances, so caller should check
229  *    for ENOTSUP error.
230  *
231  * @param name
232  *   The name argument plays as the nonredundant key to find the action.
233  *
234  * @param action
235  *   The action argument is the function pointer to the action function.
236  *
237  * @return
238  *  - 0 on success.
239  *  - (<0) on failure.
240  */
241 __rte_experimental
242 int
243 rte_mp_action_register(const char *name, rte_mp_t action);
244
245 /**
246  * @warning
247  * @b EXPERIMENTAL: this API may change without prior notice
248  *
249  * Unregister an action function for primary/secondary communication.
250  *
251  * Call this function to unregister an action  if the calling component does
252  * not want to response the messages from the corresponding component in its
253  * primary process or secondary processes.
254  *
255  * @note IPC may be unsupported in certain circumstances, so caller should check
256  *    for ENOTSUP error.
257  *
258  * @param name
259  *   The name argument plays as the nonredundant key to find the action.
260  *
261  */
262 __rte_experimental
263 void
264 rte_mp_action_unregister(const char *name);
265
266 /**
267  * @warning
268  * @b EXPERIMENTAL: this API may change without prior notice
269  *
270  * Send a message to the peer process.
271  *
272  * This function will send a message which will be responded by the action
273  * identified by name in the peer process.
274  *
275  * @param msg
276  *   The msg argument contains the customized message.
277  *
278  * @return
279  *  - On success, return 0.
280  *  - On failure, return -1, and the reason will be stored in rte_errno.
281  */
282 __rte_experimental
283 int
284 rte_mp_sendmsg(struct rte_mp_msg *msg);
285
286 /**
287  * @warning
288  * @b EXPERIMENTAL: this API may change without prior notice
289  *
290  * Send a request to the peer process and expect a reply.
291  *
292  * This function sends a request message to the peer process, and will
293  * block until receiving reply message from the peer process.
294  *
295  * @note The caller is responsible to free reply->replies.
296  *
297  * @note This API must not be used inside memory-related or IPC callbacks, and
298  *   no memory allocations should take place inside such callback.
299  *
300  * @note IPC may be unsupported in certain circumstances, so caller should check
301  *    for ENOTSUP error.
302  *
303  * @param req
304  *   The req argument contains the customized request message.
305  *
306  * @param reply
307  *   The reply argument will be for storing all the replied messages;
308  *   the caller is responsible for free reply->msgs.
309  *
310  * @param ts
311  *   The ts argument specifies how long we can wait for the peer(s) to reply.
312  *
313  * @return
314  *  - On success, return 0.
315  *  - On failure, return -1, and the reason will be stored in rte_errno.
316  */
317 __rte_experimental
318 int
319 rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
320                const struct timespec *ts);
321
322 /**
323  * @warning
324  * @b EXPERIMENTAL: this API may change without prior notice
325  *
326  * Send a request to the peer process and expect a reply in a separate callback.
327  *
328  * This function sends a request message to the peer process, and will not
329  * block. Instead, reply will be received in a separate callback.
330  *
331  * @note IPC may be unsupported in certain circumstances, so caller should check
332  *    for ENOTSUP error.
333  *
334  * @param req
335  *   The req argument contains the customized request message.
336  *
337  * @param ts
338  *   The ts argument specifies how long we can wait for the peer(s) to reply.
339  *
340  * @param clb
341  *   The callback to trigger when all responses for this request have arrived.
342  *
343  * @return
344  *  - On success, return 0.
345  *  - On failure, return -1, and the reason will be stored in rte_errno.
346  */
347 __rte_experimental
348 int
349 rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
350                 rte_mp_async_reply_t clb);
351
352 /**
353  * @warning
354  * @b EXPERIMENTAL: this API may change without prior notice
355  *
356  * Send a reply to the peer process.
357  *
358  * This function will send a reply message in response to a request message
359  * received previously.
360  *
361  * @note When handling IPC request callbacks, the reply must be sent even in
362  *   cases of error handling. Simply returning success or failure will *not*
363  *   send a response to the requestor.
364  *   Implementation of error signalling mechanism is up to the application.
365  *
366  * @param msg
367  *   The msg argument contains the customized message.
368  *
369  * @param peer
370  *   The peer argument is the pointer to the peer socket path.
371  *
372  * @return
373  *  - On success, return 0.
374  *  - On failure, return -1, and the reason will be stored in rte_errno.
375  */
376 __rte_experimental
377 int
378 rte_mp_reply(struct rte_mp_msg *msg, const char *peer);
379
380 /**
381  * Usage function typedef used by the application usage function.
382  *
383  * Use this function typedef to define and call rte_set_application_usage_hook()
384  * routine.
385  */
386 typedef void    (*rte_usage_hook_t)(const char * prgname);
387
388 /**
389  * Add application usage routine callout from the eal_usage() routine.
390  *
391  * This function allows the application to include its usage message
392  * in the EAL system usage message. The routine rte_set_application_usage_hook()
393  * needs to be called before the rte_eal_init() routine in the application.
394  *
395  * This routine is optional for the application and will behave as if the set
396  * routine was never called as the default behavior.
397  *
398  * @param usage_func
399  *   The func argument is a function pointer to the application usage routine.
400  *   Called function is defined using rte_usage_hook_t typedef, which is of
401  *   the form void rte_usage_func(const char * prgname).
402  *
403  *   Calling this routine with a NULL value will reset the usage hook routine and
404  *   return the current value, which could be NULL.
405  * @return
406  *   - Returns the current value of the rte_application_usage pointer to allow
407  *     the caller to daisy chain the usage routines if needing more then one.
408  */
409 rte_usage_hook_t
410 rte_set_application_usage_hook(rte_usage_hook_t usage_func);
411
412 /**
413  * Whether EAL is using huge pages (disabled by --no-huge option).
414  * The no-huge mode is not compatible with all drivers or features.
415  *
416  * @return
417  *   Nonzero if hugepages are enabled.
418  */
419 int rte_eal_has_hugepages(void);
420
421 /**
422  * Whether EAL is using PCI bus.
423  * Disabled by --no-pci option.
424  *
425  * @return
426  *   Nonzero if the PCI bus is enabled.
427  */
428 int rte_eal_has_pci(void);
429
430 /**
431  * Whether the EAL was asked to create UIO device.
432  *
433  * @return
434  *   Nonzero if true.
435  */
436 int rte_eal_create_uio_dev(void);
437
438 /**
439  * The user-configured vfio interrupt mode.
440  *
441  * @return
442  *   Interrupt mode configured with the command line,
443  *   RTE_INTR_MODE_NONE by default.
444  */
445 enum rte_intr_mode rte_eal_vfio_intr_mode(void);
446
447 /**
448  * @warning
449  * @b EXPERIMENTAL: this API may change without prior notice
450  *
451  * Copy the user-configured vfio VF token.
452  *
453  * @param vf_token
454  *   vfio VF token configured with the command line is copied
455  *   into this parameter, zero uuid by default.
456  */
457 __rte_experimental
458 void rte_eal_vfio_get_vf_token(rte_uuid_t vf_token);
459
460 /**
461  * A wrap API for syscall gettid.
462  *
463  * @return
464  *   On success, returns the thread ID of calling process.
465  *   It is always successful.
466  */
467 int rte_sys_gettid(void);
468
469 RTE_DECLARE_PER_LCORE(int, _thread_id);
470
471 /**
472  * Get system unique thread id.
473  *
474  * @return
475  *   On success, returns the thread ID of calling process.
476  *   It is always successful.
477  */
478 static inline int rte_gettid(void)
479 {
480         if (RTE_PER_LCORE(_thread_id) == -1)
481                 RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
482         return RTE_PER_LCORE(_thread_id);
483 }
484
485 /**
486  * Get the iova mode
487  *
488  * @return
489  *   enum rte_iova_mode value.
490  */
491 enum rte_iova_mode rte_eal_iova_mode(void);
492
493 /**
494  * Get user provided pool ops name for mbuf
495  *
496  * @return
497  *   returns user provided pool ops name.
498  */
499 const char *
500 rte_eal_mbuf_user_pool_ops(void);
501
502 /**
503  * Get the runtime directory of DPDK
504  *
505  * @return
506  *  The runtime directory path of DPDK
507  */
508 const char *
509 rte_eal_get_runtime_dir(void);
510
511 #ifdef __cplusplus
512 }
513 #endif
514
515 #endif /* _RTE_EAL_H_ */