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