Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2023 Intel Corporation
3 : : */
4 : :
5 : : #include <arpa/inet.h>
6 : :
7 : : #include "cpfl_flow_parser.h"
8 : :
9 : : static enum rte_flow_item_type
10 : 0 : cpfl_get_item_type_by_str(const char *type)
11 : : {
12 [ # # ]: 0 : if (strcmp(type, "eth") == 0)
13 : : return RTE_FLOW_ITEM_TYPE_ETH;
14 [ # # ]: 0 : else if (strcmp(type, "ipv4") == 0)
15 : : return RTE_FLOW_ITEM_TYPE_IPV4;
16 [ # # ]: 0 : else if (strcmp(type, "tcp") == 0)
17 : : return RTE_FLOW_ITEM_TYPE_TCP;
18 [ # # ]: 0 : else if (strcmp(type, "udp") == 0)
19 : : return RTE_FLOW_ITEM_TYPE_UDP;
20 [ # # ]: 0 : else if (strcmp(type, "vxlan") == 0)
21 : : return RTE_FLOW_ITEM_TYPE_VXLAN;
22 [ # # ]: 0 : else if (strcmp(type, "icmp") == 0)
23 : : return RTE_FLOW_ITEM_TYPE_ICMP;
24 [ # # ]: 0 : else if (strcmp(type, "vlan") == 0)
25 : : return RTE_FLOW_ITEM_TYPE_VLAN;
26 : :
27 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %s.", type);
28 : 0 : return RTE_FLOW_ITEM_TYPE_VOID;
29 : : }
30 : :
31 : : static enum rte_flow_action_type
32 : 0 : cpfl_get_action_type_by_str(const char *type)
33 : : {
34 [ # # ]: 0 : if (strcmp(type, "vxlan_encap") == 0)
35 : : return RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP;
36 [ # # ]: 0 : else if (strcmp(type, "vxlan_decap") == 0)
37 : : return RTE_FLOW_ACTION_TYPE_VXLAN_DECAP;
38 [ # # ]: 0 : else if (strcmp(type, "prog") == 0)
39 : : return RTE_FLOW_ACTION_TYPE_PROG;
40 : :
41 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %s.", type);
42 : 0 : return RTE_FLOW_ACTION_TYPE_VOID;
43 : : }
44 : :
45 : : static const char *
46 : 0 : cpfl_json_t_to_string(json_t *object, const char *name)
47 : : {
48 : : json_t *subobject;
49 : :
50 [ # # ]: 0 : if (!object) {
51 : 0 : PMD_DRV_LOG(ERR, "object doesn't exist.");
52 : 0 : return NULL;
53 : : }
54 : 0 : subobject = json_object_get(object, name);
55 [ # # ]: 0 : if (!subobject) {
56 : 0 : PMD_DRV_LOG(ERR, "%s doesn't exist.", name);
57 : 0 : return NULL;
58 : : }
59 : :
60 : 0 : return json_string_value(subobject);
61 : : }
62 : :
63 : : static int
64 : 0 : cpfl_json_t_to_int(json_t *object, const char *name, int *value)
65 : : {
66 : : json_t *subobject;
67 : :
68 [ # # ]: 0 : if (!object) {
69 : 0 : PMD_DRV_LOG(ERR, "object doesn't exist.");
70 : 0 : return -EINVAL;
71 : : }
72 : 0 : subobject = json_object_get(object, name);
73 [ # # ]: 0 : if (!subobject) {
74 : 0 : PMD_DRV_LOG(ERR, "%s doesn't exist.", name);
75 : 0 : return -EINVAL;
76 : : }
77 [ # # ]: 0 : if (!json_is_integer(subobject)) {
78 : 0 : PMD_DRV_LOG(ERR, "%s is not an integer.", name);
79 : 0 : return -EINVAL;
80 : : }
81 : 0 : *value = (int)json_integer_value(subobject);
82 : :
83 : 0 : return 0;
84 : : }
85 : :
86 : : static int
87 : 0 : cpfl_json_t_to_uint16(json_t *object, const char *name, uint16_t *value)
88 : : {
89 : : json_t *subobject;
90 : :
91 [ # # ]: 0 : if (!object) {
92 : 0 : PMD_DRV_LOG(ERR, "object doesn't exist.");
93 : 0 : return -EINVAL;
94 : : }
95 : 0 : subobject = json_object_get(object, name);
96 [ # # ]: 0 : if (!subobject) {
97 : 0 : PMD_DRV_LOG(ERR, "%s doesn't exist.", name);
98 : 0 : return -EINVAL;
99 : : }
100 [ # # ]: 0 : if (!json_is_integer(subobject)) {
101 : 0 : PMD_DRV_LOG(ERR, "%s is not an integer.", name);
102 : 0 : return -EINVAL;
103 : : }
104 : 0 : *value = (uint16_t)json_integer_value(subobject);
105 : :
106 : 0 : return 0;
107 : : }
108 : :
109 : : static int
110 : 0 : cpfl_json_t_to_uint32(json_t *object, const char *name, uint32_t *value)
111 : : {
112 : : json_t *subobject;
113 : :
114 [ # # ]: 0 : if (!object) {
115 : 0 : PMD_DRV_LOG(ERR, "object doesn't exist.");
116 : 0 : return -EINVAL;
117 : : }
118 : 0 : subobject = json_object_get(object, name);
119 [ # # ]: 0 : if (!subobject) {
120 : 0 : PMD_DRV_LOG(ERR, "%s doesn't exist.", name);
121 : 0 : return -EINVAL;
122 : : }
123 [ # # ]: 0 : if (!json_is_integer(subobject)) {
124 : 0 : PMD_DRV_LOG(ERR, "%s is not an integer.", name);
125 : 0 : return -EINVAL;
126 : : }
127 : 0 : *value = (uint32_t)json_integer_value(subobject);
128 : :
129 : 0 : return 0;
130 : : }
131 : :
132 : : static int
133 : 0 : cpfl_flow_js_pattern_key_attr(json_t *ob_pr_key_attrs, struct cpfl_flow_js_pr *js_pr)
134 : : {
135 : : int i, len;
136 : : struct cpfl_flow_js_pr_key_attr *attr;
137 : :
138 : 0 : len = json_array_size(ob_pr_key_attrs);
139 : 0 : js_pr->key.attributes = rte_malloc(NULL, sizeof(struct cpfl_flow_js_pr_key_attr), 0);
140 [ # # ]: 0 : if (!js_pr->key.attributes) {
141 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
142 : 0 : return -ENOMEM;
143 : : }
144 : 0 : js_pr->key.attr_size = len;
145 : : attr = js_pr->key.attributes;
146 [ # # ]: 0 : for (i = 0; i < len; i++) {
147 : : json_t *object;
148 : : const char *name;
149 : 0 : uint16_t value = 0;
150 : : int ret;
151 : :
152 : 0 : object = json_array_get(ob_pr_key_attrs, i);
153 : 0 : name = cpfl_json_t_to_string(object, "Name");
154 [ # # ]: 0 : if (!name) {
155 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'Name'.");
156 : 0 : goto err;
157 : : }
158 : 0 : ret = cpfl_json_t_to_uint16(object, "Value", &value);
159 [ # # ]: 0 : if (ret < 0) {
160 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'value'.");
161 : 0 : goto err;
162 : : }
163 [ # # ]: 0 : if (strcmp(name, "ingress") == 0) {
164 : 0 : attr->ingress = value;
165 [ # # ]: 0 : } else if (strcmp(name, "egress") == 0) {
166 : 0 : attr->egress = value;
167 : : } else {
168 : : /* TODO: more... */
169 : 0 : PMD_DRV_LOG(ERR, "Not support attr name: %s.", name);
170 : 0 : goto err;
171 : : }
172 : : }
173 : :
174 : : return 0;
175 : : err:
176 : 0 : rte_free(js_pr->key.attributes);
177 : 0 : return -EINVAL;
178 : : }
179 : :
180 : : static int
181 : 0 : cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
182 : : struct cpfl_flow_js_pr_key_proto *js_field)
183 : : {
184 : : int len, i;
185 : :
186 [ # # ]: 0 : if (!ob_fields)
187 : : return 0;
188 : 0 : len = json_array_size(ob_fields);
189 [ # # ]: 0 : if (len == 0)
190 : : return 0;
191 : 0 : js_field->fields_size = len;
192 : 0 : js_field->fields =
193 : 0 : rte_malloc(NULL, sizeof(struct cpfl_flow_js_pr_key_proto_field) * len, 0);
194 [ # # ]: 0 : if (!js_field->fields) {
195 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
196 : 0 : return -ENOMEM;
197 : : }
198 [ # # ]: 0 : for (i = 0; i < len; i++) {
199 : : json_t *object;
200 : : const char *name, *mask;
201 : :
202 : 0 : object = json_array_get(ob_fields, i);
203 : 0 : name = cpfl_json_t_to_string(object, "name");
204 [ # # ]: 0 : if (!name) {
205 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'name'.");
206 : 0 : goto err;
207 : : }
208 [ # # ]: 0 : if (strlen(name) > CPFL_JS_STR_SIZE - 1) {
209 : 0 : PMD_DRV_LOG(ERR, "The 'name' is too long.");
210 : 0 : goto err;
211 : : }
212 [ # # ]: 0 : strncpy(js_field->fields[i].name, name, CPFL_JS_STR_SIZE - 1);
213 : :
214 [ # # ]: 0 : if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
215 : : js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
216 : 0 : mask = cpfl_json_t_to_string(object, "mask");
217 [ # # ]: 0 : if (!mask) {
218 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
219 : 0 : goto err;
220 : : }
221 [ # # ]: 0 : if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
222 : 0 : PMD_DRV_LOG(ERR, "The 'mask' is too long.");
223 : 0 : goto err;
224 : : }
225 : 0 : strncpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
226 : : } else {
227 : : uint32_t mask_32b;
228 : : int ret;
229 : :
230 : 0 : ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
231 [ # # ]: 0 : if (ret < 0) {
232 : 0 : PMD_DRV_LOG(ERR, "Can not parse uint32 'mask'.");
233 : 0 : goto err;
234 : : }
235 : 0 : js_field->fields[i].mask_32b = mask_32b;
236 : : }
237 : : }
238 : :
239 : : return 0;
240 : :
241 : 0 : err:
242 : 0 : rte_free(js_field->fields);
243 : 0 : return -EINVAL;
244 : : }
245 : :
246 : : static int
247 : 0 : cpfl_flow_js_pattern_key_proto(json_t *ob_pr_key_protos, struct cpfl_flow_js_pr *js_pr)
248 : : {
249 : : int len, i, ret;
250 : :
251 : 0 : len = json_array_size(ob_pr_key_protos);
252 [ # # ]: 0 : if (len == 0)
253 : : return 0;
254 : 0 : js_pr->key.proto_size = len;
255 : 0 : js_pr->key.protocols = rte_malloc(NULL, sizeof(struct cpfl_flow_js_pr_key_proto) * len, 0);
256 [ # # ]: 0 : if (!js_pr->key.protocols) {
257 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
258 : 0 : return -ENOMEM;
259 : : }
260 : :
261 [ # # ]: 0 : for (i = 0; i < len; i++) {
262 : : json_t *object, *ob_fields;
263 : : const char *type;
264 : : enum rte_flow_item_type item_type;
265 : :
266 : 0 : object = json_array_get(ob_pr_key_protos, i);
267 : : /* pr->key->proto->type */
268 : 0 : type = cpfl_json_t_to_string(object, "type");
269 [ # # ]: 0 : if (!type) {
270 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'type'.");
271 : 0 : goto err;
272 : : }
273 : 0 : item_type = cpfl_get_item_type_by_str(type);
274 [ # # ]: 0 : if (item_type == RTE_FLOW_ITEM_TYPE_VOID)
275 : 0 : goto err;
276 : 0 : js_pr->key.protocols[i].type = item_type;
277 : : /* pr->key->proto->fields */
278 : 0 : ob_fields = json_object_get(object, "fields");
279 : 0 : ret = cpfl_flow_js_pattern_key_proto_field(ob_fields,
280 : 0 : &js_pr->key.protocols[i]);
281 [ # # ]: 0 : if (ret < 0)
282 : 0 : goto err;
283 : : }
284 : :
285 : : return 0;
286 : :
287 : 0 : err:
288 : 0 : rte_free(js_pr->key.protocols);
289 : 0 : return -EINVAL;
290 : : }
291 : :
292 : : static int
293 : 0 : cpfl_flow_js_pattern_act_fv_proto(json_t *ob_value, struct cpfl_flow_js_fv *js_fv)
294 : : {
295 : 0 : uint16_t layer = 0, offset = 0, mask = 0;
296 : : const char *header;
297 : : enum rte_flow_item_type type;
298 : : int ret;
299 : :
300 : 0 : ret = cpfl_json_t_to_uint16(ob_value, "layer", &layer);
301 [ # # ]: 0 : if (ret < 0) {
302 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'value'.");
303 : 0 : return -EINVAL;
304 : : }
305 : :
306 : 0 : header = cpfl_json_t_to_string(ob_value, "header");
307 [ # # ]: 0 : if (!header) {
308 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'header'.");
309 : 0 : return -EINVAL;
310 : : }
311 : 0 : ret = cpfl_json_t_to_uint16(ob_value, "offset", &offset);
312 [ # # ]: 0 : if (ret < 0) {
313 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'offset'.");
314 : 0 : return -EINVAL;
315 : : }
316 : 0 : ret = cpfl_json_t_to_uint16(ob_value, "mask", &mask);
317 [ # # ]: 0 : if (ret < 0) {
318 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'mask'.");
319 : 0 : return -EINVAL;
320 : : }
321 : 0 : type = cpfl_get_item_type_by_str(header);
322 [ # # ]: 0 : if (type == RTE_FLOW_ITEM_TYPE_VOID)
323 : : return -EINVAL;
324 : 0 : js_fv->proto.layer = layer;
325 : 0 : js_fv->proto.offset = offset;
326 : 0 : js_fv->proto.mask = mask;
327 : 0 : js_fv->proto.header = type;
328 : :
329 : 0 : return 0;
330 : : }
331 : :
332 : : static int
333 : 0 : cpfl_flow_js_pattern_act_fv_metadata(json_t *ob_value, struct cpfl_flow_js_fv *js_fv)
334 : : {
335 : : int ret;
336 : :
337 : 0 : ret = cpfl_json_t_to_uint16(ob_value, "type", &js_fv->meta.type);
338 [ # # ]: 0 : if (ret < 0) {
339 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'size'.");
340 : 0 : return ret;
341 : : }
342 : 0 : ret = cpfl_json_t_to_uint16(ob_value, "offset", &js_fv->meta.offset);
343 [ # # ]: 0 : if (ret < 0) {
344 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'size'.");
345 : 0 : return ret;
346 : : }
347 : 0 : ret = cpfl_json_t_to_uint16(ob_value, "mask", &js_fv->meta.mask);
348 [ # # ]: 0 : if (ret < 0) {
349 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'size'.");
350 : 0 : return ret;
351 : : }
352 : :
353 : : return 0;
354 : : }
355 : :
356 : : static int
357 : 0 : cpfl_flow_js_pattern_act_fv(json_t *ob_fvs, struct cpfl_flow_js_pr_action *js_act)
358 : : {
359 : : int len, i;
360 : :
361 : 0 : len = json_array_size(ob_fvs);
362 [ # # ]: 0 : if (len == 0)
363 : : return 0;
364 : 0 : js_act->sem.fv = rte_malloc(NULL, sizeof(struct cpfl_flow_js_fv) * len, 0);
365 [ # # ]: 0 : if (!js_act->sem.fv) {
366 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
367 : 0 : return -ENOMEM;
368 : : }
369 : 0 : js_act->sem.fv_size = len;
370 [ # # ]: 0 : for (i = 0; i < len; i++) {
371 : : struct cpfl_flow_js_fv *js_fv;
372 : : json_t *object, *ob_value;
373 : 0 : uint16_t offset = 0;
374 : : const char *type;
375 : : int ret;
376 : :
377 : 0 : js_fv = &js_act->sem.fv[i];
378 : 0 : object = json_array_get(ob_fvs, i);
379 : 0 : ret = cpfl_json_t_to_uint16(object, "offset", &offset);
380 [ # # ]: 0 : if (ret < 0) {
381 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'offset'.");
382 : 0 : goto err;
383 : : }
384 : 0 : js_fv->offset = offset;
385 : :
386 : 0 : type = cpfl_json_t_to_string(object, "type");
387 [ # # ]: 0 : if (!type) {
388 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'type'.");
389 : 0 : goto err;
390 : : }
391 : 0 : ob_value = json_object_get(object, "value");
392 [ # # ]: 0 : if (strcmp(type, "immediate") == 0) {
393 : 0 : js_fv->type = CPFL_FV_TYPE_IMMEDIATE;
394 : 0 : js_fv->immediate = json_integer_value(ob_value);
395 [ # # ]: 0 : } else if (strcmp(type, "metadata") == 0) {
396 : 0 : js_fv->type = CPFL_FV_TYPE_METADATA;
397 : 0 : cpfl_flow_js_pattern_act_fv_metadata(ob_value, js_fv);
398 [ # # ]: 0 : } else if (strcmp(type, "protocol") == 0) {
399 : 0 : js_fv->type = CPFL_FV_TYPE_PROTOCOL;
400 : 0 : cpfl_flow_js_pattern_act_fv_proto(ob_value, js_fv);
401 : : } else {
402 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %s.", type);
403 : 0 : goto err;
404 : : }
405 : : }
406 : :
407 : : return 0;
408 : :
409 : : err:
410 : 0 : rte_free(js_act->sem.fv);
411 : 0 : return -EINVAL;
412 : : }
413 : :
414 : : static int
415 : 0 : cpfl_flow_js_pattern_per_act(json_t *ob_per_act, struct cpfl_flow_js_pr_action *js_act)
416 : : {
417 : : const char *type;
418 : : int ret;
419 : :
420 : : /* pr->actions->type */
421 : 0 : type = cpfl_json_t_to_string(ob_per_act, "type");
422 [ # # ]: 0 : if (!type) {
423 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'type'.");
424 : 0 : return -EINVAL;
425 : : }
426 : : /* pr->actions->data */
427 [ # # ]: 0 : if (strcmp(type, "sem") == 0) {
428 : : json_t *ob_fvs, *ob_sem;
429 : :
430 : 0 : js_act->type = CPFL_JS_PR_ACTION_TYPE_SEM;
431 : 0 : ob_sem = json_object_get(ob_per_act, "data");
432 : 0 : ret = cpfl_json_t_to_uint16(ob_sem, "profile", &js_act->sem.prof);
433 [ # # ]: 0 : if (ret < 0) {
434 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'profile'.");
435 : 0 : return -EINVAL;
436 : : }
437 : 0 : ret = cpfl_json_t_to_uint16(ob_sem, "subprofile", &js_act->sem.subprof);
438 [ # # ]: 0 : if (ret < 0) {
439 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'subprofile'.");
440 : 0 : return -EINVAL;
441 : : }
442 : 0 : ret = cpfl_json_t_to_uint16(ob_sem, "keysize", &js_act->sem.keysize);
443 [ # # ]: 0 : if (ret < 0) {
444 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'keysize'.");
445 : 0 : return -EINVAL;
446 : : }
447 : 0 : ob_fvs = json_object_get(ob_sem, "fieldvectors");
448 : 0 : ret = cpfl_flow_js_pattern_act_fv(ob_fvs, js_act);
449 : : if (ret < 0)
450 : : return ret;
451 : : } else {
452 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %s.", type);
453 : 0 : return -EINVAL;
454 : : }
455 : :
456 : : return 0;
457 : : }
458 : :
459 : : static int
460 : 0 : cpfl_flow_js_pattern_act(json_t *ob_pr_acts, struct cpfl_flow_js_pr *js_pr)
461 : : {
462 : : int i, len, ret;
463 : :
464 : 0 : len = json_array_size(ob_pr_acts);
465 [ # # ]: 0 : if (len == 0)
466 : : return 0;
467 : 0 : js_pr->actions = rte_malloc(NULL, sizeof(struct cpfl_flow_js_pr_action) * len, 0);
468 [ # # ]: 0 : if (!js_pr->actions) {
469 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
470 : 0 : return -ENOMEM;
471 : : }
472 : 0 : js_pr->actions_size = len;
473 [ # # ]: 0 : for (i = 0; i < len; i++) {
474 : : struct cpfl_flow_js_pr_action *js_act;
475 : : json_t *object;
476 : :
477 : 0 : object = json_array_get(ob_pr_acts, i);
478 : 0 : js_act = &js_pr->actions[i];
479 : 0 : ret = cpfl_flow_js_pattern_per_act(object, js_act);
480 [ # # ]: 0 : if (ret < 0) {
481 : 0 : rte_free(js_pr->actions);
482 : 0 : PMD_DRV_LOG(ERR, "Can not parse pattern action.");
483 : 0 : return -EINVAL;
484 : : }
485 : : }
486 : :
487 : : return 0;
488 : : }
489 : :
490 : : /**
491 : : * The patterns object array defines a set of rules directing the PMD to match sequences of
492 : : * rte_flow protocol headers and translate them into profile/field vectors for each pipeline
493 : : * stage. This object is mandatory.
494 : : */
495 : : static int
496 : 0 : cpfl_flow_js_pattern_rule(json_t *ob_root, struct cpfl_flow_js_parser *parser)
497 : : {
498 : : json_t *ob_prs;
499 : : int i, len;
500 : :
501 : : /* Pattern Rules */
502 : 0 : ob_prs = json_object_get(ob_root, "patterns");
503 [ # # ]: 0 : if (!ob_prs) {
504 : 0 : PMD_DRV_LOG(ERR, "The patterns is mandatory.");
505 : 0 : return -EINVAL;
506 : : }
507 : :
508 : 0 : len = json_array_size(ob_prs);
509 [ # # ]: 0 : if (len == 0)
510 : : return 0;
511 : 0 : parser->patterns = rte_malloc(NULL, sizeof(struct cpfl_flow_js_pr) * len, 0);
512 [ # # ]: 0 : if (!parser->patterns) {
513 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
514 : 0 : return -ENOMEM;
515 : : }
516 : 0 : parser->pr_size = len;
517 [ # # ]: 0 : for (i = 0; i < len; i++) {
518 : : json_t *object;
519 : : json_t *ob_pr_actions;
520 : : json_t *ob_pr_key;
521 : : json_t *ob_pr_key_protos;
522 : : json_t *ob_pr_key_attrs;
523 : : int ret;
524 : :
525 : 0 : object = json_array_get(ob_prs, i);
526 : : /* pr->key */
527 : 0 : ob_pr_key = json_object_get(object, "key");
528 : : /* pr->key->protocols */
529 : 0 : ob_pr_key_protos = json_object_get(ob_pr_key, "protocols");
530 : 0 : ret = cpfl_flow_js_pattern_key_proto(ob_pr_key_protos, &parser->patterns[i]);
531 [ # # ]: 0 : if (ret < 0) {
532 : 0 : PMD_DRV_LOG(ERR, "Can not parse key->protocols.");
533 : 0 : goto err;
534 : : }
535 : : /* pr->key->attributes */
536 : 0 : ob_pr_key_attrs = json_object_get(ob_pr_key, "attributes");
537 : 0 : ret = cpfl_flow_js_pattern_key_attr(ob_pr_key_attrs, &parser->patterns[i]);
538 [ # # ]: 0 : if (ret < 0) {
539 : 0 : PMD_DRV_LOG(ERR, "Can not parse key->attributes.");
540 : 0 : goto err;
541 : : }
542 : : /* pr->actions */
543 : 0 : ob_pr_actions = json_object_get(object, "actions");
544 : 0 : ret = cpfl_flow_js_pattern_act(ob_pr_actions, &parser->patterns[i]);
545 [ # # ]: 0 : if (ret < 0) {
546 : 0 : PMD_DRV_LOG(ERR, "Can not parse pattern action.");
547 : 0 : goto err;
548 : : }
549 : : }
550 : :
551 : : return 0;
552 : :
553 : 0 : err:
554 : 0 : rte_free(parser->patterns);
555 : 0 : return -EINVAL;
556 : : }
557 : :
558 : : static int
559 : 0 : cpfl_flow_js_mr_key(json_t *ob_mr_keys, struct cpfl_flow_js_mr_key *js_mr_key)
560 : : {
561 : : int len, i;
562 : :
563 : 0 : len = json_array_size(ob_mr_keys);
564 [ # # ]: 0 : if (len == 0)
565 : : return 0;
566 : 0 : js_mr_key->actions = rte_malloc(NULL, sizeof(struct cpfl_flow_js_mr_key_action) * len, 0);
567 [ # # ]: 0 : if (!js_mr_key->actions) {
568 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
569 : 0 : return -ENOMEM;
570 : : }
571 : 0 : js_mr_key->actions_size = len;
572 [ # # ]: 0 : for (i = 0; i < len; i++) {
573 : : json_t *object, *ob_data;
574 : : const char *type;
575 : : enum rte_flow_action_type act_type;
576 : :
577 : 0 : object = json_array_get(ob_mr_keys, i);
578 : : /* mr->key->actions->type */
579 : 0 : type = cpfl_json_t_to_string(object, "type");
580 [ # # ]: 0 : if (!type) {
581 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'type'.");
582 : 0 : goto err;
583 : : }
584 : 0 : act_type = cpfl_get_action_type_by_str(type);
585 [ # # ]: 0 : if (act_type == RTE_FLOW_ACTION_TYPE_VOID)
586 : 0 : goto err;
587 : 0 : js_mr_key->actions[i].type = act_type;
588 : : /* mr->key->actions->data */
589 : 0 : ob_data = json_object_get(object, "data");
590 [ # # ]: 0 : if (js_mr_key->actions[i].type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP) {
591 : : json_t *ob_protos;
592 : : int proto_size, j;
593 : : struct cpfl_flow_js_mr_key_action_vxlan_encap *encap;
594 : :
595 : 0 : ob_protos = json_object_get(ob_data, "protocols");
596 : 0 : encap = &js_mr_key->actions[i].encap;
597 [ # # ]: 0 : if (!ob_protos) {
598 : 0 : encap->proto_size = 0;
599 : 0 : continue;
600 : : }
601 : 0 : proto_size = json_array_size(ob_protos);
602 : 0 : encap->proto_size = proto_size;
603 [ # # ]: 0 : for (j = 0; j < proto_size; j++) {
604 : : const char *s;
605 : : json_t *subobject;
606 : : enum rte_flow_item_type proto_type;
607 : :
608 : 0 : subobject = json_array_get(ob_protos, j);
609 : 0 : s = json_string_value(subobject);
610 : 0 : proto_type = cpfl_get_item_type_by_str(s);
611 [ # # ]: 0 : if (proto_type == RTE_FLOW_ITEM_TYPE_VOID) {
612 : 0 : PMD_DRV_LOG(ERR, "parse VXLAN_ENCAP failed.");
613 : 0 : goto err;
614 : : }
615 : 0 : encap->protocols[j] = proto_type;
616 : : }
617 [ # # ]: 0 : } else if (js_mr_key->actions[i].type == RTE_FLOW_ACTION_TYPE_PROG) {
618 : : int ret;
619 : : uint32_t param_size, j;
620 : 0 : uint16_t value = 0;
621 : : json_t *ob_param, *subobject;
622 : : const char *name;
623 : :
624 : 0 : ret = cpfl_json_t_to_uint32(object, "id", &js_mr_key->actions[i].prog.id);
625 [ # # ]: 0 : if (ret < 0) {
626 : 0 : PMD_DRV_LOG(ERR, "Can not parse uint32 'id'.");
627 : 0 : goto err;
628 : : }
629 [ # # ]: 0 : if (json_object_get(object, "name")) {
630 : 0 : js_mr_key->actions[i].prog.has_name = TRUE;
631 : 0 : name = cpfl_json_t_to_string(object, "name");
632 [ # # ]: 0 : if (!name) {
633 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'name'.");
634 : 0 : goto err;
635 : : }
636 [ # # ]: 0 : if (strlen(name) > CPFL_JS_STR_SIZE - 1) {
637 : 0 : PMD_DRV_LOG(ERR, "The 'name' is too long.");
638 : 0 : goto err;
639 : : }
640 : 0 : strncpy(js_mr_key->actions[i].prog.name, name,
641 : : CPFL_JS_STR_SIZE - 1);
642 : : }
643 : :
644 : 0 : ob_param = json_object_get(object, "parameters");
645 : 0 : param_size = json_array_size(ob_param);
646 : 0 : js_mr_key->actions[i].prog.param_size = param_size;
647 [ # # ]: 0 : for (j = 0; j < param_size; j++) {
648 : 0 : subobject = json_array_get(ob_param, j);
649 : 0 : ret = cpfl_json_t_to_uint16(subobject, "index", &value);
650 [ # # ]: 0 : if (ret < 0) {
651 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'index'.");
652 : 0 : goto err;
653 : : }
654 : 0 : js_mr_key->actions[i].prog.params[j].index = value;
655 [ # # ]: 0 : if (json_object_get(subobject, "name")) {
656 : 0 : js_mr_key->actions[i].prog.params[j].has_name = TRUE;
657 : 0 : name = cpfl_json_t_to_string(subobject, "name");
658 [ # # ]: 0 : if (!name) {
659 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'name'.");
660 : 0 : goto err;
661 : : }
662 [ # # ]: 0 : if (strlen(name) > CPFL_JS_STR_SIZE - 1) {
663 : 0 : PMD_DRV_LOG(ERR, "The 'name' is too long.");
664 : 0 : goto err;
665 : : }
666 : 0 : strncpy(js_mr_key->actions[i].prog.params[j].name, name,
667 : : CPFL_JS_STR_SIZE - 1);
668 : : }
669 : 0 : ret = cpfl_json_t_to_uint16(subobject, "size", &value);
670 [ # # ]: 0 : if (ret < 0) {
671 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'size'.");
672 : 0 : goto err;
673 : : }
674 : 0 : js_mr_key->actions[i].prog.params[j].size = value;
675 : : }
676 : :
677 [ # # ]: 0 : } else if (js_mr_key->actions[i].type != RTE_FLOW_ACTION_TYPE_VXLAN_DECAP) {
678 : 0 : PMD_DRV_LOG(ERR, "not support this type: %d.", js_mr_key->actions[i].type);
679 : 0 : goto err;
680 : : }
681 : : }
682 : :
683 : : return 0;
684 : :
685 : 0 : err:
686 : 0 : rte_free(js_mr_key->actions);
687 : 0 : return -EINVAL;
688 : : }
689 : :
690 : : static int
691 : 0 : cpfl_flow_js_mr_layout(json_t *ob_layouts, struct cpfl_flow_js_mr_action_mod *js_mod)
692 : : {
693 : : int len, i;
694 : :
695 : 0 : len = json_array_size(ob_layouts);
696 : 0 : js_mod->layout_size = len;
697 [ # # ]: 0 : if (len == 0)
698 : : return 0;
699 : :
700 [ # # ]: 0 : for (i = 0; i < len; i++) {
701 : : json_t *object;
702 : 0 : int index = 0, size = 0, offset = 0;
703 : : int ret;
704 : : const char *hint;
705 : :
706 : 0 : object = json_array_get(ob_layouts, i);
707 : 0 : ret = cpfl_json_t_to_int(object, "index", &index);
708 [ # # ]: 0 : if (ret < 0) {
709 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'index'.");
710 : 0 : goto err;
711 : : }
712 : 0 : js_mod->layout[i].index = index;
713 : 0 : ret = cpfl_json_t_to_int(object, "size", &size);
714 [ # # ]: 0 : if (ret < 0) {
715 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'size'.");
716 : 0 : goto err;
717 : : }
718 : 0 : js_mod->layout[i].size = size;
719 : 0 : ret = cpfl_json_t_to_int(object, "offset", &offset);
720 [ # # ]: 0 : if (ret < 0) {
721 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'offset'.");
722 : 0 : goto err;
723 : : }
724 : 0 : js_mod->layout[i].offset = offset;
725 : 0 : hint = cpfl_json_t_to_string(object, "hint");
726 [ # # ]: 0 : if (!hint) {
727 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'hint'.");
728 : 0 : goto err;
729 : : }
730 [ # # ]: 0 : if (strlen(hint) > CPFL_JS_STR_SIZE - 1) {
731 : 0 : PMD_DRV_LOG(ERR, "The 'hint' is too long.");
732 : 0 : goto err;
733 : : }
734 : 0 : strncpy(js_mod->layout[i].hint, hint, CPFL_JS_STR_SIZE - 1);
735 : : }
736 : :
737 : : return 0;
738 : :
739 : : err:
740 : 0 : rte_free(js_mod->layout);
741 : 0 : return -EINVAL;
742 : : }
743 : :
744 : : static int
745 : 0 : cpfl_flow_js_mr_content(json_t *ob_content, struct cpfl_flow_js_mr_action_mod *js_mod)
746 : : {
747 : : int ret, len, i;
748 : : json_t *ob_field;
749 : :
750 [ # # ]: 0 : if (!ob_content)
751 : : return 0;
752 : :
753 : 0 : js_mod->is_content = TRUE;
754 : 0 : ret = cpfl_json_t_to_uint16(ob_content, "size", &js_mod->content.size);
755 [ # # ]: 0 : if (ret < 0) {
756 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'size'.");
757 : 0 : return -EINVAL;
758 : : }
759 : :
760 : 0 : ob_field = json_object_get(ob_content, "fields");
761 : 0 : len = json_array_size(ob_field);
762 : 0 : js_mod->content.field_size = len;
763 [ # # ]: 0 : if (len == 0)
764 : : return 0;
765 : :
766 [ # # ]: 0 : for (i = 0; i < len; i++) {
767 : : json_t *object;
768 : 0 : uint16_t start = 0, width = 0, index = 0;
769 : : const char *type;
770 : :
771 : 0 : object = json_array_get(ob_field, i);
772 : 0 : type = cpfl_json_t_to_string(object, "type");
773 [ # # ]: 0 : if (!type) {
774 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'type'.");
775 : 0 : goto err;
776 : : }
777 [ # # ]: 0 : if (strlen(type) > CPFL_JS_STR_SIZE - 1) {
778 : 0 : PMD_DRV_LOG(ERR, "The 'type' is too long.");
779 : 0 : goto err;
780 : : }
781 : 0 : strncpy(js_mod->content.fields[i].type, type, CPFL_JS_STR_SIZE - 1);
782 : 0 : ret = cpfl_json_t_to_uint16(object, "start", &start);
783 [ # # ]: 0 : if (ret < 0) {
784 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'start'.");
785 : 0 : goto err;
786 : : }
787 : 0 : js_mod->content.fields[i].start = start;
788 : 0 : ret = cpfl_json_t_to_uint16(object, "width", &width);
789 [ # # ]: 0 : if (ret < 0) {
790 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'width'.");
791 : 0 : goto err;
792 : : }
793 : 0 : js_mod->content.fields[i].width = width;
794 [ # # ]: 0 : if (strcmp(type, "parameter") == 0) {
795 : 0 : ret = cpfl_json_t_to_uint16(object, "index", &index);
796 [ # # ]: 0 : if (ret < 0) {
797 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'index'.");
798 : 0 : goto err;
799 : : }
800 : 0 : js_mod->content.fields[i].index = index;
801 [ # # ]: 0 : } else if (strcmp(type, "constant") == 0) {
802 : : json_t *ob_value, *subobj;
803 : : int value_len, j;
804 : :
805 : 0 : ob_value = json_object_get(object, "value");
806 : 0 : value_len = json_array_size(ob_value);
807 [ # # ]: 0 : for (j = 0; j < value_len; j++) {
808 : 0 : subobj = json_array_get(ob_value, j);
809 : 0 : js_mod->content.fields[i].value[j] =
810 : 0 : (uint8_t)json_integer_value(subobj);
811 : : }
812 : : }
813 : : }
814 : :
815 : : return 0;
816 : :
817 : : err:
818 : 0 : return -EINVAL;
819 : : }
820 : :
821 : : static int
822 : 0 : cpfl_flow_js_mr_action(json_t *ob_mr_act, struct cpfl_flow_js_mr_action *js_mr_act)
823 : : {
824 : : json_t *ob_data;
825 : : const char *type;
826 : :
827 : : /* mr->action->type */
828 : 0 : type = cpfl_json_t_to_string(ob_mr_act, "type");
829 [ # # ]: 0 : if (!type) {
830 : 0 : PMD_DRV_LOG(ERR, "Can not parse string 'type'.");
831 : 0 : return -EINVAL;
832 : : }
833 : : /* mr->action->data */
834 : 0 : ob_data = json_object_get(ob_mr_act, "data");
835 [ # # ]: 0 : if (strcmp(type, "mod") == 0) {
836 : : json_t *ob_layouts, *ob_content;
837 : 0 : uint16_t profile = 0;
838 : : int ret;
839 : :
840 : 0 : js_mr_act->type = CPFL_JS_MR_ACTION_TYPE_MOD;
841 : 0 : ret = cpfl_json_t_to_uint16(ob_data, "profile", &profile);
842 [ # # ]: 0 : if (ret < 0) {
843 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'profile'.");
844 : 0 : return -EINVAL;
845 : : }
846 : 0 : js_mr_act->mod.prof = profile;
847 : 0 : ob_layouts = json_object_get(ob_data, "layout");
848 : 0 : ret = cpfl_flow_js_mr_layout(ob_layouts, &js_mr_act->mod);
849 [ # # ]: 0 : if (ret < 0) {
850 : 0 : PMD_DRV_LOG(ERR, "Can not parse layout.");
851 : 0 : return ret;
852 : : }
853 : 0 : ob_content = json_object_get(ob_data, "content");
854 : 0 : ret = cpfl_flow_js_mr_content(ob_content, &js_mr_act->mod);
855 [ # # ]: 0 : if (ret < 0) {
856 : 0 : PMD_DRV_LOG(ERR, "Can not parse 'content'.");
857 : 0 : return ret;
858 : : }
859 : : } else {
860 : 0 : PMD_DRV_LOG(ERR, "not support this type: %s.", type);
861 : 0 : return -EINVAL;
862 : : }
863 : :
864 : 0 : return 0;
865 : : }
866 : :
867 : : /**
868 : : * The modifications object array defines a set of rules for the PMD to match rte_flow
869 : : * modification actions and translate them into the Modification profile. This object
870 : : * is optional.
871 : : */
872 : : static int
873 : 0 : cpfl_flow_js_mod_rule(json_t *ob_root, struct cpfl_flow_js_parser *parser)
874 : : {
875 : : json_t *ob_mrs;
876 : : int i, len;
877 : :
878 : 0 : ob_mrs = json_object_get(ob_root, "modifications");
879 [ # # ]: 0 : if (!ob_mrs) {
880 : 0 : PMD_DRV_LOG(INFO, "The modifications is optional.");
881 : 0 : return 0;
882 : : }
883 : 0 : len = json_array_size(ob_mrs);
884 [ # # ]: 0 : if (len == 0)
885 : : return 0;
886 : 0 : parser->mr_size = len;
887 : 0 : parser->modifications = rte_malloc(NULL, sizeof(struct cpfl_flow_js_mr) * len, 0);
888 [ # # ]: 0 : if (!parser->modifications) {
889 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
890 : 0 : return -ENOMEM;
891 : : }
892 [ # # ]: 0 : for (i = 0; i < len; i++) {
893 : : int ret;
894 : : json_t *object, *ob_mr_key, *ob_mr_action, *ob_mr_key_action;
895 : :
896 : 0 : object = json_array_get(ob_mrs, i);
897 : : /* mr->key */
898 : 0 : ob_mr_key = json_object_get(object, "key");
899 : : /* mr->key->actions */
900 : 0 : ob_mr_key_action = json_object_get(ob_mr_key, "actions");
901 : 0 : ret = cpfl_flow_js_mr_key(ob_mr_key_action, &parser->modifications[i].key);
902 [ # # ]: 0 : if (ret < 0) {
903 : 0 : PMD_DRV_LOG(ERR, "parse mr_key failed.");
904 : 0 : goto err;
905 : : }
906 : : /* mr->action */
907 : 0 : ob_mr_action = json_object_get(object, "action");
908 : 0 : ret = cpfl_flow_js_mr_action(ob_mr_action, &parser->modifications[i].action);
909 [ # # ]: 0 : if (ret < 0) {
910 : 0 : PMD_DRV_LOG(ERR, "parse mr_action failed.");
911 : 0 : goto err;
912 : : }
913 : : }
914 : :
915 : : return 0;
916 : :
917 : 0 : err:
918 : 0 : rte_free(parser->modifications);
919 : 0 : return -EINVAL;
920 : : }
921 : :
922 : : static int
923 : 0 : cpfl_parser_init(json_t *ob_root, struct cpfl_flow_js_parser *parser)
924 : : {
925 : : int ret = 0;
926 : :
927 : 0 : ret = cpfl_flow_js_pattern_rule(ob_root, parser);
928 [ # # ]: 0 : if (ret < 0) {
929 : 0 : PMD_DRV_LOG(ERR, "parse pattern_rule failed.");
930 : 0 : return ret;
931 : : }
932 : 0 : ret = cpfl_flow_js_mod_rule(ob_root, parser);
933 [ # # ]: 0 : if (ret < 0) {
934 : 0 : PMD_DRV_LOG(ERR, "parse mod_rule failed.");
935 : 0 : return ret;
936 : : }
937 : :
938 : : return 0;
939 : : }
940 : :
941 : : int
942 : 0 : cpfl_parser_create(struct cpfl_flow_js_parser **flow_parser, const char *filename)
943 : : {
944 : : struct cpfl_flow_js_parser *parser;
945 : : json_error_t json_error;
946 : : json_t *root;
947 : : int ret;
948 : :
949 : 0 : parser = rte_zmalloc("flow_parser", sizeof(struct cpfl_flow_js_parser), 0);
950 [ # # ]: 0 : if (!parser) {
951 : 0 : PMD_DRV_LOG(ERR, "Not enough memory to create flow parser.");
952 : 0 : return -ENOMEM;
953 : : }
954 : 0 : root = json_load_file(filename, 0, &json_error);
955 [ # # ]: 0 : if (!root) {
956 : 0 : PMD_DRV_LOG(ERR, "Bad JSON file \"%s\": %s", filename, json_error.text);
957 : 0 : goto free_parser;
958 : : }
959 : 0 : ret = cpfl_parser_init(root, parser);
960 [ # # ]: 0 : if (ret < 0) {
961 : 0 : PMD_DRV_LOG(ERR, "parser init failed.");
962 : 0 : goto free_parser;
963 : : }
964 : 0 : *flow_parser = parser;
965 : 0 : json_decref(root);
966 : :
967 : 0 : return 0;
968 : 0 : free_parser:
969 : 0 : rte_free(parser);
970 : 0 : return -EINVAL;
971 : : }
972 : :
973 : : static void
974 : : cpfl_parser_free_pr_action(struct cpfl_flow_js_pr_action *pr_act)
975 : : {
976 : 0 : if (pr_act->type == CPFL_JS_PR_ACTION_TYPE_SEM)
977 : 0 : rte_free(pr_act->sem.fv);
978 : : }
979 : :
980 : : int
981 : 0 : cpfl_parser_destroy(struct cpfl_flow_js_parser *parser)
982 : : {
983 : : int i, j;
984 : :
985 [ # # ]: 0 : if (!parser)
986 : : return 0;
987 : :
988 [ # # ]: 0 : for (i = 0; i < parser->pr_size; i++) {
989 : 0 : struct cpfl_flow_js_pr *pattern = &parser->patterns[i];
990 : :
991 [ # # ]: 0 : for (j = 0; j < pattern->key.proto_size; j++)
992 : 0 : rte_free(pattern->key.protocols[j].fields);
993 : 0 : rte_free(pattern->key.protocols);
994 : 0 : rte_free(pattern->key.attributes);
995 : :
996 [ # # ]: 0 : for (j = 0; j < pattern->actions_size; j++) {
997 : : struct cpfl_flow_js_pr_action *pr_act;
998 : :
999 [ # # ]: 0 : pr_act = &pattern->actions[j];
1000 : : cpfl_parser_free_pr_action(pr_act);
1001 : : }
1002 : 0 : rte_free(pattern->actions);
1003 : : }
1004 : 0 : rte_free(parser->patterns);
1005 [ # # ]: 0 : for (i = 0; i < parser->mr_size; i++) {
1006 : 0 : struct cpfl_flow_js_mr *mr = &parser->modifications[i];
1007 : :
1008 : 0 : rte_free(mr->key.actions);
1009 : : }
1010 : 0 : rte_free(parser->modifications);
1011 : 0 : rte_free(parser);
1012 : :
1013 : 0 : return 0;
1014 : : }
1015 : :
1016 : : static int
1017 : : cpfl_get_items_length(const struct rte_flow_item *items)
1018 : 0 : {
1019 : : int length = 0;
1020 : : const struct rte_flow_item *item = items;
1021 : :
1022 [ # # # # : 0 : while ((item + length++)->type != RTE_FLOW_ITEM_TYPE_END)
# # # # ]
1023 : 0 : continue;
1024 : : return length;
1025 : : }
1026 : :
1027 : : static int
1028 : : cpfl_get_actions_length(const struct rte_flow_action *actions)
1029 : 0 : {
1030 : : int length = 0;
1031 : : const struct rte_flow_action *action = actions;
1032 : :
1033 [ # # ]: 0 : while ((action + length++)->type != RTE_FLOW_ACTION_TYPE_END)
1034 : 0 : continue;
1035 : : return length;
1036 : : }
1037 : :
1038 : : static int
1039 : 0 : cpfl_parse_fv_protocol(struct cpfl_flow_js_fv *js_fv, const struct rte_flow_item *items,
1040 : : uint16_t offset, uint8_t *fv)
1041 : : {
1042 : : uint16_t v_layer, v_offset, v_mask;
1043 : : enum rte_flow_item_type v_header;
1044 : : int j, layer, length;
1045 : : uint16_t temp_fv;
1046 : :
1047 : : length = cpfl_get_items_length(items);
1048 : 0 : v_layer = js_fv->proto.layer;
1049 : 0 : v_header = js_fv->proto.header;
1050 : 0 : v_offset = js_fv->proto.offset;
1051 : 0 : v_mask = js_fv->proto.mask;
1052 : : layer = 0;
1053 [ # # ]: 0 : for (j = 0; j < length - 1; j++) {
1054 [ # # ]: 0 : if (items[j].type == v_header) {
1055 [ # # ]: 0 : if (layer == v_layer) {
1056 : : /* copy out 16 bits from offset */
1057 : : const uint8_t *pointer;
1058 : :
1059 : 0 : pointer = &(((const uint8_t *)(items[j].spec))[v_offset]);
1060 : 0 : temp_fv = ntohs((*((const uint16_t *)pointer)) & v_mask);
1061 : 0 : fv[2 * offset] = (uint8_t)(temp_fv >> 8);
1062 : 0 : fv[2 * offset + 1] = (uint8_t)(temp_fv & 0x00ff);
1063 : 0 : break;
1064 : : }
1065 : 0 : layer++;
1066 : : }
1067 : : }
1068 : :
1069 : 0 : return 0;
1070 : : }
1071 : :
1072 : : static int
1073 : 0 : cpfl_parse_fieldvectors(struct cpfl_itf *itf, struct cpfl_flow_js_fv *js_fvs, int size,
1074 : : uint8_t *fv, const struct rte_flow_item *items)
1075 : : {
1076 : : int i, ret;
1077 : :
1078 [ # # ]: 0 : for (i = 0; i < size; i++) {
1079 : : uint16_t offset, temp_fv, value_int;
1080 : : enum cpfl_flow_js_fv_type type;
1081 : : struct cpfl_flow_js_fv *js_fv;
1082 : :
1083 : 0 : js_fv = &js_fvs[i];
1084 : 0 : offset = js_fv->offset;
1085 : 0 : type = js_fv->type;
1086 [ # # ]: 0 : if (type == CPFL_FV_TYPE_IMMEDIATE) {
1087 : 0 : value_int = js_fv->immediate;
1088 : 0 : temp_fv = (value_int << 8) & 0xff00;
1089 : 0 : fv[2 * offset] = (uint8_t)(temp_fv >> 8);
1090 : 0 : fv[2 * offset + 1] = (uint8_t)(temp_fv & 0x00ff);
1091 [ # # ]: 0 : } else if (type == CPFL_FV_TYPE_METADATA) {
1092 : : uint16_t type, v_offset, mask;
1093 : :
1094 : 0 : type = js_fv->meta.type;
1095 : 0 : v_offset = js_fv->meta.offset;
1096 : 0 : mask = js_fv->meta.mask;
1097 : 0 : temp_fv = cpfl_metadata_read16(&itf->adapter->meta, type, v_offset) & mask;
1098 : 0 : fv[2 * offset] = (uint8_t)(temp_fv & 0x00ff);
1099 : 0 : fv[2 * offset + 1] = (uint8_t)(temp_fv >> 8);
1100 [ # # ]: 0 : } else if (type == CPFL_FV_TYPE_PROTOCOL) {
1101 : 0 : ret = cpfl_parse_fv_protocol(js_fv, items, offset, fv);
1102 [ # # ]: 0 : if (ret)
1103 : 0 : return ret;
1104 : : } else {
1105 : 0 : PMD_DRV_LOG(DEBUG, "not support this type: %d.", type);
1106 : 0 : return -EINVAL;
1107 : : }
1108 : : }
1109 : :
1110 : : return 0;
1111 : : }
1112 : :
1113 : : static int
1114 : 0 : cpfl_parse_pr_actions(struct cpfl_itf *itf,
1115 : : struct cpfl_flow_js_pr_action *actions,
1116 : : int size,
1117 : : const struct rte_flow_item *items,
1118 : : const struct rte_flow_attr *attr,
1119 : : struct cpfl_flow_pr_action *pr_action)
1120 : : {
1121 : : int i, ret;
1122 : :
1123 [ # # ]: 0 : for (i = 0; i < size; i++) {
1124 : : struct cpfl_flow_js_pr_action *pr_act;
1125 : : enum cpfl_flow_pr_action_type type;
1126 : :
1127 : 0 : pr_act = &actions[i];
1128 : : /* pr->actions->type */
1129 : 0 : type = pr_act->type;
1130 : : /* pr->actions->data */
1131 [ # # # # ]: 0 : if (attr->group == 1 && type == CPFL_JS_PR_ACTION_TYPE_SEM) {
1132 : : struct cpfl_flow_js_pr_action_sem *sem = &pr_act->sem;
1133 : :
1134 : 0 : pr_action->type = CPFL_JS_PR_ACTION_TYPE_SEM;
1135 : 0 : pr_action->sem.prof = sem->prof;
1136 : 0 : pr_action->sem.subprof = sem->subprof;
1137 : 0 : pr_action->sem.keysize = sem->keysize;
1138 : 0 : memset(pr_action->sem.cpfl_flow_pr_fv, 0,
1139 : : sizeof(pr_action->sem.cpfl_flow_pr_fv));
1140 : 0 : ret = cpfl_parse_fieldvectors(itf, sem->fv, sem->fv_size,
1141 : : pr_action->sem.cpfl_flow_pr_fv, items);
1142 : 0 : return ret;
1143 [ # # ]: 0 : } else if (attr->group > 4 || attr->group == 0) {
1144 : : return -EPERM;
1145 : : }
1146 : : }
1147 : :
1148 : : return 0;
1149 : : }
1150 : :
1151 : : static int
1152 : 0 : cpfl_check_eth_mask(const char *mask, struct rte_ether_addr addr)
1153 : : {
1154 : : int i, ret;
1155 : : struct rte_ether_addr mask_bytes;
1156 : :
1157 : 0 : ret = rte_ether_unformat_addr(mask, &mask_bytes);
1158 [ # # ]: 0 : if (ret < 0) {
1159 : 0 : PMD_DRV_LOG(ERR, "translate mac address from string to rte_ether_addr failed.");
1160 : 0 : return -EINVAL;
1161 : : }
1162 : : /* validate eth mask addr if match */
1163 [ # # ]: 0 : for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) {
1164 [ # # ]: 0 : if (mask_bytes.addr_bytes[i] != addr.addr_bytes[i])
1165 : : return -EINVAL;
1166 : : }
1167 : :
1168 : : return 0;
1169 : : }
1170 : :
1171 : : static int
1172 : : cpfl_check_ipv4_mask(const char *mask, rte_be32_t addr)
1173 : : {
1174 : : uint32_t out_addr;
1175 : :
1176 : : /* 0: success; -EINVAL: invalid; -ENOTSUP: fail */
1177 : 0 : int ret = inet_pton(AF_INET, mask, &out_addr);
1178 : :
1179 [ # # # # ]: 0 : if (ret < 0)
1180 : : return -EINVAL;
1181 : : /* validate ipv4 mask addr if match */
1182 [ # # # # ]: 0 : if (out_addr != addr)
1183 : : return -EINVAL;
1184 : :
1185 : : return 0;
1186 : : }
1187 : :
1188 : : static int
1189 : 0 : cpfl_check_eth(struct cpfl_flow_js_pr_key_proto *proto, const struct rte_flow_item_eth *eth_mask)
1190 : : {
1191 : : int field_size, j;
1192 : : int flag_dst_addr, flag_src_addr, flag_ether_type;
1193 : : struct cpfl_flow_js_pr_key_proto_field *field;
1194 : :
1195 [ # # ]: 0 : if (!proto)
1196 : : return 0;
1197 : 0 : field_size = proto->fields_size;
1198 [ # # ]: 0 : if (field_size != 0 && !eth_mask)
1199 : : return -EINVAL;
1200 : :
1201 [ # # ]: 0 : if (field_size == 0 && eth_mask)
1202 : : return -EINVAL;
1203 : :
1204 [ # # ]: 0 : if (field_size == 0 && !eth_mask)
1205 : : return 0;
1206 : :
1207 : : flag_dst_addr = false;
1208 : : flag_src_addr = false;
1209 : : flag_ether_type = false;
1210 [ # # ]: 0 : for (j = 0; j < field_size; j++) {
1211 : : const char *name, *s_mask;
1212 : :
1213 : 0 : field = &proto->fields[j];
1214 : : /* match: rte_flow_item_eth.dst, more see Field Mapping
1215 : : */
1216 : 0 : name = field->name;
1217 : : /* match: rte_flow_item->mask */
1218 [ # # ]: 0 : if (strcmp(name, "src_addr") == 0) {
1219 : 0 : s_mask = field->mask;
1220 [ # # ]: 0 : if (cpfl_check_eth_mask(s_mask, eth_mask->src) < 0)
1221 : : return -EINVAL;
1222 : : flag_src_addr = true;
1223 [ # # ]: 0 : } else if (strcmp(name, "dst_addr") == 0) {
1224 : 0 : s_mask = field->mask;
1225 [ # # ]: 0 : if (cpfl_check_eth_mask(s_mask, eth_mask->dst) < 0)
1226 : : return -EINVAL;
1227 : : flag_dst_addr = true;
1228 [ # # ]: 0 : } else if (strcmp(name, "ether_type") == 0) {
1229 : 0 : uint16_t mask = (uint16_t)field->mask_32b;
1230 : :
1231 [ # # ]: 0 : if (mask != eth_mask->type)
1232 : : return -EINVAL;
1233 : : flag_ether_type = true;
1234 : : } else {
1235 : : /* TODO: more type... */
1236 : 0 : PMD_DRV_LOG(ERR, "not support this name.");
1237 : 0 : return -EINVAL;
1238 : : }
1239 : : }
1240 [ # # ]: 0 : if (!flag_src_addr) {
1241 [ # # ]: 0 : if (strcmp((const char *)eth_mask->src.addr_bytes, "\x00\x00\x00\x00\x00\x00") != 0)
1242 : : return -EINVAL;
1243 : : }
1244 [ # # ]: 0 : if (!flag_dst_addr) {
1245 [ # # ]: 0 : if (strcmp((const char *)eth_mask->dst.addr_bytes, "\x00\x00\x00\x00\x00\x00") != 0)
1246 : : return -EINVAL;
1247 : : }
1248 [ # # ]: 0 : if (!flag_ether_type) {
1249 [ # # ]: 0 : if (eth_mask->hdr.ether_type != (rte_be16_t)0)
1250 : 0 : return -EINVAL;
1251 : : }
1252 : :
1253 : : return 0;
1254 : : }
1255 : :
1256 : : static int
1257 : 0 : cpfl_check_ipv4(struct cpfl_flow_js_pr_key_proto *proto, const struct rte_flow_item_ipv4 *ipv4_mask)
1258 : : {
1259 : : int field_size, j;
1260 : : int flag_next_proto_id, flag_src_addr, flag_dst_addr;
1261 : : struct cpfl_flow_js_pr_key_proto_field *field;
1262 : :
1263 [ # # ]: 0 : if (!proto)
1264 : : return 0;
1265 : :
1266 : 0 : field_size = proto->fields_size;
1267 [ # # ]: 0 : if (field_size != 0 && !ipv4_mask)
1268 : : return -EINVAL;
1269 : :
1270 [ # # ]: 0 : if (field_size == 0 && ipv4_mask)
1271 : : return -EINVAL;
1272 : :
1273 [ # # ]: 0 : if (field_size == 0 && !ipv4_mask)
1274 : : return 0;
1275 : :
1276 : : flag_dst_addr = false;
1277 : : flag_src_addr = false;
1278 : : flag_next_proto_id = false;
1279 [ # # ]: 0 : for (j = 0; j < field_size; j++) {
1280 : : const char *name;
1281 : :
1282 : 0 : field = &proto->fields[j];
1283 : 0 : name = field->name;
1284 [ # # ]: 0 : if (strcmp(name, "src_addr") == 0) {
1285 : : const char *mask;
1286 : :
1287 : 0 : mask = field->mask;
1288 : 0 : if (cpfl_check_ipv4_mask(mask, ipv4_mask->hdr.src_addr) < 0)
1289 : 0 : return -EINVAL;
1290 : : flag_src_addr = true;
1291 [ # # ]: 0 : } else if (strcmp(name, "dst_addr") == 0) {
1292 : : const char *mask;
1293 : :
1294 : 0 : mask = field->mask;
1295 : 0 : if (cpfl_check_ipv4_mask(mask, ipv4_mask->hdr.dst_addr) < 0)
1296 : 0 : return -EINVAL;
1297 : : flag_dst_addr = true;
1298 [ # # ]: 0 : } else if (strcmp(name, "next_proto_id") == 0) {
1299 : : uint8_t mask;
1300 : :
1301 : 0 : mask = (uint8_t)field->mask_32b;
1302 [ # # ]: 0 : if (mask != ipv4_mask->hdr.next_proto_id)
1303 : : return -EINVAL;
1304 : : flag_next_proto_id = true;
1305 : : } else {
1306 : 0 : PMD_DRV_LOG(ERR, "not support this name.");
1307 : 0 : return -EINVAL;
1308 : : }
1309 : : }
1310 [ # # ]: 0 : if (!flag_src_addr) {
1311 [ # # ]: 0 : if (ipv4_mask->hdr.src_addr != (rte_be32_t)0)
1312 : : return -EINVAL;
1313 : : }
1314 [ # # ]: 0 : if (!flag_dst_addr) {
1315 [ # # ]: 0 : if (ipv4_mask->hdr.dst_addr != (rte_be32_t)0)
1316 : : return -EINVAL;
1317 : : }
1318 [ # # ]: 0 : if (!flag_next_proto_id) {
1319 [ # # ]: 0 : if (ipv4_mask->hdr.next_proto_id != (uint8_t)0)
1320 : 0 : return -EINVAL;
1321 : : }
1322 : :
1323 : : return 0;
1324 : : }
1325 : :
1326 : : static int
1327 : 0 : cpfl_check_tcp(struct cpfl_flow_js_pr_key_proto *proto, const struct rte_flow_item_tcp *tcp_mask)
1328 : : {
1329 : : int field_size, j;
1330 : : int flag_src_port, flag_dst_port;
1331 : : struct cpfl_flow_js_pr_key_proto_field *field;
1332 : :
1333 [ # # ]: 0 : if (!proto)
1334 : : return 0;
1335 : :
1336 : 0 : field_size = proto->fields_size;
1337 [ # # ]: 0 : if (field_size != 0 && !tcp_mask)
1338 : : return -EINVAL;
1339 : :
1340 [ # # ]: 0 : if (field_size == 0 && tcp_mask)
1341 : : return -EINVAL;
1342 : :
1343 [ # # ]: 0 : if (field_size == 0 && !tcp_mask)
1344 : : return 0;
1345 : :
1346 : : flag_src_port = false;
1347 : : flag_dst_port = false;
1348 [ # # ]: 0 : for (j = 0; j < field_size; j++) {
1349 : : const char *name;
1350 : : uint16_t mask;
1351 : :
1352 : 0 : field = &proto->fields[j];
1353 : 0 : name = field->name;
1354 : 0 : mask = (uint16_t)field->mask_32b;
1355 [ # # ]: 0 : if (strcmp(name, "src_port") == 0) {
1356 [ # # ]: 0 : if (tcp_mask->hdr.src_port != mask)
1357 : : return -EINVAL;
1358 : : flag_src_port = true;
1359 [ # # ]: 0 : } else if (strcmp(name, "dst_port") == 0) {
1360 [ # # ]: 0 : if (tcp_mask->hdr.dst_port != mask)
1361 : : return -EINVAL;
1362 : : flag_dst_port = true;
1363 : : } else {
1364 : 0 : PMD_DRV_LOG(ERR, "not support this name.");
1365 : 0 : return -EINVAL;
1366 : : }
1367 : : }
1368 [ # # ]: 0 : if (!flag_src_port) {
1369 [ # # ]: 0 : if (tcp_mask->hdr.src_port != (rte_be16_t)0)
1370 : : return -EINVAL;
1371 : : }
1372 [ # # ]: 0 : if (!flag_dst_port) {
1373 [ # # ]: 0 : if (tcp_mask->hdr.dst_port != (rte_be16_t)0)
1374 : 0 : return -EINVAL;
1375 : : }
1376 : :
1377 : : return 0;
1378 : : }
1379 : :
1380 : : static int
1381 : 0 : cpfl_check_udp(struct cpfl_flow_js_pr_key_proto *proto, const struct rte_flow_item_udp *udp_mask)
1382 : : {
1383 : : int field_size, j;
1384 : : bool flag_src_port, flag_dst_port;
1385 : : struct cpfl_flow_js_pr_key_proto_field *field;
1386 : :
1387 [ # # ]: 0 : if (!proto)
1388 : : return 0;
1389 : 0 : field_size = proto->fields_size;
1390 [ # # ]: 0 : if (field_size != 0 && !udp_mask)
1391 : : return -EINVAL;
1392 [ # # ]: 0 : if (field_size == 0 && udp_mask)
1393 : : return -EINVAL;
1394 [ # # ]: 0 : if (field_size == 0 && !udp_mask)
1395 : : return 0;
1396 : : flag_src_port = false;
1397 : : flag_dst_port = false;
1398 [ # # ]: 0 : for (j = 0; j < field_size; j++) {
1399 : : const char *name;
1400 : : uint16_t mask;
1401 : :
1402 : 0 : field = &proto->fields[j];
1403 : : /* match: rte_flow_item_eth.dst */
1404 : 0 : name = field->name; /* match: rte_flow_item->mask */
1405 : 0 : mask = (uint16_t)field->mask_32b;
1406 [ # # ]: 0 : if (strcmp(name, "src_port") == 0) {
1407 [ # # ]: 0 : if (udp_mask->hdr.src_port != mask)
1408 : : return -EINVAL;
1409 : : flag_src_port = true;
1410 [ # # ]: 0 : } else if (strcmp(name, "dst_port") == 0) {
1411 [ # # ]: 0 : if (udp_mask->hdr.dst_port != mask)
1412 : : return -EINVAL;
1413 : : flag_dst_port = true;
1414 : : } else {
1415 : 0 : PMD_DRV_LOG(ERR, "not support this name: %s.", name);
1416 : 0 : return -EINVAL;
1417 : : }
1418 : : }
1419 [ # # ]: 0 : if (!flag_src_port) {
1420 [ # # ]: 0 : if (udp_mask->hdr.src_port != (rte_be16_t)0)
1421 : : return -EINVAL;
1422 : : }
1423 [ # # ]: 0 : if (!flag_dst_port) {
1424 [ # # ]: 0 : if (udp_mask->hdr.dst_port != (rte_be16_t)0)
1425 : 0 : return -EINVAL;
1426 : : }
1427 : :
1428 : : return 0;
1429 : : }
1430 : :
1431 : : static int
1432 : 0 : cpfl_check_vxlan(struct cpfl_flow_js_pr_key_proto *proto,
1433 : : const struct rte_flow_item_vxlan *vxlan_mask)
1434 : : {
1435 : : int field_size, j;
1436 : : struct cpfl_flow_js_pr_key_proto_field *field;
1437 : :
1438 [ # # ]: 0 : if (!proto)
1439 : : return 0;
1440 : 0 : field_size = proto->fields_size;
1441 [ # # ]: 0 : if (field_size != 0 && !vxlan_mask)
1442 : : return -EINVAL;
1443 [ # # ]: 0 : if (field_size == 0 && vxlan_mask)
1444 : : return -EINVAL;
1445 [ # # ]: 0 : if (field_size == 0 && !vxlan_mask)
1446 : : return 0;
1447 [ # # ]: 0 : for (j = 0; j < field_size; j++) {
1448 : : const char *name;
1449 : : int64_t mask;
1450 : :
1451 : 0 : field = &proto->fields[j];
1452 : 0 : name = field->name;
1453 : : /* match: rte_flow_item->mask */
1454 : 0 : mask = (int64_t)field->mask_32b;
1455 [ # # ]: 0 : if (strcmp(name, "vx_vni") == 0) {
1456 [ # # ]: 0 : if ((int64_t)RTE_BE32(vxlan_mask->hdr.vx_vni) != mask)
1457 : : return -EINVAL;
1458 : : } else {
1459 : 0 : PMD_DRV_LOG(ERR, "not support this name.");
1460 : 0 : return -EINVAL;
1461 : : }
1462 : : }
1463 : :
1464 : : return 0;
1465 : : }
1466 : :
1467 : : static int
1468 : : cpfl_check_icmp(struct cpfl_flow_js_pr_key_proto *proto, const struct rte_flow_item_icmp *icmp_mask)
1469 : : {
1470 : : int field_size;
1471 : :
1472 : : if (!proto)
1473 : : return 0;
1474 : 0 : field_size = proto->fields_size;
1475 : 0 : if ((field_size != 0 && !icmp_mask) || (field_size == 0 && icmp_mask))
1476 : : return -EINVAL;
1477 : :
1478 : : return 0;
1479 : : }
1480 : :
1481 : : static int
1482 : 0 : cpfl_check_pattern_key_proto(struct cpfl_flow_js_pr_key_proto *protocols,
1483 : : int proto_size,
1484 : : const struct rte_flow_item *items)
1485 : : {
1486 : : int i, length;
1487 : : int j = 0;
1488 : :
1489 : : length = cpfl_get_items_length(items);
1490 [ # # ]: 0 : if (proto_size > length - 1)
1491 : : return -EINVAL;
1492 [ # # ]: 0 : for (i = 0; i < proto_size; i++) {
1493 : : struct cpfl_flow_js_pr_key_proto *key_proto;
1494 : : enum rte_flow_item_type type;
1495 : :
1496 : 0 : key_proto = &protocols[i];
1497 : : /* pr->key->proto->type */
1498 : 0 : type = key_proto->type;
1499 : : /* pr->key->proto->fields */
1500 [ # # # # : 0 : switch (type) {
# # # ]
1501 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
1502 [ # # ]: 0 : if (items[j++].type == RTE_FLOW_ITEM_TYPE_ETH) {
1503 : : const struct rte_flow_item_eth *eth_mask;
1504 : : int ret;
1505 : :
1506 : 0 : eth_mask = (const struct rte_flow_item_eth *)items[i].mask;
1507 : 0 : ret = cpfl_check_eth(key_proto, eth_mask);
1508 [ # # ]: 0 : if (ret < 0)
1509 : 0 : return ret;
1510 : : } else {
1511 : : return -EINVAL;
1512 : : }
1513 : : break;
1514 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
1515 [ # # ]: 0 : if (items[j++].type == RTE_FLOW_ITEM_TYPE_IPV4) {
1516 : : const struct rte_flow_item_ipv4 *ipv4_mask;
1517 : : int ret;
1518 : :
1519 : 0 : ipv4_mask = (const struct rte_flow_item_ipv4 *)items[i].mask;
1520 : 0 : ret = cpfl_check_ipv4(key_proto, ipv4_mask);
1521 [ # # ]: 0 : if (ret < 0)
1522 : 0 : return ret;
1523 : : } else {
1524 : : return -EINVAL;
1525 : : }
1526 : : break;
1527 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
1528 [ # # ]: 0 : if (items[j++].type == RTE_FLOW_ITEM_TYPE_TCP) {
1529 : : const struct rte_flow_item_tcp *tcp_mask;
1530 : : int ret;
1531 : :
1532 : 0 : tcp_mask = (const struct rte_flow_item_tcp *)items[i].mask;
1533 : 0 : ret = cpfl_check_tcp(key_proto, tcp_mask);
1534 [ # # ]: 0 : if (ret < 0)
1535 : 0 : return ret;
1536 : : } else {
1537 : : return -EINVAL;
1538 : : }
1539 : : break;
1540 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
1541 [ # # ]: 0 : if (items[j++].type == RTE_FLOW_ITEM_TYPE_UDP) {
1542 : : const struct rte_flow_item_udp *udp_mask;
1543 : : int ret;
1544 : :
1545 : 0 : udp_mask = (const struct rte_flow_item_udp *)items[i].mask;
1546 : 0 : ret = cpfl_check_udp(key_proto, udp_mask);
1547 [ # # ]: 0 : if (ret < 0)
1548 : 0 : return ret;
1549 : : } else {
1550 : : return -EINVAL;
1551 : : }
1552 : : break;
1553 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
1554 [ # # ]: 0 : if (items[j++].type == RTE_FLOW_ITEM_TYPE_VXLAN) {
1555 : : const struct rte_flow_item_vxlan *vxlan_mask;
1556 : : int ret;
1557 : :
1558 : 0 : vxlan_mask = (const struct rte_flow_item_vxlan *)items[i].mask;
1559 : 0 : ret = cpfl_check_vxlan(key_proto, vxlan_mask);
1560 [ # # ]: 0 : if (ret < 0)
1561 : 0 : return ret;
1562 : : } else {
1563 : : return -EINVAL;
1564 : : }
1565 : : break;
1566 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
1567 [ # # ]: 0 : if (items[j++].type == RTE_FLOW_ITEM_TYPE_ICMP) {
1568 : : const struct rte_flow_item_icmp *icmp_mask;
1569 : : int ret;
1570 : :
1571 [ # # ]: 0 : icmp_mask = (const struct rte_flow_item_icmp *)items[i].mask;
1572 : : ret = cpfl_check_icmp(key_proto, icmp_mask);
1573 : : if (ret < 0)
1574 : : return ret;
1575 : : } else {
1576 : : return -EINVAL;
1577 : : }
1578 : : break;
1579 : 0 : default:
1580 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %d.", type);
1581 : 0 : return -EPERM;
1582 : : }
1583 : : }
1584 [ # # ]: 0 : if (items[j].type != RTE_FLOW_ITEM_TYPE_END)
1585 : 0 : return -EINVAL;
1586 : :
1587 : : return 0;
1588 : : }
1589 : :
1590 : : static int
1591 : 0 : cpfl_check_pattern_key_attr(struct cpfl_flow_js_pr_key_attr *key_attr,
1592 : : const struct rte_flow_attr *attr)
1593 : : {
1594 [ # # ]: 0 : if (key_attr->ingress != attr->ingress) {
1595 : 0 : PMD_DRV_LOG(DEBUG, "ingress not match.");
1596 : 0 : return -EINVAL;
1597 : : }
1598 [ # # ]: 0 : if (key_attr->egress != attr->egress) {
1599 : 0 : PMD_DRV_LOG(DEBUG, "egress not match.");
1600 : 0 : return -EINVAL;
1601 : : }
1602 : :
1603 : : return 0;
1604 : : }
1605 : :
1606 : : static int
1607 : 0 : cpfl_check_pattern_key(struct cpfl_flow_js_pr *pattern,
1608 : : const struct rte_flow_item *items,
1609 : : const struct rte_flow_attr *attr)
1610 : : {
1611 : : int ret;
1612 : :
1613 : : /* pr->key */
1614 : : /* pr->key->protocols */
1615 : 0 : ret = cpfl_check_pattern_key_proto(pattern->key.protocols,
1616 : 0 : pattern->key.proto_size, items);
1617 [ # # ]: 0 : if (ret < 0)
1618 : : return -EINVAL;
1619 : : /* pr->key->attributes */
1620 : 0 : ret = cpfl_check_pattern_key_attr(pattern->key.attributes, attr);
1621 [ # # ]: 0 : if (ret < 0)
1622 : 0 : return -EINVAL;
1623 : :
1624 : : return 0;
1625 : : }
1626 : :
1627 : : /* output: struct cpfl_flow_pr_action* pr_action */
1628 : : int
1629 : 0 : cpfl_flow_parse_items(struct cpfl_itf *itf,
1630 : : struct cpfl_flow_js_parser *parser,
1631 : : const struct rte_flow_item *items,
1632 : : const struct rte_flow_attr *attr,
1633 : : struct cpfl_flow_pr_action *pr_action)
1634 : : {
1635 : : int i, size;
1636 : : struct cpfl_flow_js_pr *pattern;
1637 : :
1638 : 0 : size = parser->pr_size;
1639 [ # # ]: 0 : for (i = 0; i < size; i++) {
1640 : : int ret;
1641 : :
1642 : 0 : pattern = &parser->patterns[i];
1643 : 0 : ret = cpfl_check_pattern_key(pattern, items, attr);
1644 [ # # ]: 0 : if (ret < 0)
1645 : : continue;
1646 : : /* pr->actions */
1647 : 0 : ret = cpfl_parse_pr_actions(itf, pattern->actions, pattern->actions_size,
1648 : : items, attr, pr_action);
1649 : 0 : return ret;
1650 : : }
1651 : :
1652 : : return -EINVAL;
1653 : : }
1654 : :
1655 : : /* modifications rules */
1656 : : static int
1657 : 0 : cpfl_check_actions_vxlan_encap(struct cpfl_flow_mr_key_action_vxlan_encap *encap,
1658 : : const struct rte_flow_action *action)
1659 : : {
1660 : : const struct rte_flow_action_vxlan_encap *action_vxlan_encap;
1661 : : struct rte_flow_item *definition;
1662 : : int def_length, i, proto_size;
1663 : :
1664 : 0 : action_vxlan_encap = (const struct rte_flow_action_vxlan_encap *)action->conf;
1665 : 0 : definition = action_vxlan_encap->definition;
1666 : : def_length = cpfl_get_items_length(definition);
1667 : 0 : proto_size = encap->proto_size;
1668 [ # # ]: 0 : if (proto_size != def_length - 1) {
1669 : 0 : PMD_DRV_LOG(DEBUG, "protocols not match.");
1670 : 0 : return -EINVAL;
1671 : : }
1672 [ # # ]: 0 : for (i = 0; i < proto_size; i++) {
1673 : : enum rte_flow_item_type proto;
1674 : :
1675 : 0 : proto = encap->protocols[i];
1676 [ # # ]: 0 : if (proto == RTE_FLOW_ITEM_TYPE_VLAN) {
1677 [ # # ]: 0 : if (definition[i].type != RTE_FLOW_ITEM_TYPE_VOID) {
1678 : 0 : PMD_DRV_LOG(DEBUG, "protocols not match.");
1679 : 0 : return -EINVAL;
1680 : : }
1681 [ # # ]: 0 : } else if (proto != definition[i].type) {
1682 : 0 : PMD_DRV_LOG(DEBUG, "protocols not match.");
1683 : 0 : return -EINVAL;
1684 : : }
1685 : : }
1686 : :
1687 : : return 0;
1688 : : }
1689 : :
1690 : : static int
1691 : 0 : cpfl_parse_check_prog_action(struct cpfl_flow_js_mr_key_action *key_act,
1692 : : struct cpfl_flow_mr_key_action_prog *mr_key_prog,
1693 : : const struct rte_flow_action_prog *prog)
1694 : : {
1695 : : uint32_t k;
1696 : : bool check_name;
1697 : :
1698 : 0 : check_name = key_act->prog.has_name ? strcmp(prog->name, key_act->prog.name) == 0
1699 [ # # ]: 0 : : atol(prog->name) == key_act->prog.id;
1700 [ # # ]: 0 : if (!check_name) {
1701 : 0 : PMD_DRV_LOG(ERR, "Not support this prog type: %s.", prog->name);
1702 : 0 : return -EINVAL;
1703 : : }
1704 [ # # ]: 0 : if (key_act->prog.param_size != prog->args_num)
1705 : : return -EINVAL;
1706 [ # # ]: 0 : for (k = 0; k < key_act->prog.param_size; k++) {
1707 : 0 : const struct rte_flow_action_prog_argument *arg = &prog->args[k];
1708 : : struct cpfl_flow_js_prog_parameter *param = &key_act->prog.params[k];
1709 : :
1710 : 0 : check_name = param->has_name ? strcmp(arg->name, param->name) == 0
1711 [ # # ]: 0 : : atoi(arg->name) == param->index;
1712 [ # # # # ]: 0 : if (!check_name || arg->size != param->size)
1713 : : return -EINVAL;
1714 [ # # ]: 0 : if (param->has_name) {
1715 : 0 : mr_key_prog->has_name = TRUE;
1716 : 0 : strncpy(mr_key_prog->name[param->index], param->name,
1717 : : CPFL_JS_STR_SIZE - 1);
1718 : : }
1719 : : }
1720 : :
1721 : : return 0;
1722 : : }
1723 : :
1724 : : /* check and parse */
1725 : : static int
1726 : 0 : cpfl_parse_mr_key_action(struct cpfl_flow_js_mr_key_action *key_acts, int size,
1727 : : const struct rte_flow_action *actions,
1728 : : struct cpfl_flow_mr_key_action *mr_key_action)
1729 : : {
1730 : : int actions_length, i;
1731 : : int j = 0;
1732 : : int ret;
1733 : :
1734 : : actions_length = cpfl_get_actions_length(actions);
1735 [ # # ]: 0 : if (size > actions_length - 1)
1736 : : return -EINVAL;
1737 [ # # ]: 0 : for (i = 0; i < size; i++) {
1738 : : enum rte_flow_action_type type;
1739 : : struct cpfl_flow_js_mr_key_action *key_act;
1740 : :
1741 : 0 : key_act = &key_acts[i];
1742 : : /* mr->key->actions->type */
1743 : 0 : type = key_act->type;
1744 : : /* mr->key->actions->data */
1745 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP) {
1746 : : int proto_size, k;
1747 : : struct cpfl_flow_mr_key_action_vxlan_encap *encap;
1748 : :
1749 [ # # ]: 0 : while (j < actions_length &&
1750 [ # # ]: 0 : actions[j].type != RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP) {
1751 : 0 : j++;
1752 : : }
1753 [ # # ]: 0 : if (j >= actions_length)
1754 : : return -EINVAL;
1755 : 0 : mr_key_action->mods[i].type = RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP;
1756 : 0 : mr_key_action->mods[i].encap.action = &actions[j];
1757 : 0 : encap = &mr_key_action->mods[i].encap;
1758 : :
1759 : 0 : proto_size = key_act->encap.proto_size;
1760 : 0 : encap->proto_size = proto_size;
1761 [ # # ]: 0 : for (k = 0; k < proto_size; k++) {
1762 : : enum rte_flow_item_type proto;
1763 : :
1764 : 0 : proto = key_act->encap.protocols[k];
1765 : 0 : encap->protocols[k] = proto;
1766 : : }
1767 : 0 : ret = cpfl_check_actions_vxlan_encap(encap, &actions[j]);
1768 [ # # ]: 0 : if (ret < 0)
1769 : : return -EINVAL;
1770 : 0 : j++;
1771 [ # # ]: 0 : } else if (type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP) {
1772 [ # # ]: 0 : while (j < actions_length &&
1773 [ # # ]: 0 : actions[j].type != RTE_FLOW_ACTION_TYPE_VXLAN_DECAP) {
1774 : 0 : j++;
1775 : : }
1776 [ # # ]: 0 : if (j >= actions_length)
1777 : : return -EINVAL;
1778 : 0 : mr_key_action->mods[i].type = RTE_FLOW_ACTION_TYPE_VXLAN_DECAP;
1779 : 0 : j++;
1780 [ # # ]: 0 : } else if (type == RTE_FLOW_ACTION_TYPE_PROG) {
1781 : : const struct rte_flow_action_prog *prog;
1782 : :
1783 [ # # ]: 0 : while (j < actions_length &&
1784 [ # # ]: 0 : actions[j].type != RTE_FLOW_ACTION_TYPE_PROG) {
1785 : 0 : j++;
1786 : : }
1787 [ # # ]: 0 : if (j >= actions_length)
1788 : : return -EINVAL;
1789 : 0 : prog = actions[j].conf;
1790 : 0 : mr_key_action->prog.prog = prog;
1791 : 0 : ret = cpfl_parse_check_prog_action(key_act, &mr_key_action->prog, prog);
1792 [ # # ]: 0 : if (ret < 0)
1793 : : return -EINVAL;
1794 : : } else {
1795 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %d.", type);
1796 : 0 : return -EPERM;
1797 : : }
1798 : : }
1799 : :
1800 : : return 0;
1801 : : }
1802 : :
1803 : : /* output: uint8_t *buffer, uint16_t *byte_len */
1804 : : static int
1805 : 0 : cpfl_parse_layout(struct cpfl_flow_js_mr_layout *layouts, int layout_size,
1806 : : struct cpfl_flow_mr_key_mod *mods,
1807 : : uint8_t *buffer, uint16_t *byte_len)
1808 : : {
1809 : : int i;
1810 : : int start = 0;
1811 : :
1812 [ # # ]: 0 : for (i = 0; i < layout_size; i++) {
1813 : : int index, size, offset;
1814 : : const char *hint;
1815 : : const uint8_t *addr = NULL;
1816 : : struct cpfl_flow_mr_key_mod *temp;
1817 : : struct cpfl_flow_js_mr_layout *layout;
1818 : :
1819 : 0 : layout = &layouts[i];
1820 : : /* index links to the element of the actions array. */
1821 : 0 : index = layout->index;
1822 : 0 : size = layout->size;
1823 : 0 : offset = layout->offset;
1824 [ # # ]: 0 : if (index == -1) {
1825 : : hint = "dummpy";
1826 : 0 : start += size;
1827 : 0 : continue;
1828 : : }
1829 : 0 : hint = layout->hint;
1830 : 0 : temp = mods + index;
1831 [ # # ]: 0 : if (temp->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP) {
1832 : : const struct rte_flow_action_vxlan_encap *action_vxlan_encap;
1833 : : struct rte_flow_item *definition;
1834 : : int def_length, k;
1835 : :
1836 : 0 : action_vxlan_encap =
1837 : 0 : (const struct rte_flow_action_vxlan_encap *)temp->encap.action->conf;
1838 : 0 : definition = action_vxlan_encap->definition;
1839 : : def_length = cpfl_get_items_length(definition);
1840 [ # # ]: 0 : for (k = 0; k < def_length - 1; k++) {
1841 [ # # ]: 0 : if ((strcmp(hint, "eth") == 0 &&
1842 [ # # ]: 0 : definition[k].type == RTE_FLOW_ITEM_TYPE_ETH) ||
1843 [ # # ]: 0 : (strcmp(hint, "ipv4") == 0 &&
1844 [ # # ]: 0 : definition[k].type == RTE_FLOW_ITEM_TYPE_IPV4) ||
1845 [ # # ]: 0 : (strcmp(hint, "udp") == 0 &&
1846 [ # # ]: 0 : definition[k].type == RTE_FLOW_ITEM_TYPE_UDP) ||
1847 [ # # ]: 0 : (strcmp(hint, "tcp") == 0 &&
1848 [ # # ]: 0 : definition[k].type == RTE_FLOW_ITEM_TYPE_TCP) ||
1849 [ # # ]: 0 : (strcmp(hint, "vxlan") == 0 &&
1850 [ # # ]: 0 : definition[k].type == RTE_FLOW_ITEM_TYPE_VXLAN)) {
1851 : 0 : addr = (const uint8_t *)(definition[k].spec);
1852 [ # # ]: 0 : if (start > 255) {
1853 : 0 : *byte_len = 0;
1854 : 0 : PMD_DRV_LOG(ERR, "byte length is too long: %s",
1855 : : hint);
1856 : 0 : return -EINVAL;
1857 : : }
1858 : 0 : memcpy(buffer + start, addr + offset, size);
1859 : : break;
1860 : : } /* TODO: more hint... */
1861 : : }
1862 [ # # ]: 0 : if (k == def_length - 1) {
1863 : 0 : *byte_len = 0;
1864 : 0 : PMD_DRV_LOG(ERR, "can not find corresponding hint: %s", hint);
1865 : 0 : return -EINVAL;
1866 : : }
1867 : : } else {
1868 : 0 : *byte_len = 0;
1869 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %d.", temp->type);
1870 : 0 : return -EINVAL;
1871 : : } /* else TODO: more type... */
1872 : 0 : start += size;
1873 : : }
1874 : 0 : *byte_len = start;
1875 : :
1876 : 0 : return 0;
1877 : : }
1878 : :
1879 : : static int
1880 : 0 : cpfl_parse_content(struct cpfl_flow_js_mr_content *content,
1881 : : struct cpfl_flow_mr_key_action_prog *prog, uint8_t *buffer)
1882 : : {
1883 : : int i, j;
1884 : :
1885 [ # # ]: 0 : for (i = 0; i < content->field_size; i++) {
1886 : : uint16_t start, width, shift_bit;
1887 : :
1888 : 0 : start = content->fields[i].start / 8;
1889 : 0 : width = (content->fields[i].width + 7) / 8;
1890 : 0 : shift_bit = (8 - content->fields[i].start % 8 - content->fields[i].width % 8) % 8;
1891 : :
1892 [ # # ]: 0 : for (j = 0; j < width; j++) {
1893 : : uint8_t old_value = 0;
1894 : :
1895 [ # # ]: 0 : if (strcmp(content->fields[i].type, "parameter") == 0) {
1896 : : uint32_t k;
1897 : 0 : uint16_t index = content->fields[i].index;
1898 : 0 : const struct rte_flow_action_prog *act_prog = prog->prog;
1899 : :
1900 [ # # ]: 0 : for (k = 0; k < act_prog->args_num; k++) {
1901 : 0 : const char *name = act_prog->args[k].name;
1902 : :
1903 [ # # ]: 0 : if ((prog->has_name &&
1904 [ # # # # ]: 0 : strcmp(prog->name[index], name) == 0) ||
1905 [ # # ]: 0 : (!prog->has_name && atoi(name) == index)) {
1906 : 0 : old_value = act_prog->args[k].value[j];
1907 : 0 : break;
1908 : : }
1909 : : }
1910 [ # # ]: 0 : if (k == act_prog->args_num)
1911 : : return -EINVAL;
1912 [ # # ]: 0 : } else if (strcmp(content->fields[i].type, "constant") == 0) {
1913 : 0 : old_value = content->fields[i].value[j];
1914 : : } else {
1915 : : return -EINVAL;
1916 : : }
1917 : 0 : memset(buffer + start + j, buffer[start + j] | old_value << shift_bit, 1);
1918 : : }
1919 : : }
1920 : :
1921 : : return 0;
1922 : : }
1923 : :
1924 : : static int
1925 : 0 : cpfl_parse_mr_action(struct cpfl_flow_js_mr_action *action,
1926 : : struct cpfl_flow_mr_key_action *mr_key_action,
1927 : : struct cpfl_flow_mr_action *mr_action)
1928 : : {
1929 : : enum cpfl_flow_mr_action_type type;
1930 : :
1931 : : /* mr->action->type */
1932 : 0 : type = action->type;
1933 : : /* mr->action->data */
1934 [ # # ]: 0 : if (action->mod.is_content) {
1935 : 0 : struct cpfl_flow_js_mr_content *content = &action->mod.content;
1936 : :
1937 : 0 : mr_action->type = CPFL_JS_MR_ACTION_TYPE_MOD;
1938 : : mr_action->mod.byte_len = 0;
1939 : 0 : mr_action->mod.prof = action->mod.prof;
1940 : 0 : mr_action->mod.byte_len = content->size;
1941 : 0 : memset(mr_action->mod.data, 0, sizeof(mr_action->mod.data));
1942 : :
1943 : 0 : return cpfl_parse_content(content, &mr_key_action->prog, mr_action->mod.data);
1944 : : }
1945 : :
1946 [ # # ]: 0 : if (type == CPFL_JS_MR_ACTION_TYPE_MOD) {
1947 : : struct cpfl_flow_js_mr_layout *layout;
1948 : :
1949 : 0 : mr_action->type = CPFL_JS_MR_ACTION_TYPE_MOD;
1950 : 0 : mr_action->mod.byte_len = 0;
1951 : 0 : mr_action->mod.prof = action->mod.prof;
1952 : 0 : layout = action->mod.layout;
1953 : : if (!layout)
1954 : : return 0;
1955 : 0 : memset(mr_action->mod.data, 0, sizeof(mr_action->mod.data));
1956 : :
1957 : 0 : return cpfl_parse_layout(layout, action->mod.layout_size, mr_key_action->mods,
1958 : : mr_action->mod.data, &mr_action->mod.byte_len);
1959 : : }
1960 : 0 : PMD_DRV_LOG(ERR, "Not support this type: %d.", type);
1961 : :
1962 : 0 : return -EINVAL;
1963 : : }
1964 : :
1965 : : static int
1966 : : cpfl_check_mod_key(struct cpfl_flow_js_mr *mr, const struct rte_flow_action *actions,
1967 : : struct cpfl_flow_mr_key_action *mr_key_action)
1968 : : {
1969 : : int key_action_size;
1970 : :
1971 : : /* mr->key->actions */
1972 : 0 : key_action_size = mr->key.actions_size;
1973 : 0 : return cpfl_parse_mr_key_action(mr->key.actions, key_action_size, actions, mr_key_action);
1974 : : }
1975 : :
1976 : : /* output: struct cpfl_flow_mr_action *mr_action */
1977 : : static int
1978 : 0 : cpfl_parse_mod_rules(struct cpfl_flow_js_parser *parser, const struct rte_flow_action *actions,
1979 : : struct cpfl_flow_mr_action *mr_action)
1980 : : {
1981 : : int i;
1982 : 0 : struct cpfl_flow_mr_key_action mr_key_action = {0};
1983 : :
1984 [ # # ]: 0 : for (i = 0; i < parser->mr_size; i++) {
1985 : : int ret;
1986 : : struct cpfl_flow_js_mr *mr;
1987 : :
1988 : 0 : mr = &parser->modifications[i];
1989 [ # # ]: 0 : if (!mr)
1990 : : return -EINVAL;
1991 : : ret = cpfl_check_mod_key(mr, actions, &mr_key_action);
1992 [ # # ]: 0 : if (ret < 0)
1993 : : continue;
1994 : : /* mr->action */
1995 : 0 : return cpfl_parse_mr_action(&mr->action, &mr_key_action, mr_action);
1996 : : }
1997 : :
1998 : : return -EINVAL;
1999 : : }
2000 : :
2001 : : int
2002 : 0 : cpfl_flow_parse_actions(struct cpfl_flow_js_parser *parser, const struct rte_flow_action *actions,
2003 : : struct cpfl_flow_mr_action *mr_action)
2004 : : {
2005 : : /* modifications rules */
2006 [ # # ]: 0 : if (!parser->modifications) {
2007 : 0 : PMD_DRV_LOG(INFO, "The modifications is optional.");
2008 : 0 : return 0;
2009 : : }
2010 : :
2011 : 0 : return cpfl_parse_mod_rules(parser, actions, mr_action);
2012 : : }
2013 : :
2014 : : bool
2015 [ # # ]: 0 : cpfl_metadata_write_port_id(struct cpfl_itf *itf)
2016 : : {
2017 : : uint16_t dev_id;
2018 : : const int type = 0;
2019 : : const int offset = 5;
2020 : :
2021 : : dev_id = cpfl_get_port_id(itf);
2022 [ # # ]: 0 : if (dev_id == CPFL_INVALID_HW_ID) {
2023 : 0 : PMD_DRV_LOG(ERR, "fail to get hw ID\n");
2024 : 0 : return false;
2025 : : }
2026 : 0 : cpfl_metadata_write16(&itf->adapter->meta, type, offset, dev_id << 3);
2027 : :
2028 : 0 : return true;
2029 : : }
2030 : :
2031 : : bool
2032 : 0 : cpfl_metadata_write_targetvsi(struct cpfl_itf *itf)
2033 : : {
2034 : : uint16_t dev_id;
2035 : : const int type = 6;
2036 : : const int offset = 2;
2037 : :
2038 : 0 : dev_id = cpfl_get_vsi_id(itf);
2039 [ # # ]: 0 : if (dev_id == CPFL_INVALID_HW_ID) {
2040 : 0 : PMD_DRV_LOG(ERR, "fail to get hw ID");
2041 : 0 : return false;
2042 : : }
2043 : 0 : cpfl_metadata_write16(&itf->adapter->meta, type, offset, dev_id << 1);
2044 : :
2045 : 0 : return true;
2046 : : }
2047 : :
2048 : : bool
2049 : 0 : cpfl_metadata_write_sourcevsi(struct cpfl_itf *itf)
2050 : : {
2051 : : uint16_t dev_id;
2052 : : const int type = 6;
2053 : : const int offset = 0;
2054 : :
2055 : 0 : dev_id = cpfl_get_vsi_id(itf);
2056 [ # # ]: 0 : if (dev_id == CPFL_INVALID_HW_ID) {
2057 : 0 : PMD_DRV_LOG(ERR, "fail to get hw ID");
2058 : 0 : return false;
2059 : : }
2060 : 0 : cpfl_metadata_write16(&itf->adapter->meta, type, offset, dev_id);
2061 : :
2062 : 0 : return true;
2063 : : }
2064 : :
2065 : 0 : bool cpfl_metadata_write_vsi(struct cpfl_itf *itf)
2066 : : {
2067 : : uint16_t dev_id;
2068 : : const int type = 0;
2069 : : const int offset = 24;
2070 : :
2071 : 0 : dev_id = cpfl_get_vsi_id(itf);
2072 [ # # ]: 0 : if (dev_id == CPFL_INVALID_HW_ID) {
2073 : 0 : PMD_DRV_LOG(ERR, "fail to get hw ID");
2074 : 0 : return false;
2075 : : }
2076 : 0 : cpfl_metadata_write16(&itf->adapter->meta, type, offset, dev_id);
2077 : :
2078 : 0 : return true;
2079 : : }
|