]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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 | }; | |
124 | ||
125 | /** | |
126 | * Initialize generic flow error structure. | |
127 | * | |
128 | * This function also sets rte_errno to a given value. | |
129 | * | |
130 | * @param[out] error | |
131 | * Pointer to flow error structure (may be NULL). | |
132 | * @param code | |
133 | * Related error code (rte_errno). | |
134 | * @param type | |
135 | * Cause field and error types. | |
136 | * @param cause | |
137 | * Object responsible for the error. | |
138 | * @param message | |
139 | * Human-readable error message. | |
140 | * | |
141 | * @return | |
142 | * Error code. | |
143 | */ | |
144 | static inline int | |
145 | rte_flow_error_set(struct rte_flow_error *error, | |
146 | int code, | |
147 | enum rte_flow_error_type type, | |
148 | const void *cause, | |
149 | const char *message) | |
150 | { | |
151 | if (error) { | |
152 | *error = (struct rte_flow_error){ | |
153 | .type = type, | |
154 | .cause = cause, | |
155 | .message = message, | |
156 | }; | |
157 | } | |
158 | rte_errno = code; | |
159 | return code; | |
160 | } | |
161 | ||
162 | /** | |
163 | * Get generic flow operations structure from a port. | |
164 | * | |
165 | * @param port_id | |
166 | * Port identifier to query. | |
167 | * @param[out] error | |
168 | * Pointer to flow error structure. | |
169 | * | |
170 | * @return | |
171 | * The flow operations structure associated with port_id, NULL in case of | |
172 | * error, in which case rte_errno is set and the error structure contains | |
173 | * additional details. | |
174 | */ | |
175 | const struct rte_flow_ops * | |
176 | rte_flow_ops_get(uint8_t port_id, struct rte_flow_error *error); | |
177 | ||
178 | #ifdef __cplusplus | |
179 | } | |
180 | #endif | |
181 | ||
182 | #endif /* RTE_FLOW_DRIVER_H_ */ |