1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5 
6 #ifndef RTE_FLOW_DRIVER_H_
7 #define RTE_FLOW_DRIVER_H_
8 
9 /**
10  * @file
11  * RTE generic flow API (driver side)
12  *
13  * This file provides implementation helpers for internal use by PMDs, they
14  * are not intended to be exposed to applications and are not subject to ABI
15  * versioning.
16  */
17 
18 #include <stdint.h>
19 
20 #include "rte_ethdev.h"
21 #include "rte_ethdev_driver.h"
22 #include "rte_flow.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /**
29  * Generic flow operations structure implemented and returned by PMDs.
30  *
31  * To implement this API, PMDs must handle the RTE_ETH_FILTER_GENERIC filter
32  * type in their .filter_ctrl callback function (struct eth_dev_ops) as well
33  * as the RTE_ETH_FILTER_GET filter operation.
34  *
35  * If successful, this operation must result in a pointer to a PMD-specific
36  * struct rte_flow_ops written to the argument address as described below:
37  *
38  * \code
39  *
40  * // PMD filter_ctrl callback
41  *
42  * static const struct rte_flow_ops pmd_flow_ops = { ... };
43  *
44  * switch (filter_type) {
45  * case RTE_ETH_FILTER_GENERIC:
46  *     if (filter_op != RTE_ETH_FILTER_GET)
47  *         return -EINVAL;
48  *     *(const void **)arg = &pmd_flow_ops;
49  *     return 0;
50  * }
51  *
52  * \endcode
53  *
54  * See also rte_flow_ops_get().
55  *
56  * These callback functions are not supposed to be used by applications
57  * directly, which must rely on the API defined in rte_flow.h.
58  *
59  * Public-facing wrapper functions perform a few consistency checks so that
60  * unimplemented (i.e. NULL) callbacks simply return -ENOTSUP. These
61  * callbacks otherwise only differ by their first argument (with port ID
62  * already resolved to a pointer to struct rte_eth_dev).
63  */
64 struct rte_flow_ops {
65 	/** See rte_flow_validate(). */
66 	int (*validate)
67 		(struct rte_eth_dev *,
68 		 const struct rte_flow_attr *,
69 		 const struct rte_flow_item [],
70 		 const struct rte_flow_action [],
71 		 struct rte_flow_error *);
72 	/** See rte_flow_create(). */
73 	struct rte_flow *(*create)
74 		(struct rte_eth_dev *,
75 		 const struct rte_flow_attr *,
76 		 const struct rte_flow_item [],
77 		 const struct rte_flow_action [],
78 		 struct rte_flow_error *);
79 	/** See rte_flow_destroy(). */
80 	int (*destroy)
81 		(struct rte_eth_dev *,
82 		 struct rte_flow *,
83 		 struct rte_flow_error *);
84 	/** See rte_flow_flush(). */
85 	int (*flush)
86 		(struct rte_eth_dev *,
87 		 struct rte_flow_error *);
88 	/** See rte_flow_query(). */
89 	int (*query)
90 		(struct rte_eth_dev *,
91 		 struct rte_flow *,
92 		 const struct rte_flow_action *,
93 		 void *,
94 		 struct rte_flow_error *);
95 	/** See rte_flow_isolate(). */
96 	int (*isolate)
97 		(struct rte_eth_dev *,
98 		 int,
99 		 struct rte_flow_error *);
100 	/** See rte_flow_dev_dump(). */
101 	int (*dev_dump)
102 		(struct rte_eth_dev *dev,
103 		 FILE *file,
104 		 struct rte_flow_error *error);
105 	/** See rte_flow_get_aged_flows() */
106 	int (*get_aged_flows)
107 		(struct rte_eth_dev *dev,
108 		 void **context,
109 		 uint32_t nb_contexts,
110 		 struct rte_flow_error *err);
111 	/** See rte_flow_shared_action_create() */
112 	struct rte_flow_shared_action *(*shared_action_create)
113 		(struct rte_eth_dev *dev,
114 		 const struct rte_flow_shared_action_conf *conf,
115 		 const struct rte_flow_action *action,
116 		 struct rte_flow_error *error);
117 	/** See rte_flow_shared_action_destroy() */
118 	int (*shared_action_destroy)
119 		(struct rte_eth_dev *dev,
120 		 struct rte_flow_shared_action *shared_action,
121 		 struct rte_flow_error *error);
122 	/** See rte_flow_shared_action_update() */
123 	int (*shared_action_update)
124 		(struct rte_eth_dev *dev,
125 		 struct rte_flow_shared_action *shared_action,
126 		 const struct rte_flow_action *update,
127 		 struct rte_flow_error *error);
128 	/** See rte_flow_shared_action_query() */
129 	int (*shared_action_query)
130 		(struct rte_eth_dev *dev,
131 		 const struct rte_flow_shared_action *shared_action,
132 		 void *data,
133 		 struct rte_flow_error *error);
134 	/** See rte_flow_tunnel_decap_set() */
135 	int (*tunnel_decap_set)
136 		(struct rte_eth_dev *dev,
137 		 struct rte_flow_tunnel *tunnel,
138 		 struct rte_flow_action **pmd_actions,
139 		 uint32_t *num_of_actions,
140 		 struct rte_flow_error *err);
141 	/** See rte_flow_tunnel_match() */
142 	int (*tunnel_match)
143 		(struct rte_eth_dev *dev,
144 		 struct rte_flow_tunnel *tunnel,
145 		 struct rte_flow_item **pmd_items,
146 		 uint32_t *num_of_items,
147 		 struct rte_flow_error *err);
148 	/** See rte_flow_get_rte_flow_restore_info() */
149 	int (*get_restore_info)
150 		(struct rte_eth_dev *dev,
151 		 struct rte_mbuf *m,
152 		 struct rte_flow_restore_info *info,
153 		 struct rte_flow_error *err);
154 	/** See rte_flow_action_tunnel_decap_release() */
155 	int (*tunnel_action_decap_release)
156 		(struct rte_eth_dev *dev,
157 		 struct rte_flow_action *pmd_actions,
158 		 uint32_t num_of_actions,
159 		 struct rte_flow_error *err);
160 	/** See rte_flow_item_release() */
161 	int (*tunnel_item_release)
162 		(struct rte_eth_dev *dev,
163 		 struct rte_flow_item *pmd_items,
164 		 uint32_t num_of_items,
165 		 struct rte_flow_error *err);
166 };
167 
168 /**
169  * Get generic flow operations structure from a port.
170  *
171  * @param port_id
172  *   Port identifier to query.
173  * @param[out] error
174  *   Pointer to flow error structure.
175  *
176  * @return
177  *   The flow operations structure associated with port_id, NULL in case of
178  *   error, in which case rte_errno is set and the error structure contains
179  *   additional details.
180  */
181 const struct rte_flow_ops *
182 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error);
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif /* RTE_FLOW_DRIVER_H_ */
189