4d95391d8344ad7125d2610f42115b79e865da88
[deb_dpdk.git] / lib / librte_ether / rte_flow_driver.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 6WIND S.A.
5  *   Copyright 2016 Mellanox.
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 6WIND S.A. 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 RTE_FLOW_DRIVER_H_
35 #define RTE_FLOW_DRIVER_H_
36
37 /**
38  * @file
39  * RTE generic flow 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_flow.h"
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 /**
57  * Generic flow operations structure implemented and returned by PMDs.
58  *
59  * To implement this API, PMDs must handle the RTE_ETH_FILTER_GENERIC filter
60  * type in their .filter_ctrl callback function (struct eth_dev_ops) as well
61  * as the RTE_ETH_FILTER_GET filter operation.
62  *
63  * If successful, this operation must result in a pointer to a PMD-specific
64  * struct rte_flow_ops written to the argument address as described below:
65  *
66  * \code
67  *
68  * // PMD filter_ctrl callback
69  *
70  * static const struct rte_flow_ops pmd_flow_ops = { ... };
71  *
72  * switch (filter_type) {
73  * case RTE_ETH_FILTER_GENERIC:
74  *     if (filter_op != RTE_ETH_FILTER_GET)
75  *         return -EINVAL;
76  *     *(const void **)arg = &pmd_flow_ops;
77  *     return 0;
78  * }
79  *
80  * \endcode
81  *
82  * See also rte_flow_ops_get().
83  *
84  * These callback functions are not supposed to be used by applications
85  * directly, which must rely on the API defined in rte_flow.h.
86  *
87  * Public-facing wrapper functions perform a few consistency checks so that
88  * unimplemented (i.e. NULL) callbacks simply return -ENOTSUP. These
89  * callbacks otherwise only differ by their first argument (with port ID
90  * already resolved to a pointer to struct rte_eth_dev).
91  */
92 struct rte_flow_ops {
93         /** See rte_flow_validate(). */
94         int (*validate)
95                 (struct rte_eth_dev *,
96                  const struct rte_flow_attr *,
97                  const struct rte_flow_item [],
98                  const struct rte_flow_action [],
99                  struct rte_flow_error *);
100         /** See rte_flow_create(). */
101         struct rte_flow *(*create)
102                 (struct rte_eth_dev *,
103                  const struct rte_flow_attr *,
104                  const struct rte_flow_item [],
105                  const struct rte_flow_action [],
106                  struct rte_flow_error *);
107         /** See rte_flow_destroy(). */
108         int (*destroy)
109                 (struct rte_eth_dev *,
110                  struct rte_flow *,
111                  struct rte_flow_error *);
112         /** See rte_flow_flush(). */
113         int (*flush)
114                 (struct rte_eth_dev *,
115                  struct rte_flow_error *);
116         /** See rte_flow_query(). */
117         int (*query)
118                 (struct rte_eth_dev *,
119                  struct rte_flow *,
120                  enum rte_flow_action_type,
121                  void *,
122                  struct rte_flow_error *);
123         /** See rte_flow_isolate(). */
124         int (*isolate)
125                 (struct rte_eth_dev *,
126                  int,
127                  struct rte_flow_error *);
128 };
129
130 /**
131  * Initialize generic flow error structure.
132  *
133  * This function also sets rte_errno to a given value.
134  *
135  * @param[out] error
136  *   Pointer to flow error structure (may be NULL).
137  * @param code
138  *   Related error code (rte_errno).
139  * @param type
140  *   Cause field and error types.
141  * @param cause
142  *   Object responsible for the error.
143  * @param message
144  *   Human-readable error message.
145  *
146  * @return
147  *   Error code.
148  */
149 static inline int
150 rte_flow_error_set(struct rte_flow_error *error,
151                    int code,
152                    enum rte_flow_error_type type,
153                    const void *cause,
154                    const char *message)
155 {
156         if (error) {
157                 *error = (struct rte_flow_error){
158                         .type = type,
159                         .cause = cause,
160                         .message = message,
161                 };
162         }
163         rte_errno = code;
164         return code;
165 }
166
167 /**
168  * Get generic flow operations structure from a port.
169  *
170  * @param port_id
171  *   Port identifier to query.
172  * @param[out] error
173  *   Pointer to flow error structure.
174  *
175  * @return
176  *   The flow operations structure associated with port_id, NULL in case of
177  *   error, in which case rte_errno is set and the error structure contains
178  *   additional details.
179  */
180 const struct rte_flow_ops *
181 rte_flow_ops_get(uint8_t port_id, struct rte_flow_error *error);
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif /* RTE_FLOW_DRIVER_H_ */