c9ab7bae81e666193e4fdb2dd2b8ed79f8d9ba80
[dpdk.git] / lib / librte_power / rte_power_guest_channel.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2021 Intel Corporation
3  */
4 #ifndef RTE_POWER_GUEST_CHANNEL_H
5 #define RTE_POWER_GUEST_CHANNEL_H
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 #include <stdint.h>
12 #include <stdbool.h>
13
14 #define MAX_VFS 10
15 #define VM_MAX_NAME_SZ 32
16 #define MAX_VCPU_PER_VM         8
17 #define HOURS 24
18
19 /* Valid Commands */
20 #define CPU_POWER               1
21 #define CPU_POWER_CONNECT       2
22 #define PKT_POLICY              3
23 #define PKT_POLICY_REMOVE       4
24
25 #define CORE_TYPE_VIRTUAL 0
26 #define CORE_TYPE_PHYSICAL 1
27
28 /* CPU Power Command Scaling */
29 #define CPU_POWER_SCALE_UP      1
30 #define CPU_POWER_SCALE_DOWN    2
31 #define CPU_POWER_SCALE_MAX     3
32 #define CPU_POWER_SCALE_MIN     4
33 #define CPU_POWER_ENABLE_TURBO  5
34 #define CPU_POWER_DISABLE_TURBO 6
35
36 /* CPU Power Queries */
37 #define CPU_POWER_QUERY_FREQ_LIST  7
38 #define CPU_POWER_QUERY_FREQ       8
39 #define CPU_POWER_QUERY_CAPS_LIST  9
40 #define CPU_POWER_QUERY_CAPS       10
41
42 /* --- Outgoing messages --- */
43
44 /* Generic Power Command Response */
45 #define CPU_POWER_CMD_ACK       1
46 #define CPU_POWER_CMD_NACK      2
47
48 /* CPU Power Query Responses */
49 #define CPU_POWER_FREQ_LIST     3
50 #define CPU_POWER_CAPS_LIST     4
51
52 struct rte_power_timer_profile {
53         int busy_hours[HOURS];
54         int quiet_hours[HOURS];
55         int hours_to_use_traffic_profile[HOURS];
56 };
57
58 enum rte_power_workload_level {HIGH, MEDIUM, LOW};
59
60 enum rte_power_policy {
61         TRAFFIC,
62         TIME,
63         WORKLOAD,
64         BRANCH_RATIO
65 };
66
67 struct rte_power_traffic_policy {
68         uint32_t min_packet_thresh;
69         uint32_t avg_max_packet_thresh;
70         uint32_t max_max_packet_thresh;
71 };
72
73 struct rte_power_turbo_status {
74         bool tbEnabled;
75 };
76
77 struct rte_power_channel_packet {
78         uint64_t resource_id; /**< core_num, device */
79         uint32_t unit;        /**< scale down/up/min/max */
80         uint32_t command;     /**< Power, IO, etc */
81         char vm_name[VM_MAX_NAME_SZ];
82
83         uint64_t vfid[MAX_VFS];
84         int nb_mac_to_monitor;
85         struct rte_power_traffic_policy traffic_policy;
86         uint8_t vcpu_to_control[MAX_VCPU_PER_VM];
87         uint8_t num_vcpu;
88         struct rte_power_timer_profile timer_policy;
89         bool core_type;
90         enum rte_power_workload_level workload;
91         enum rte_power_policy policy_to_use;
92         struct rte_power_turbo_status t_boost_status;
93 };
94
95 struct rte_power_channel_packet_freq_list {
96         uint64_t resource_id; /**< core_num, device */
97         uint32_t unit;        /**< scale down/up/min/max */
98         uint32_t command;     /**< Power, IO, etc */
99         char vm_name[VM_MAX_NAME_SZ];
100
101         uint32_t freq_list[MAX_VCPU_PER_VM];
102         uint8_t num_vcpu;
103 };
104
105 struct rte_power_channel_packet_caps_list {
106         uint64_t resource_id; /**< core_num, device */
107         uint32_t unit;        /**< scale down/up/min/max */
108         uint32_t command;     /**< Power, IO, etc */
109         char vm_name[VM_MAX_NAME_SZ];
110
111         uint64_t turbo[MAX_VCPU_PER_VM];
112         uint64_t priority[MAX_VCPU_PER_VM];
113         uint8_t num_vcpu;
114 };
115
116 /**
117  * @internal
118  *
119  * @warning
120  * @b EXPERIMENTAL: this API may change without prior notice.
121  *
122  * Send a message contained in pkt over the Virtio-Serial to the host endpoint.
123  *
124  * @param pkt
125  *  Pointer to a populated struct channel_packet.
126  *
127  * @param lcore_id
128  *  Use channel specific to this lcore_id.
129  *
130  * @return
131  *  - 0 on success.
132  *  - Negative on error.
133  */
134 __rte_experimental
135 int rte_power_guest_channel_send_msg(struct rte_power_channel_packet *pkt,
136                         unsigned int lcore_id);
137
138 /**
139  * @internal
140  *
141  * @warning
142  * @b EXPERIMENTAL: this API may change without prior notice.
143  *
144  * Receive a message contained in pkt over the Virtio-Serial
145  * from the host endpoint.
146  *
147  * @param pkt
148  *  Pointer to channel_packet or
149  *  channel_packet_freq_list struct.
150  *
151  * @param pkt_len
152  *  Size of expected data packet.
153  *
154  * @param lcore_id
155  *  Use channel specific to this lcore_id.
156  *
157  * @return
158  *  - 0 on success.
159  *  - Negative on error.
160  */
161 __rte_experimental
162 int rte_power_guest_channel_receive_msg(void *pkt,
163                 size_t pkt_len,
164                 unsigned int lcore_id);
165
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif /* RTE_POWER_GUEST_CHANNEL_H_ */