Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <stddef.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : : #include <rte_byteorder.h>
15 : : #include <rte_common.h>
16 : : #include <rte_cycles.h>
17 : :
18 : : #include <rte_interrupts.h>
19 : : #include <rte_log.h>
20 : : #include <rte_debug.h>
21 : : #include <rte_pci.h>
22 : : #include <rte_branch_prediction.h>
23 : : #include <rte_memory.h>
24 : : #include <rte_eal.h>
25 : : #include <rte_alarm.h>
26 : : #include <rte_ether.h>
27 : : #include <rte_tailq.h>
28 : : #include <ethdev_driver.h>
29 : : #include <rte_malloc.h>
30 : : #include <rte_random.h>
31 : : #include <dev_driver.h>
32 : : #include <rte_hash_crc.h>
33 : : #include <rte_flow.h>
34 : : #include <rte_hexdump.h>
35 : : #include <rte_flow_driver.h>
36 : :
37 : : #include "ixgbe_logs.h"
38 : : #include "base/ixgbe_api.h"
39 : : #include "base/ixgbe_vf.h"
40 : : #include "base/ixgbe_common.h"
41 : : #include "ixgbe_osdep.h"
42 : : #include "ixgbe_ethdev.h"
43 : : #include "ixgbe_bypass.h"
44 : : #include "ixgbe_rxtx.h"
45 : : #include "base/ixgbe_type.h"
46 : : #include "base/ixgbe_phy.h"
47 : : #include "rte_pmd_ixgbe.h"
48 : :
49 : : #include "../common/flow_check.h"
50 : : #include "../common/flow_engine.h"
51 : : #include "ixgbe_flow.h"
52 : :
53 : : const struct ci_flow_engine_list ixgbe_flow_engine_list = {
54 : : {
55 : : &ixgbe_ethertype_flow_engine,
56 : : &ixgbe_syn_flow_engine,
57 : : &ixgbe_l2_tunnel_flow_engine,
58 : : &ixgbe_ntuple_flow_engine,
59 : : &ixgbe_security_flow_engine,
60 : : &ixgbe_fdir_flow_engine,
61 : : &ixgbe_fdir_tunnel_flow_engine,
62 : : &ixgbe_hash_flow_engine,
63 : : },
64 : : };
65 : : /*
66 : : * All ixgbe engines mostly check the same stuff, so use a common check.
67 : : */
68 : : int
69 : 0 : ixgbe_flow_actions_check(const struct ci_flow_actions *actions,
70 : : const struct ci_flow_actions_check_param *param,
71 : : struct rte_flow_error *error)
72 : : {
73 : : const struct rte_flow_action *action;
74 : 0 : struct rte_eth_dev_data *dev_data = param->driver_ctx;
75 : 0 : struct ixgbe_adapter *ad = IXGBE_DEV_PRIVATE_TO_ADAPTER(dev_data->dev_private);
76 : : size_t idx;
77 : :
78 [ # # ]: 0 : for (idx = 0; idx < actions->count; idx++) {
79 : 0 : action = actions->actions[idx];
80 : :
81 [ # # # ]: 0 : switch (action->type) {
82 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
83 : : {
84 : 0 : const struct rte_flow_action_queue *queue = action->conf;
85 [ # # ]: 0 : if (queue->index >= dev_data->nb_rx_queues) {
86 : 0 : return rte_flow_error_set(error, EINVAL,
87 : : RTE_FLOW_ERROR_TYPE_ACTION,
88 : : action,
89 : : "queue index out of range");
90 : : }
91 : : break;
92 : : }
93 : 0 : case RTE_FLOW_ACTION_TYPE_VF:
94 : : {
95 : 0 : const struct rte_flow_action_vf *vf = action->conf;
96 [ # # ]: 0 : if (vf->id >= ad->max_vfs) {
97 : 0 : return rte_flow_error_set(error, EINVAL,
98 : : RTE_FLOW_ERROR_TYPE_ACTION,
99 : : action,
100 : : "VF id out of range");
101 : : }
102 : : break;
103 : : }
104 : : default:
105 : : /* no specific validation */
106 : : break;
107 : : }
108 : : }
109 : : return 0;
110 : : }
111 : :
112 : : /**
113 : : * Please be aware there's an assumption for all the parsers.
114 : : * rte_flow_item is using big endian, rte_flow_attr and
115 : : * rte_flow_action are using CPU order.
116 : : * Because the pattern is used to describe the packets,
117 : : * normally the packets should use network order.
118 : : */
119 : :
120 : : /**
121 : : * Create or destroy a flow rule.
122 : : * Theorically one rule can match more than one filters.
123 : : * We will let it use the filter which it hitt first.
124 : : * So, the sequence matters.
125 : : */
126 : : static struct rte_flow *
127 : 0 : ixgbe_flow_create(struct rte_eth_dev *dev,
128 : : const struct rte_flow_attr *attr,
129 : : const struct rte_flow_item pattern[],
130 : : const struct rte_flow_action actions[],
131 : : struct rte_flow_error *error)
132 : : {
133 : 0 : struct ixgbe_adapter *ad = IXGBE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
134 : :
135 : 0 : return ci_flow_create(&ad->flow_engine_conf, attr, pattern, actions, error);
136 : : }
137 : :
138 : : /**
139 : : * Check if the flow rule is supported by ixgbe.
140 : : * It only checks the format. Don't guarantee the rule can be programmed into
141 : : * the HW. Because there can be no enough room for the rule.
142 : : */
143 : : static int
144 : 0 : ixgbe_flow_validate(struct rte_eth_dev *dev,
145 : : const struct rte_flow_attr *attr,
146 : : const struct rte_flow_item pattern[],
147 : : const struct rte_flow_action actions[],
148 : : struct rte_flow_error *error)
149 : : {
150 : 0 : struct ixgbe_adapter *ad = IXGBE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
151 : :
152 : 0 : return ci_flow_validate(&ad->flow_engine_conf, attr, pattern, actions, error);
153 : : }
154 : :
155 : : /* Destroy a flow rule on ixgbe. */
156 : : static int
157 : 0 : ixgbe_flow_destroy(struct rte_eth_dev *dev,
158 : : struct rte_flow *flow,
159 : : struct rte_flow_error *error)
160 : : {
161 : 0 : struct ixgbe_adapter *ad = IXGBE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
162 : :
163 : 0 : return ci_flow_destroy(&ad->flow_engine_conf, flow, error);
164 : : }
165 : :
166 : : /* Destroy all flow rules associated with a port on ixgbe. */
167 : : static int
168 : 0 : ixgbe_flow_flush(struct rte_eth_dev *dev,
169 : : struct rte_flow_error *error)
170 : : {
171 : 0 : struct ixgbe_adapter *ad = IXGBE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
172 : : int ret = 0;
173 : :
174 : : /* flush the flow engine */
175 : 0 : ret = ci_flow_flush(&ad->flow_engine_conf, error);
176 [ # # ]: 0 : if (ret) {
177 : 0 : PMD_DRV_LOG(ERR, "Failed to flush flow");
178 : 0 : return ret;
179 : : }
180 : :
181 : : return 0;
182 : : }
183 : :
184 : : static int
185 : 0 : ixgbe_flow_dev_dump(struct rte_eth_dev *dev,
186 : : struct rte_flow *flow,
187 : : FILE *file,
188 : : struct rte_flow_error *error)
189 : : {
190 : 0 : struct ixgbe_adapter *ad = IXGBE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
191 : :
192 : 0 : return ci_flow_dump(&ad->flow_engine_conf, flow, file, error);
193 : : }
194 : :
195 : : const struct rte_flow_ops ixgbe_flow_ops = {
196 : : .validate = ixgbe_flow_validate,
197 : : .create = ixgbe_flow_create,
198 : : .destroy = ixgbe_flow_destroy,
199 : : .flush = ixgbe_flow_flush,
200 : : .dev_dump = ixgbe_flow_dev_dump,
201 : : };
|