Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2022 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 <rte_debug.h>
13 : : #include <rte_ether.h>
14 : : #include <rte_ethdev.h>
15 : : #include <rte_log.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_eth_ctrl.h>
18 : : #include <rte_tailq.h>
19 : : #include <rte_flow_driver.h>
20 : : #include <rte_flow.h>
21 : : #include <iavf.h>
22 : : #include "iavf_generic_flow.h"
23 : : #include "../common/flow_check.h"
24 : :
25 : : #define MAX_QGRP_NUM_TYPE 7
26 : : #define IAVF_IPV6_ADDR_LENGTH 16
27 : : #define MAX_INPUT_SET_BYTE 32
28 : :
29 : : #define IAVF_SW_INSET_ETHER ( \
30 : : IAVF_INSET_DMAC | IAVF_INSET_SMAC | IAVF_INSET_ETHERTYPE)
31 : : #define IAVF_SW_INSET_MAC_IPV4 ( \
32 : : IAVF_INSET_DMAC | IAVF_INSET_IPV4_DST | IAVF_INSET_IPV4_SRC | \
33 : : IAVF_INSET_IPV4_PROTO | IAVF_INSET_IPV4_TTL | IAVF_INSET_IPV4_TOS)
34 : : #define IAVF_SW_INSET_MAC_VLAN_IPV4 ( \
35 : : IAVF_SW_INSET_MAC_IPV4 | IAVF_INSET_VLAN_OUTER)
36 : : #define IAVF_SW_INSET_MAC_IPV4_TCP ( \
37 : : IAVF_INSET_DMAC | IAVF_INSET_IPV4_DST | IAVF_INSET_IPV4_SRC | \
38 : : IAVF_INSET_IPV4_TTL | IAVF_INSET_IPV4_TOS | \
39 : : IAVF_INSET_TCP_DST_PORT | IAVF_INSET_TCP_SRC_PORT)
40 : : #define IAVF_SW_INSET_MAC_IPV4_UDP ( \
41 : : IAVF_INSET_DMAC | IAVF_INSET_IPV4_DST | IAVF_INSET_IPV4_SRC | \
42 : : IAVF_INSET_IPV4_TTL | IAVF_INSET_IPV4_TOS | \
43 : : IAVF_INSET_UDP_DST_PORT | IAVF_INSET_UDP_SRC_PORT)
44 : : #define IAVF_SW_INSET_MAC_IPV6 ( \
45 : : IAVF_INSET_DMAC | IAVF_INSET_IPV6_DST | IAVF_INSET_IPV6_SRC | \
46 : : IAVF_INSET_IPV6_TC | IAVF_INSET_IPV6_HOP_LIMIT | \
47 : : IAVF_INSET_IPV6_NEXT_HDR)
48 : : #define IAVF_SW_INSET_MAC_IPV6_TCP ( \
49 : : IAVF_INSET_DMAC | IAVF_INSET_IPV6_DST | IAVF_INSET_IPV6_SRC | \
50 : : IAVF_INSET_IPV6_HOP_LIMIT | IAVF_INSET_IPV6_TC | \
51 : : IAVF_INSET_TCP_DST_PORT | IAVF_INSET_TCP_SRC_PORT)
52 : : #define IAVF_SW_INSET_MAC_IPV6_UDP ( \
53 : : IAVF_INSET_DMAC | IAVF_INSET_IPV6_DST | IAVF_INSET_IPV6_SRC | \
54 : : IAVF_INSET_IPV6_HOP_LIMIT | IAVF_INSET_IPV6_TC | \
55 : : IAVF_INSET_UDP_DST_PORT | IAVF_INSET_UDP_SRC_PORT)
56 : :
57 : : static struct iavf_flow_parser iavf_fsub_parser;
58 : :
59 : : static struct
60 : : iavf_pattern_match_item iavf_fsub_pattern_list[] = {
61 : : {iavf_pattern_ethertype, IAVF_SW_INSET_ETHER, IAVF_INSET_NONE},
62 : : {iavf_pattern_eth_ipv4, IAVF_SW_INSET_MAC_IPV4, IAVF_INSET_NONE},
63 : : {iavf_pattern_eth_vlan_ipv4, IAVF_SW_INSET_MAC_VLAN_IPV4, IAVF_INSET_NONE},
64 : : {iavf_pattern_eth_ipv4_udp, IAVF_SW_INSET_MAC_IPV4_UDP, IAVF_INSET_NONE},
65 : : {iavf_pattern_eth_ipv4_tcp, IAVF_SW_INSET_MAC_IPV4_TCP, IAVF_INSET_NONE},
66 : : {iavf_pattern_eth_ipv6, IAVF_SW_INSET_MAC_IPV6, IAVF_INSET_NONE},
67 : : {iavf_pattern_eth_ipv6_udp, IAVF_SW_INSET_MAC_IPV6_UDP, IAVF_INSET_NONE},
68 : : {iavf_pattern_eth_ipv6_tcp, IAVF_SW_INSET_MAC_IPV6_TCP, IAVF_INSET_NONE},
69 : : };
70 : :
71 : : static int
72 : 0 : iavf_fsub_create(struct iavf_adapter *ad, struct rte_flow *flow,
73 : : void *meta, struct rte_flow_error *error)
74 : : {
75 : : struct iavf_fsub_conf *filter = meta;
76 : : int ret;
77 : :
78 : 0 : ret = iavf_flow_sub(ad, filter);
79 [ # # ]: 0 : if (ret) {
80 : 0 : rte_flow_error_set(error, -ret,
81 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
82 : : "Failed to subscribe flow rule.");
83 : 0 : return -rte_errno;
84 : : }
85 : :
86 : 0 : flow->rule = filter;
87 : 0 : return ret;
88 : : }
89 : :
90 : : static int
91 : 0 : iavf_fsub_destroy(struct iavf_adapter *ad, struct rte_flow *flow,
92 : : struct rte_flow_error *error)
93 : : {
94 : : struct iavf_fsub_conf *filter;
95 : : int ret;
96 : :
97 : 0 : filter = (struct iavf_fsub_conf *)flow->rule;
98 : :
99 : 0 : ret = iavf_flow_unsub(ad, filter);
100 [ # # ]: 0 : if (ret) {
101 : 0 : rte_flow_error_set(error, -ret,
102 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
103 : : "Failed to unsubscribe flow rule.");
104 : 0 : return -rte_errno;
105 : : }
106 : :
107 : : return ret;
108 : : }
109 : :
110 : : static int
111 : 0 : iavf_fsub_validation(struct iavf_adapter *ad,
112 : : __rte_unused struct rte_flow *flow,
113 : : void *meta,
114 : : struct rte_flow_error *error)
115 : : {
116 : : struct iavf_fsub_conf *filter = meta;
117 : : int ret;
118 : :
119 : 0 : ret = iavf_flow_sub_check(ad, filter);
120 [ # # ]: 0 : if (ret) {
121 : 0 : rte_flow_error_set(error, -ret,
122 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
123 : : "Failed to validate filter rule.");
124 : 0 : return -rte_errno;
125 : : }
126 : :
127 : : return ret;
128 : : };
129 : :
130 : : static int
131 : 0 : iavf_fsub_parse_pattern(const struct rte_flow_item pattern[],
132 : : const uint64_t input_set_mask,
133 : : struct rte_flow_error *error,
134 : : struct iavf_fsub_conf *filter)
135 : : {
136 : : struct virtchnl_proto_hdrs *hdrs = &filter->sub_fltr.proto_hdrs;
137 : : enum rte_flow_item_type item_type;
138 : : const struct rte_flow_item_eth *eth_spec, *eth_mask;
139 : : const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
140 : : const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
141 : : const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
142 : : const struct rte_flow_item_udp *udp_spec, *udp_mask;
143 : : const struct rte_flow_item_vlan *vlan_spec, *vlan_mask;
144 : : const struct rte_flow_item *item = pattern;
145 : : struct virtchnl_proto_hdr_w_msk *hdr, *hdr1 = NULL;
146 : : uint64_t outer_input_set = IAVF_INSET_NONE;
147 : : uint64_t *input = NULL;
148 : : uint16_t input_set_byte = 0;
149 : : uint32_t layer = 0;
150 : :
151 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
152 [ # # ]: 0 : if (item->last) {
153 : 0 : rte_flow_error_set(error, EINVAL,
154 : : RTE_FLOW_ERROR_TYPE_ITEM,
155 : : item, "Not support range");
156 : 0 : return -rte_errno;
157 : : }
158 : :
159 : : item_type = item->type;
160 [ # # # # : 0 : switch (item_type) {
# # # # ]
161 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
162 : 0 : eth_spec = item->spec;
163 : 0 : eth_mask = item->mask;
164 : :
165 : : hdr1 = &hdrs->proto_hdr_w_msk[layer];
166 : :
167 : 0 : VIRTCHNL_SET_PROTO_HDR_TYPE(hdr1, ETH);
168 : :
169 [ # # ]: 0 : if (eth_spec && eth_mask) {
170 : : input = &outer_input_set;
171 : :
172 [ # # ]: 0 : if (!rte_is_zero_ether_addr(ð_mask->hdr.dst_addr)) {
173 : 0 : *input |= IAVF_INSET_DMAC;
174 : 0 : input_set_byte += 6;
175 : : } else {
176 : : /* flow subscribe filter will add dst mac in kernel */
177 : 0 : input_set_byte += 6;
178 : : }
179 : :
180 [ # # ]: 0 : if (!rte_is_zero_ether_addr(ð_mask->hdr.src_addr)) {
181 : 0 : *input |= IAVF_INSET_SMAC;
182 : 0 : input_set_byte += 6;
183 : : }
184 : :
185 [ # # ]: 0 : if (eth_mask->hdr.ether_type) {
186 : 0 : *input |= IAVF_INSET_ETHERTYPE;
187 : 0 : input_set_byte += 2;
188 : : }
189 : :
190 : 0 : memcpy(hdr1->buffer_spec, eth_spec,
191 : : sizeof(struct rte_ether_hdr));
192 : 0 : memcpy(hdr1->buffer_mask, eth_mask,
193 : : sizeof(struct rte_ether_hdr));
194 : : } else {
195 : : /* flow subscribe filter will add dst mac in kernel */
196 : 0 : input_set_byte += 6;
197 : : }
198 : :
199 : 0 : hdrs->count = ++layer;
200 : 0 : break;
201 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
202 : 0 : ipv4_spec = item->spec;
203 : 0 : ipv4_mask = item->mask;
204 : :
205 : : hdr = &hdrs->proto_hdr_w_msk[layer];
206 : :
207 : 0 : VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, IPV4);
208 : :
209 [ # # ]: 0 : if (ipv4_spec && ipv4_mask) {
210 : : input = &outer_input_set;
211 : : /* Check IPv4 mask and update input set */
212 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
213 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
214 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
215 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
216 : 0 : rte_flow_error_set(error, EINVAL,
217 : : RTE_FLOW_ERROR_TYPE_ITEM,
218 : : item, "Invalid IPv4 mask.");
219 : 0 : return -rte_errno;
220 : : }
221 : :
222 [ # # ]: 0 : if (ipv4_mask->hdr.src_addr) {
223 : 0 : *input |= IAVF_INSET_IPV4_SRC;
224 : 0 : input_set_byte += 4;
225 : : }
226 [ # # ]: 0 : if (ipv4_mask->hdr.dst_addr) {
227 : 0 : *input |= IAVF_INSET_IPV4_DST;
228 : 0 : input_set_byte += 4;
229 : : }
230 [ # # ]: 0 : if (ipv4_mask->hdr.time_to_live) {
231 : 0 : *input |= IAVF_INSET_IPV4_TTL;
232 : 0 : input_set_byte++;
233 : : }
234 [ # # ]: 0 : if (ipv4_mask->hdr.next_proto_id) {
235 : 0 : *input |= IAVF_INSET_IPV4_PROTO;
236 : 0 : input_set_byte++;
237 : : }
238 [ # # ]: 0 : if (ipv4_mask->hdr.type_of_service) {
239 : 0 : *input |= IAVF_INSET_IPV4_TOS;
240 : 0 : input_set_byte++;
241 : : }
242 : :
243 : 0 : memcpy(hdr->buffer_spec, &ipv4_spec->hdr,
244 : : sizeof(ipv4_spec->hdr));
245 : 0 : memcpy(hdr->buffer_mask, &ipv4_mask->hdr,
246 : : sizeof(ipv4_spec->hdr));
247 : : }
248 : :
249 : 0 : hdrs->count = ++layer;
250 : 0 : break;
251 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6: {
252 : : int j;
253 : :
254 : 0 : ipv6_spec = item->spec;
255 : 0 : ipv6_mask = item->mask;
256 : :
257 : : hdr = &hdrs->proto_hdr_w_msk[layer];
258 : :
259 : 0 : VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, IPV6);
260 : :
261 [ # # ]: 0 : if (ipv6_spec && ipv6_mask) {
262 : : input = &outer_input_set;
263 : :
264 [ # # ]: 0 : if (ipv6_mask->hdr.payload_len) {
265 : 0 : rte_flow_error_set(error, EINVAL,
266 : : RTE_FLOW_ERROR_TYPE_ITEM,
267 : : item, "Invalid IPv6 mask");
268 : 0 : return -rte_errno;
269 : : }
270 : :
271 [ # # ]: 0 : for (j = 0; j < IAVF_IPV6_ADDR_LENGTH; j++) {
272 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j]) {
273 : 0 : *input |= IAVF_INSET_IPV6_SRC;
274 : 0 : break;
275 : : }
276 : : }
277 [ # # ]: 0 : for (j = 0; j < IAVF_IPV6_ADDR_LENGTH; j++) {
278 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j]) {
279 : 0 : *input |= IAVF_INSET_IPV6_DST;
280 : 0 : break;
281 : : }
282 : : }
283 : :
284 [ # # ]: 0 : for (j = 0; j < IAVF_IPV6_ADDR_LENGTH; j++) {
285 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j])
286 : 0 : input_set_byte++;
287 : :
288 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j])
289 : 0 : input_set_byte++;
290 : : }
291 : :
292 [ # # ]: 0 : if (ipv6_mask->hdr.proto) {
293 : 0 : *input |= IAVF_INSET_IPV6_NEXT_HDR;
294 : 0 : input_set_byte++;
295 : : }
296 [ # # ]: 0 : if (ipv6_mask->hdr.hop_limits) {
297 : 0 : *input |= IAVF_INSET_IPV6_HOP_LIMIT;
298 : 0 : input_set_byte++;
299 : : }
300 [ # # ]: 0 : if (ipv6_mask->hdr.vtc_flow &
301 : : rte_cpu_to_be_32(RTE_IPV6_HDR_TC_MASK)) {
302 : 0 : *input |= IAVF_INSET_IPV6_TC;
303 : 0 : input_set_byte += 4;
304 : : }
305 : :
306 : 0 : memcpy(hdr->buffer_spec, &ipv6_spec->hdr,
307 : : sizeof(ipv6_spec->hdr));
308 : 0 : memcpy(hdr->buffer_mask, &ipv6_mask->hdr,
309 : : sizeof(ipv6_spec->hdr));
310 : : }
311 : :
312 : 0 : hdrs->count = ++layer;
313 : 0 : break;
314 : : }
315 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
316 : 0 : udp_spec = item->spec;
317 : 0 : udp_mask = item->mask;
318 : :
319 : : hdr = &hdrs->proto_hdr_w_msk[layer];
320 : :
321 : 0 : VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, UDP);
322 : :
323 [ # # ]: 0 : if (udp_spec && udp_mask) {
324 : : input = &outer_input_set;
325 : : /* Check UDP mask and update input set*/
326 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
327 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
328 : 0 : rte_flow_error_set(error, EINVAL,
329 : : RTE_FLOW_ERROR_TYPE_ITEM,
330 : : item, "Invalid UDP mask");
331 : 0 : return -rte_errno;
332 : : }
333 : :
334 [ # # ]: 0 : if (udp_mask->hdr.src_port) {
335 : 0 : *input |= IAVF_INSET_UDP_SRC_PORT;
336 : 0 : input_set_byte += 2;
337 : : }
338 [ # # ]: 0 : if (udp_mask->hdr.dst_port) {
339 : 0 : *input |= IAVF_INSET_UDP_DST_PORT;
340 : 0 : input_set_byte += 2;
341 : : }
342 : :
343 : 0 : memcpy(hdr->buffer_spec, &udp_spec->hdr,
344 : : sizeof(udp_spec->hdr));
345 : 0 : memcpy(hdr->buffer_mask, &udp_mask->hdr,
346 : : sizeof(udp_mask->hdr));
347 : : }
348 : :
349 : 0 : hdrs->count = ++layer;
350 : 0 : break;
351 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
352 : 0 : tcp_spec = item->spec;
353 : 0 : tcp_mask = item->mask;
354 : :
355 : : hdr = &hdrs->proto_hdr_w_msk[layer];
356 : :
357 : 0 : VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, TCP);
358 : :
359 [ # # ]: 0 : if (tcp_spec && tcp_mask) {
360 : : input = &outer_input_set;
361 : : /* Check TCP mask and update input set */
362 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
363 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
364 [ # # ]: 0 : tcp_mask->hdr.data_off ||
365 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
366 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
367 [ # # ]: 0 : tcp_mask->hdr.cksum ||
368 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
369 : 0 : rte_flow_error_set(error, EINVAL,
370 : : RTE_FLOW_ERROR_TYPE_ITEM,
371 : : item, "Invalid TCP mask");
372 : 0 : return -rte_errno;
373 : : }
374 : :
375 [ # # ]: 0 : if (tcp_mask->hdr.src_port) {
376 : 0 : *input |= IAVF_INSET_TCP_SRC_PORT;
377 : 0 : input_set_byte += 2;
378 : : }
379 [ # # ]: 0 : if (tcp_mask->hdr.dst_port) {
380 : 0 : *input |= IAVF_INSET_TCP_DST_PORT;
381 : 0 : input_set_byte += 2;
382 : : }
383 : :
384 : 0 : memcpy(hdr->buffer_spec, &tcp_spec->hdr,
385 : : sizeof(tcp_spec->hdr));
386 : 0 : memcpy(hdr->buffer_mask, &tcp_mask->hdr,
387 : : sizeof(tcp_mask->hdr));
388 : : }
389 : :
390 : 0 : hdrs->count = ++layer;
391 : 0 : break;
392 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
393 : 0 : vlan_spec = item->spec;
394 : 0 : vlan_mask = item->mask;
395 : :
396 : : hdr = &hdrs->proto_hdr_w_msk[layer];
397 : :
398 : 0 : VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, S_VLAN);
399 : :
400 [ # # ]: 0 : if (vlan_spec && vlan_mask) {
401 : : input = &outer_input_set;
402 : :
403 : 0 : *input |= IAVF_INSET_VLAN_OUTER;
404 : :
405 [ # # ]: 0 : if (vlan_mask->hdr.vlan_tci)
406 : 0 : input_set_byte += 2;
407 : :
408 [ # # ]: 0 : if (vlan_mask->hdr.eth_proto) {
409 : 0 : rte_flow_error_set(error, EINVAL,
410 : : RTE_FLOW_ERROR_TYPE_ITEM,
411 : : item,
412 : : "Invalid VLAN input set.");
413 : 0 : return -rte_errno;
414 : : }
415 : :
416 : 0 : memcpy(hdr->buffer_spec, &vlan_spec->hdr,
417 : : sizeof(vlan_spec->hdr));
418 : 0 : memcpy(hdr->buffer_mask, &vlan_mask->hdr,
419 : : sizeof(vlan_mask->hdr));
420 : : }
421 : :
422 : 0 : hdrs->count = ++layer;
423 : 0 : break;
424 : : case RTE_FLOW_ITEM_TYPE_VOID:
425 : : break;
426 : 0 : default:
427 : 0 : rte_flow_error_set(error, EINVAL,
428 : : RTE_FLOW_ERROR_TYPE_ITEM, pattern,
429 : : "Invalid pattern item.");
430 : 0 : return -rte_errno;
431 : : }
432 : : }
433 : :
434 : 0 : hdrs->count += VIRTCHNL_MAX_NUM_PROTO_HDRS;
435 : :
436 [ # # ]: 0 : if (input_set_byte > MAX_INPUT_SET_BYTE) {
437 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
438 : : item, "too much input set");
439 : 0 : return -rte_errno;
440 : : }
441 : :
442 [ # # # # ]: 0 : if (!outer_input_set || (outer_input_set & ~input_set_mask))
443 : 0 : return -rte_errno;
444 : :
445 : : return 0;
446 : : }
447 : :
448 : : static int
449 : 0 : iavf_fsub_parse_action(const struct ci_flow_actions *actions,
450 : : uint32_t priority,
451 : : struct rte_flow_error *error,
452 : : struct iavf_fsub_conf *filter)
453 : : {
454 : : uint16_t num_actions = 0;
455 : : size_t i;
456 : :
457 [ # # ]: 0 : for (i = 0; i < actions->count; i++) {
458 : 0 : const struct rte_flow_action *action = actions->actions[i];
459 : : struct virtchnl_filter_action *filter_action =
460 : 0 : &filter->sub_fltr.actions.actions[num_actions];
461 : :
462 [ # # # # ]: 0 : switch (action->type) {
463 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
464 : : /* nothing to be done, but skip the action */
465 : 0 : continue;
466 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
467 : : {
468 : 0 : const struct rte_flow_action_queue *act_q = action->conf;
469 : 0 : filter_action->type = VIRTCHNL_ACTION_QUEUE;
470 : 0 : filter_action->act_conf.queue.index = act_q->index;
471 : 0 : break;
472 : : }
473 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
474 : : {
475 : 0 : const struct rte_flow_action_rss *act_qgrp = action->conf;
476 : :
477 : 0 : filter_action->type = VIRTCHNL_ACTION_Q_REGION;
478 : 0 : filter_action->act_conf.queue.index = act_qgrp->queue[0];
479 : 0 : filter_action->act_conf.queue.region = act_qgrp->queue_num;
480 : 0 : break;
481 : : }
482 : 0 : default:
483 : : /* cannot happen */
484 : 0 : return rte_flow_error_set(error, EINVAL,
485 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
486 : : "Invalid action type.");
487 : : }
488 : 0 : filter->sub_fltr.actions.count = ++num_actions;
489 : : }
490 : :
491 : : /* 0 denotes lowest priority of recipe and highest priority
492 : : * of rte_flow. Change rte_flow priority into recipe priority.
493 : : */
494 : 0 : filter->sub_fltr.priority = priority;
495 : :
496 : 0 : return 0;
497 : : }
498 : :
499 : : static int
500 : 0 : iavf_fsub_action_check(const struct ci_flow_actions *actions,
501 : : const struct ci_flow_actions_check_param *param,
502 : : struct rte_flow_error *error)
503 : : {
504 : 0 : const struct iavf_adapter *ad = param->driver_ctx;
505 : : bool vf = false;
506 : : size_t i;
507 : :
508 : : /*
509 : : * allowed action types:
510 : : * 1. PORT_REPRESENTOR only
511 : : * 2. PORT_REPRESENTOR + QUEUE/RSS
512 : : */
513 : :
514 [ # # ]: 0 : for (i = 0; i < actions->count; i++) {
515 : 0 : const struct rte_flow_action *action = actions->actions[i];
516 [ # # # # ]: 0 : switch (action->type) {
517 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
518 : : {
519 : 0 : const struct rte_flow_action_ethdev *act_ethdev = action->conf;
520 : :
521 [ # # ]: 0 : if (act_ethdev->port_id != ad->dev_data->port_id) {
522 : 0 : return rte_flow_error_set(error, EINVAL,
523 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, act_ethdev,
524 : : "Invalid port id");
525 : : }
526 : : vf = true;
527 : : break;
528 : : }
529 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
530 : : {
531 : 0 : const struct rte_flow_action_rss *act_qgrp = action->conf;
532 : :
533 : : /* must be between 2 and 128 and be a power of 2 */
534 [ # # ]: 0 : if (act_qgrp->queue_num < 2 || act_qgrp->queue_num > 128 ||
535 : : !rte_is_power_of_2(act_qgrp->queue_num)) {
536 : 0 : return rte_flow_error_set(error, EINVAL,
537 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, act_qgrp,
538 : : "Invalid number of queues in RSS queue group");
539 : : }
540 : : /* last queue must not exceed total number of queues */
541 [ # # ]: 0 : if (act_qgrp->queue[0] + act_qgrp->queue_num > ad->dev_data->nb_rx_queues) {
542 : 0 : return rte_flow_error_set(error, EINVAL,
543 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, act_qgrp,
544 : : "Invalid queue index in RSS queue group");
545 : : }
546 : : break;
547 : : }
548 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
549 : : {
550 : 0 : const struct rte_flow_action_queue *act_q = action->conf;
551 : :
552 [ # # ]: 0 : if (act_q->index >= ad->dev_data->nb_rx_queues) {
553 : 0 : return rte_flow_error_set(error, EINVAL,
554 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, act_q,
555 : : "Invalid queue index");
556 : : }
557 : : break;
558 : : }
559 : 0 : default:
560 : : /* shouldn't happen */
561 : 0 : return rte_flow_error_set(error, EINVAL,
562 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
563 : : "Invalid action type");
564 : : }
565 : : }
566 : : /* QUEUE/RSS must be accompanied by PORT_REPRESENTOR */
567 [ # # ]: 0 : if (!vf) {
568 : 0 : return rte_flow_error_set(error, EINVAL,
569 : : RTE_FLOW_ERROR_TYPE_ACTION, actions,
570 : : "Invalid action combination");
571 : : }
572 : :
573 : : return 0;
574 : : }
575 : :
576 : : static int
577 : 0 : iavf_fsub_parse(struct iavf_adapter *ad,
578 : : struct iavf_pattern_match_item *array,
579 : : uint32_t array_len,
580 : : const struct rte_flow_item pattern[],
581 : : const struct rte_flow_action actions[],
582 : : const struct rte_flow_attr *attr,
583 : : void **meta,
584 : : struct rte_flow_error *error)
585 : : {
586 : 0 : struct ci_flow_actions parsed_actions = {0};
587 : 0 : struct ci_flow_actions_check_param param = {
588 : 0 : .allowed_types = (enum rte_flow_action_type[]){
589 : : RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR,
590 : : RTE_FLOW_ACTION_TYPE_RSS,
591 : : RTE_FLOW_ACTION_TYPE_QUEUE,
592 : : RTE_FLOW_ACTION_TYPE_END
593 : : },
594 : : .max_actions = 2,
595 : : .check = iavf_fsub_action_check,
596 : : .driver_ctx = ad,
597 : : .rss_queues_contig = true,
598 : : };
599 : : struct iavf_fsub_conf *filter;
600 : : struct iavf_pattern_match_item *pattern_match_item = NULL;
601 : 0 : struct ci_flow_attr_check_param attr_param = {
602 : : .allow_priority = true,
603 : : };
604 : : int ret = 0;
605 : :
606 : 0 : filter = rte_zmalloc(NULL, sizeof(*filter), 0);
607 [ # # ]: 0 : if (!filter) {
608 : 0 : rte_flow_error_set(error, EINVAL,
609 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
610 : : "No memory for iavf_fsub_conf_ptr");
611 : 0 : return -ENOMEM;
612 : : }
613 : :
614 : 0 : ret = ci_flow_check_attr(attr, &attr_param, error);
615 [ # # ]: 0 : if (ret)
616 : 0 : goto error;
617 : :
618 : 0 : ret = ci_flow_check_actions(actions, ¶m, &parsed_actions, error);
619 [ # # ]: 0 : if (ret)
620 : 0 : goto error;
621 : :
622 [ # # ]: 0 : if (attr->priority > 1) {
623 : 0 : rte_flow_error_set(error, EINVAL,
624 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
625 : : attr, "Only support priority 0 and 1.");
626 : 0 : ret = -rte_errno;
627 : 0 : goto error;
628 : : }
629 : :
630 : : /* search flow subscribe pattern */
631 : 0 : pattern_match_item = iavf_search_pattern_match_item(pattern, array,
632 : : array_len, error);
633 [ # # ]: 0 : if (!pattern_match_item) {
634 : 0 : ret = -rte_errno;
635 : 0 : goto error;
636 : : }
637 : :
638 : : /* parse flow subscribe pattern */
639 : 0 : ret = iavf_fsub_parse_pattern(pattern,
640 : : pattern_match_item->input_set_mask,
641 : : error, filter);
642 [ # # ]: 0 : if (ret)
643 : 0 : goto error;
644 : :
645 : : /* parse flow subscribe pattern action */
646 : 0 : ret = iavf_fsub_parse_action(&parsed_actions, attr->priority, error, filter);
647 : :
648 : 0 : error:
649 [ # # ]: 0 : if (!ret && meta)
650 : 0 : *meta = filter;
651 : : else
652 : 0 : rte_free(filter);
653 : :
654 : 0 : rte_free(pattern_match_item);
655 : 0 : return ret;
656 : : }
657 : :
658 : : static int
659 : 0 : iavf_fsub_init(struct iavf_adapter *ad)
660 : : {
661 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
662 : : struct iavf_flow_parser *parser;
663 : :
664 [ # # ]: 0 : if (!vf->vf_res)
665 : : return -EINVAL;
666 : :
667 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_FSUB_PF)
668 : : parser = &iavf_fsub_parser;
669 : : else
670 : : return -ENOTSUP;
671 : :
672 : 0 : return iavf_register_parser(parser, ad);
673 : : }
674 : :
675 : : static void
676 : 0 : iavf_fsub_uninit(struct iavf_adapter *ad)
677 : : {
678 : 0 : iavf_unregister_parser(&iavf_fsub_parser, ad);
679 : 0 : }
680 : :
681 : : static struct
682 : : iavf_flow_engine iavf_fsub_engine = {
683 : : .init = iavf_fsub_init,
684 : : .uninit = iavf_fsub_uninit,
685 : : .create = iavf_fsub_create,
686 : : .destroy = iavf_fsub_destroy,
687 : : .validation = iavf_fsub_validation,
688 : : .name = "fsub",
689 : : .type = IAVF_FLOW_ENGINE_FSUB,
690 : : .rule_size = sizeof(struct iavf_fsub_conf),
691 : : };
692 : :
693 : : static struct
694 : : iavf_flow_parser iavf_fsub_parser = {
695 : : .engine = &iavf_fsub_engine,
696 : : .array = iavf_fsub_pattern_list,
697 : : .array_len = RTE_DIM(iavf_fsub_pattern_list),
698 : : .parse_pattern_action = iavf_fsub_parse,
699 : : };
700 : :
701 : 306 : RTE_INIT(iavf_fsub_engine_init)
702 : : {
703 : 306 : iavf_register_flow_engine(&iavf_fsub_engine);
704 : 306 : }
|