Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2016-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : : #include <stdlib.h>
13 : :
14 : : #include <rte_debug.h>
15 : : #include <rte_ether.h>
16 : : #include <ethdev_driver.h>
17 : : #include <rte_log.h>
18 : : #include <rte_malloc.h>
19 : : #include <rte_tailq.h>
20 : : #include <rte_hexdump.h>
21 : : #include <rte_flow_driver.h>
22 : : #include <rte_bitmap.h>
23 : :
24 : : #include "i40e_logs.h"
25 : : #include "base/i40e_type.h"
26 : : #include "base/i40e_prototype.h"
27 : : #include "i40e_ethdev.h"
28 : : #include "i40e_hash.h"
29 : : #include "i40e_flow.h"
30 : :
31 : : #include "../common/flow_check.h"
32 : :
33 : : const struct ci_flow_engine_list i40e_flow_engine_list = {
34 : : {
35 : : &i40e_flow_engine_ethertype,
36 : : &i40e_flow_engine_fdir,
37 : : &i40e_flow_engine_fdir_ethertype,
38 : : &i40e_flow_engine_tunnel_qinq,
39 : : &i40e_flow_engine_tunnel_vxlan,
40 : : &i40e_flow_engine_tunnel_nvgre,
41 : : &i40e_flow_engine_tunnel_mpls,
42 : : &i40e_flow_engine_tunnel_gtp,
43 : : &i40e_flow_engine_tunnel_l4,
44 : : &i40e_flow_engine_hash_pattern,
45 : : &i40e_flow_engine_hash_vlan,
46 : : &i40e_flow_engine_hash_empty,
47 : : }
48 : : };
49 : :
50 : : static int i40e_flow_validate(struct rte_eth_dev *dev,
51 : : const struct rte_flow_attr *attr,
52 : : const struct rte_flow_item pattern[],
53 : : const struct rte_flow_action actions[],
54 : : struct rte_flow_error *error);
55 : : static struct rte_flow *i40e_flow_create(struct rte_eth_dev *dev,
56 : : const struct rte_flow_attr *attr,
57 : : const struct rte_flow_item pattern[],
58 : : const struct rte_flow_action actions[],
59 : : struct rte_flow_error *error);
60 : : static int i40e_flow_destroy(struct rte_eth_dev *dev,
61 : : struct rte_flow *flow,
62 : : struct rte_flow_error *error);
63 : : static int i40e_flow_flush(struct rte_eth_dev *dev,
64 : : struct rte_flow_error *error);
65 : : static int i40e_flow_query(struct rte_eth_dev *dev,
66 : : struct rte_flow *flow,
67 : : const struct rte_flow_action *actions,
68 : : void *data, struct rte_flow_error *error);
69 : : static int i40e_flow_dev_dump(struct rte_eth_dev *dev,
70 : : struct rte_flow *flow,
71 : : FILE *file,
72 : : struct rte_flow_error *error);
73 : :
74 : : const struct rte_flow_ops i40e_flow_ops = {
75 : : .validate = i40e_flow_validate,
76 : : .create = i40e_flow_create,
77 : : .destroy = i40e_flow_destroy,
78 : : .flush = i40e_flow_flush,
79 : : .query = i40e_flow_query,
80 : : .dev_dump = i40e_flow_dev_dump,
81 : : };
82 : :
83 : : static int
84 : 0 : i40e_flow_dev_dump(struct rte_eth_dev *dev,
85 : : struct rte_flow *flow,
86 : : FILE *file,
87 : : struct rte_flow_error *error)
88 : : {
89 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
90 : :
91 : 0 : return ci_flow_dump(&pf->flow_engine_conf, flow, file, error);
92 : : }
93 : :
94 : : int
95 : 0 : i40e_get_outer_vlan(struct i40e_pf *pf, uint16_t *tpid)
96 : : {
97 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
98 : 0 : int qinq = pf->dev_data->dev_conf.rxmode.offloads &
99 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
100 : 0 : uint64_t reg_r = 0;
101 : : uint16_t reg_id;
102 : : int ret;
103 : :
104 [ # # ]: 0 : if (qinq)
105 : : reg_id = 2;
106 : : else
107 : : reg_id = 3;
108 : :
109 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
110 : : ®_r, NULL);
111 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
112 : 0 : PMD_DRV_LOG(ERR, "Failed to read from L2 tag ctrl register [%d]", reg_id);
113 : 0 : return -EIO;
114 : : }
115 : :
116 : 0 : *tpid = (reg_r >> I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT) & 0xFFFF;
117 : :
118 : 0 : return 0;
119 : : }
120 : :
121 : : uint8_t
122 : 0 : i40e_flow_fdir_get_pctype_value(struct i40e_pf *pf,
123 : : enum rte_flow_item_type item_type,
124 : : struct i40e_fdir_filter *filter)
125 : : {
126 : : struct i40e_customized_pctype *cus_pctype = NULL;
127 : :
128 [ # # # # : 0 : switch (item_type) {
# ]
129 : 0 : case RTE_FLOW_ITEM_TYPE_GTPC:
130 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
131 : : I40E_CUSTOMIZED_GTPC);
132 : 0 : break;
133 : 0 : case RTE_FLOW_ITEM_TYPE_GTPU:
134 [ # # ]: 0 : if (!filter->input.flow_ext.inner_ip)
135 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
136 : : I40E_CUSTOMIZED_GTPU);
137 [ # # ]: 0 : else if (filter->input.flow_ext.iip_type ==
138 : : I40E_FDIR_IPTYPE_IPV4)
139 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
140 : : I40E_CUSTOMIZED_GTPU_IPV4);
141 [ # # ]: 0 : else if (filter->input.flow_ext.iip_type ==
142 : : I40E_FDIR_IPTYPE_IPV6)
143 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
144 : : I40E_CUSTOMIZED_GTPU_IPV6);
145 : : break;
146 : 0 : case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
147 [ # # ]: 0 : if (filter->input.flow_ext.oip_type == I40E_FDIR_IPTYPE_IPV4)
148 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
149 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
150 [ # # ]: 0 : else if (filter->input.flow_ext.oip_type ==
151 : : I40E_FDIR_IPTYPE_IPV6)
152 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
153 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
154 : : break;
155 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
156 [ # # ]: 0 : if (!filter->input.flow_ext.is_udp) {
157 [ # # ]: 0 : if (filter->input.flow_ext.oip_type ==
158 : : I40E_FDIR_IPTYPE_IPV4)
159 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
160 : : I40E_CUSTOMIZED_ESP_IPV4);
161 [ # # ]: 0 : else if (filter->input.flow_ext.oip_type ==
162 : : I40E_FDIR_IPTYPE_IPV6)
163 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
164 : : I40E_CUSTOMIZED_ESP_IPV6);
165 : : } else {
166 [ # # ]: 0 : if (filter->input.flow_ext.oip_type ==
167 : : I40E_FDIR_IPTYPE_IPV4)
168 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
169 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
170 [ # # ]: 0 : else if (filter->input.flow_ext.oip_type ==
171 : : I40E_FDIR_IPTYPE_IPV6)
172 : 0 : cus_pctype = i40e_find_customized_pctype(pf,
173 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
174 : 0 : filter->input.flow_ext.is_udp = false;
175 : : }
176 : : break;
177 : 0 : default:
178 : 0 : PMD_DRV_LOG(ERR, "Unsupported item type");
179 : : break;
180 : : }
181 : :
182 [ # # # # ]: 0 : if (cus_pctype && cus_pctype->valid)
183 : 0 : return cus_pctype->pctype;
184 : :
185 : : return I40E_FILTER_PCTYPE_INVALID;
186 : : }
187 : :
188 : : static int
189 : 0 : i40e_flow_validate(struct rte_eth_dev *dev,
190 : : const struct rte_flow_attr *attr,
191 : : const struct rte_flow_item pattern[],
192 : : const struct rte_flow_action actions[],
193 : : struct rte_flow_error *error)
194 : : {
195 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
196 : :
197 : 0 : return ci_flow_validate(&pf->flow_engine_conf, attr, pattern, actions, error);
198 : : }
199 : :
200 : : static struct rte_flow *
201 : 0 : i40e_flow_create(struct rte_eth_dev *dev,
202 : : const struct rte_flow_attr *attr,
203 : : const struct rte_flow_item pattern[],
204 : : const struct rte_flow_action actions[],
205 : : struct rte_flow_error *error)
206 : : {
207 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
208 : :
209 : 0 : return ci_flow_create(&pf->flow_engine_conf, attr, pattern, actions, error);
210 : : }
211 : :
212 : : static int
213 : 0 : i40e_flow_destroy(struct rte_eth_dev *dev,
214 : : struct rte_flow *flow,
215 : : struct rte_flow_error *error)
216 : : {
217 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
218 : :
219 : 0 : return ci_flow_destroy(&pf->flow_engine_conf, flow, error);
220 : : }
221 : :
222 : : static int
223 : 0 : i40e_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
224 : : {
225 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
226 : :
227 : 0 : return ci_flow_flush(&pf->flow_engine_conf, error);
228 : : }
229 : :
230 : : static int
231 : 0 : i40e_flow_query(struct rte_eth_dev *dev,
232 : : struct rte_flow *flow,
233 : : const struct rte_flow_action *actions,
234 : : void *data, struct rte_flow_error *error)
235 : : {
236 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
237 : :
238 : 0 : return ci_flow_query(&pf->flow_engine_conf, flow, actions, data, error);
239 : : }
|