net: add MPLS header structure
[dpdk.git] / app / test-eventdev / evt_common.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4
5 #ifndef _EVT_COMMON_
6 #define _EVT_COMMON_
7
8 #include <rte_common.h>
9 #include <rte_debug.h>
10 #include <rte_eventdev.h>
11 #include <rte_service.h>
12
13 #define CLNRM  "\x1b[0m"
14 #define CLRED  "\x1b[31m"
15 #define CLGRN  "\x1b[32m"
16 #define CLYEL  "\x1b[33m"
17
18 #define evt_err(fmt, args...) \
19         fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## args)
20
21 #define evt_info(fmt, args...) \
22         fprintf(stdout, CLYEL""fmt CLNRM "\n", ## args)
23
24 #define EVT_STR_FMT 20
25
26 #define evt_dump(str, fmt, val...) \
27         printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## val)
28
29 #define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str)
30
31 #define evt_dump_end printf("\b}\n")
32
33 #define EVT_MAX_STAGES           64
34 #define EVT_MAX_PORTS            256
35 #define EVT_MAX_QUEUES           256
36
37 static inline bool
38 evt_has_distributed_sched(uint8_t dev_id)
39 {
40         struct rte_event_dev_info dev_info;
41
42         rte_event_dev_info_get(dev_id, &dev_info);
43         return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) ?
44                         true : false;
45 }
46
47 static inline bool
48 evt_has_burst_mode(uint8_t dev_id)
49 {
50         struct rte_event_dev_info dev_info;
51
52         rte_event_dev_info_get(dev_id, &dev_info);
53         return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
54                         true : false;
55 }
56
57
58 static inline bool
59 evt_has_all_types_queue(uint8_t dev_id)
60 {
61         struct rte_event_dev_info dev_info;
62
63         rte_event_dev_info_get(dev_id, &dev_info);
64         return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES) ?
65                         true : false;
66 }
67
68 static inline int
69 evt_service_setup(uint32_t service_id)
70 {
71         int32_t core_cnt;
72         unsigned int lcore = 0;
73         uint32_t core_array[RTE_MAX_LCORE];
74         uint8_t cnt;
75         uint8_t min_cnt = UINT8_MAX;
76
77         if (!rte_service_lcore_count())
78                 return -ENOENT;
79
80         core_cnt = rte_service_lcore_list(core_array,
81                         RTE_MAX_LCORE);
82         if (core_cnt < 0)
83                 return -ENOENT;
84         /* Get the core which has least number of services running. */
85         while (core_cnt--) {
86                 /* Reset default mapping */
87                 rte_service_map_lcore_set(service_id,
88                                 core_array[core_cnt], 0);
89                 cnt = rte_service_lcore_count_services(
90                                 core_array[core_cnt]);
91                 if (cnt < min_cnt) {
92                         lcore = core_array[core_cnt];
93                         min_cnt = cnt;
94                 }
95         }
96         if (rte_service_map_lcore_set(service_id, lcore, 1))
97                 return -ENOENT;
98
99         return 0;
100 }
101
102 #endif /*  _EVT_COMMON_*/