254d1cb2688bbd5b61303580df4d9398164afdf5
[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_ethdev.h"
49 #include "rte_flow.h"
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /**
56  * Generic flow operations structure implemented and returned by PMDs.
57  *
58  * To implement this API, PMDs must handle the RTE_ETH_FILTER_GENERIC filter
59  * type in their .filter_ctrl callback function (struct eth_dev_ops) as well
60  * as the RTE_ETH_FILTER_GET filter operation.
61  *
62  * If successful, this operation must result in a pointer to a PMD-specific
63  * struct rte_flow_ops written to the argument address as described below:
64  *
65  * \code
66  *
67  * // PMD filter_ctrl callback
68  *
69  * static const struct rte_flow_ops pmd_flow_ops = { ... };
70  *
71  * switch (filter_type) {
72  * case RTE_ETH_FILTER_GENERIC:
73  *     if (filter_op != RTE_ETH_FILTER_GET)
74  *         return -EINVAL;
75  *     *(const void **)arg = &pmd_flow_ops;
76  *     return 0;
77  * }
78  *
79  * \endcode
80  *
81  * See also rte_flow_ops_get().
82  *
83  * These callback functions are not supposed to be used by applications
84  * directly, which must rely on the API defined in rte_flow.h.
85  *
86  * Public-facing wrapper functions perform a few consistency checks so that
87  * unimplemented (i.e. NULL) callbacks simply return -ENOTSUP. These
88  * callbacks otherwise only differ by their first argument (with port ID
89  * already resolved to a pointer to struct rte_eth_dev).
90  */
91 struct rte_flow_ops {
92         /** See rte_flow_validate(). */
93         int (*validate)
94                 (struct rte_eth_dev *,
95                  const struct rte_flow_attr *,
96                  const struct rte_flow_item [],
97                  const struct rte_flow_action [],
98                  struct rte_flow_error *);
99         /** See rte_flow_create(). */
100         struct rte_flow *(*create)
101                 (struct rte_eth_dev *,
102                  const struct rte_flow_attr *,
103                  const struct rte_flow_item [],
104                  const struct rte_flow_action [],
105                  struct rte_flow_error *);
106         /** See rte_flow_destroy(). */
107         int (*destroy)
108                 (struct rte_eth_dev *,
109                  struct rte_flow *,
110                  struct rte_flow_error *);
111         /** See rte_flow_flush(). */
112         int (*flush)
113                 (struct rte_eth_dev *,
114                  struct rte_flow_error *);
115         /** See rte_flow_query(). */
116         int (*query)
117                 (struct rte_eth_dev *,
118                  struct rte_flow *,
119                  enum rte_flow_action_type,
120                  void *,
121                  struct rte_flow_error *);
122         /** See rte_flow_isolate(). */
123         int (*isolate)
124                 (struct rte_eth_dev *,
125                  int,
126                  struct rte_flow_error *);
127 };
128
129 /**
130  * Get generic flow operations structure from a port.
131  *
132  * @param port_id
133  *   Port identifier to query.
134  * @param[out] error
135  *   Pointer to flow error structure.
136  *
137  * @return
138  *   The flow operations structure associated with port_id, NULL in case of
139  *   error, in which case rte_errno is set and the error structure contains
140  *   additional details.
141  */
142 const struct rte_flow_ops *
143 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error);
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif /* RTE_FLOW_DRIVER_H_ */