New upstream version 17.11-rc3
[deb_dpdk.git] / lib / librte_ether / rte_mtr_driver.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef __INCLUDE_RTE_MTR_DRIVER_H__
35 #define __INCLUDE_RTE_MTR_DRIVER_H__
36
37 /**
38  * @file
39  * RTE Generic Traffic Metering and Policing API (Driver Side)
40  *
41  * This file provides implementation helpers for internal use by PMDs, they
42  * are not intended to be exposed to applications and are not subject to ABI
43  * versioning.
44  */
45
46 #include <stdint.h>
47
48 #include <rte_errno.h>
49 #include "rte_ethdev.h"
50 #include "rte_mtr.h"
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 typedef int (*rte_mtr_capabilities_get_t)(struct rte_eth_dev *dev,
57         struct rte_mtr_capabilities *cap,
58         struct rte_mtr_error *error);
59 /**< @internal MTR capabilities get */
60
61 typedef int (*rte_mtr_meter_profile_add_t)(struct rte_eth_dev *dev,
62         uint32_t meter_profile_id,
63         struct rte_mtr_meter_profile *profile,
64         struct rte_mtr_error *error);
65 /**< @internal MTR meter profile add */
66
67 typedef int (*rte_mtr_meter_profile_delete_t)(struct rte_eth_dev *dev,
68         uint32_t meter_profile_id,
69         struct rte_mtr_error *error);
70 /**< @internal MTR meter profile delete */
71
72 typedef int (*rte_mtr_create_t)(struct rte_eth_dev *dev,
73         uint32_t mtr_id,
74         struct rte_mtr_params *params,
75         int shared,
76         struct rte_mtr_error *error);
77 /**< @internal MTR object create */
78
79 typedef int (*rte_mtr_destroy_t)(struct rte_eth_dev *dev,
80         uint32_t mtr_id,
81         struct rte_mtr_error *error);
82 /**< @internal MTR object destroy */
83
84 typedef int (*rte_mtr_meter_enable_t)(struct rte_eth_dev *dev,
85         uint32_t mtr_id,
86         struct rte_mtr_error *error);
87 /**< @internal MTR object meter enable */
88
89 typedef int (*rte_mtr_meter_disable_t)(struct rte_eth_dev *dev,
90         uint32_t mtr_id,
91         struct rte_mtr_error *error);
92 /**< @internal MTR object meter disable */
93
94 typedef int (*rte_mtr_meter_profile_update_t)(struct rte_eth_dev *dev,
95         uint32_t mtr_id,
96         uint32_t meter_profile_id,
97         struct rte_mtr_error *error);
98 /**< @internal MTR object meter profile update */
99
100 typedef int (*rte_mtr_meter_dscp_table_update_t)(struct rte_eth_dev *dev,
101         uint32_t mtr_id,
102         enum rte_mtr_color *dscp_table,
103         struct rte_mtr_error *error);
104 /**< @internal MTR object meter DSCP table update */
105
106 typedef int (*rte_mtr_policer_actions_update_t)(struct rte_eth_dev *dev,
107         uint32_t mtr_id,
108         uint32_t action_mask,
109         enum rte_mtr_policer_action *actions,
110         struct rte_mtr_error *error);
111 /**< @internal MTR object policer action update*/
112
113 typedef int (*rte_mtr_stats_update_t)(struct rte_eth_dev *dev,
114         uint32_t mtr_id,
115         uint64_t stats_mask,
116         struct rte_mtr_error *error);
117 /**< @internal MTR object enabled stats update */
118
119 typedef int (*rte_mtr_stats_read_t)(struct rte_eth_dev *dev,
120         uint32_t mtr_id,
121         struct rte_mtr_stats *stats,
122         uint64_t *stats_mask,
123         int clear,
124         struct rte_mtr_error *error);
125 /**< @internal MTR object stats read */
126
127 struct rte_mtr_ops {
128         /** MTR capabilities get */
129         rte_mtr_capabilities_get_t capabilities_get;
130
131         /** MTR meter profile add */
132         rte_mtr_meter_profile_add_t meter_profile_add;
133
134         /** MTR meter profile delete */
135         rte_mtr_meter_profile_delete_t meter_profile_delete;
136
137         /** MTR object create */
138         rte_mtr_create_t create;
139
140         /** MTR object destroy */
141         rte_mtr_destroy_t destroy;
142
143         /** MTR object meter enable */
144         rte_mtr_meter_enable_t meter_enable;
145
146         /** MTR object meter disable */
147         rte_mtr_meter_disable_t meter_disable;
148
149         /** MTR object meter profile update */
150         rte_mtr_meter_profile_update_t meter_profile_update;
151
152         /** MTR object meter DSCP table update */
153         rte_mtr_meter_dscp_table_update_t meter_dscp_table_update;
154
155         /** MTR object policer action update */
156         rte_mtr_policer_actions_update_t policer_actions_update;
157
158         /** MTR object enabled stats update */
159         rte_mtr_stats_update_t stats_update;
160
161         /** MTR object stats read */
162         rte_mtr_stats_read_t stats_read;
163 };
164
165 /**
166  * Initialize generic error structure.
167  *
168  * This function also sets rte_errno to a given value.
169  *
170  * @param[out] error
171  *   Pointer to error structure (may be NULL).
172  * @param[in] code
173  *   Related error code (rte_errno).
174  * @param[in] type
175  *   Cause field and error type.
176  * @param[in] cause
177  *   Object responsible for the error.
178  * @param[in] message
179  *   Human-readable error message.
180  *
181  * @return
182  *   Error code.
183  */
184 static inline int
185 rte_mtr_error_set(struct rte_mtr_error *error,
186                    int code,
187                    enum rte_mtr_error_type type,
188                    const void *cause,
189                    const char *message)
190 {
191         if (error) {
192                 *error = (struct rte_mtr_error){
193                         .type = type,
194                         .cause = cause,
195                         .message = message,
196                 };
197         }
198         rte_errno = code;
199         return code;
200 }
201
202 /**
203  * Get generic traffic metering and policing operations structure from a port
204  *
205  * @param[in] port_id
206  *   The port identifier of the Ethernet device.
207  * @param[out] error
208  *   Error details
209  *
210  * @return
211  *   The traffic metering and policing operations structure associated with
212  *   port_id on success, NULL otherwise.
213  */
214 const struct rte_mtr_ops *
215 rte_mtr_ops_get(uint16_t port_id, struct rte_mtr_error *error);
216
217 #ifdef __cplusplus
218 }
219 #endif
220
221 #endif /* __INCLUDE_RTE_MTR_DRIVER_H__ */