41020760b1abccd6bbd091d16ebaa3fd5c2faca3
[deb_dpdk.git] / app / test-eventdev / evt_common.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _EVT_COMMON_
34 #define _EVT_COMMON_
35
36 #include <rte_common.h>
37 #include <rte_debug.h>
38 #include <rte_eventdev.h>
39
40 #define CLNRM  "\x1b[0m"
41 #define CLRED  "\x1b[31m"
42 #define CLGRN  "\x1b[32m"
43 #define CLYEL  "\x1b[33m"
44
45 #define evt_err(fmt, args...) \
46         fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## args)
47
48 #define evt_info(fmt, args...) \
49         fprintf(stdout, CLYEL""fmt CLNRM "\n", ## args)
50
51 #define EVT_STR_FMT 20
52
53 #define evt_dump(str, fmt, val...) \
54         printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## val)
55
56 #define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str)
57
58 #define evt_dump_end printf("\b}\n")
59
60 #define EVT_MAX_STAGES           64
61 #define EVT_MAX_PORTS            256
62 #define EVT_MAX_QUEUES           256
63
64 static inline bool
65 evt_has_distributed_sched(uint8_t dev_id)
66 {
67         struct rte_event_dev_info dev_info;
68
69         rte_event_dev_info_get(dev_id, &dev_info);
70         return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) ?
71                         true : false;
72 }
73
74 static inline bool
75 evt_has_burst_mode(uint8_t dev_id)
76 {
77         struct rte_event_dev_info dev_info;
78
79         rte_event_dev_info_get(dev_id, &dev_info);
80         return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
81                         true : false;
82 }
83
84
85 static inline bool
86 evt_has_all_types_queue(uint8_t dev_id)
87 {
88         struct rte_event_dev_info dev_info;
89
90         rte_event_dev_info_get(dev_id, &dev_info);
91         return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES) ?
92                         true : false;
93 }
94
95 static inline uint32_t
96 evt_sched_type2queue_cfg(uint8_t sched_type)
97 {
98         uint32_t ret;
99
100         switch (sched_type) {
101         case RTE_SCHED_TYPE_ATOMIC:
102                 ret = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY;
103                 break;
104         case RTE_SCHED_TYPE_ORDERED:
105                 ret = RTE_EVENT_QUEUE_CFG_ORDERED_ONLY;
106                 break;
107         case RTE_SCHED_TYPE_PARALLEL:
108                 ret = RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY;
109                 break;
110         default:
111                 rte_panic("Invalid sched_type %d\n", sched_type);
112         }
113         return ret;
114 }
115
116 #endif /*  _EVT_COMMON_*/