2 *------------------------------------------------------------------
3 * Copyright (c) 2022 Intel and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #include <vppinfra/mem.h>
19 #include "avf_advanced_flow.h"
22 avf_rss_cfg_create (struct virtchnl_rss_cfg **rss_cfg, int tunnel_level)
24 *rss_cfg = clib_mem_alloc (sizeof (**rss_cfg));
25 if ((*rss_cfg) == NULL)
28 clib_memset (*rss_cfg, 0, sizeof (**rss_cfg));
30 (*rss_cfg)->proto_hdrs.tunnel_level = tunnel_level;
36 avf_rss_rcfg_destroy (struct virtchnl_rss_cfg *rss_cfg)
38 clib_mem_free (rss_cfg);
44 avf_rss_parse_action (const struct avf_flow_action actions[],
45 struct virtchnl_rss_cfg *rss_cfg,
46 struct avf_flow_error *error)
48 const struct avf_flow_action_rss *rss;
53 if (rss->func == AVF_ETH_HASH_FUNCTION_SIMPLE_XOR)
55 rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC;
56 ret = avf_flow_error_set (error, AVF_FAILURE, AVF_FLOW_ERROR_TYPE_ACTION,
57 actions, "simple xor is not supported.");
60 else if (rss->func == AVF_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ)
62 rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC;
66 rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
73 avf_rss_parse_generic_pattern (struct virtchnl_rss_cfg *rss_cfg,
74 struct avf_flow_item avf_items[],
75 struct avf_flow_error *error)
77 struct avf_flow_item *item = avf_items;
78 u8 *pkt_buf, *msk_buf;
79 u16 spec_len, pkt_len;
81 spec_len = clib_strnlen (item->spec, VIRTCHNL_MAX_SIZE_GEN_PACKET);
82 pkt_len = spec_len / 2;
84 pkt_buf = clib_mem_alloc (pkt_len);
85 msk_buf = clib_mem_alloc (pkt_len);
87 avf_parse_generic_pattern (item, pkt_buf, msk_buf, spec_len);
89 clib_memcpy (rss_cfg->proto_hdrs.raw.spec, pkt_buf, pkt_len);
90 clib_memcpy (rss_cfg->proto_hdrs.raw.mask, msk_buf, pkt_len);
92 rss_cfg->proto_hdrs.count = 0;
93 rss_cfg->proto_hdrs.tunnel_level = 0;
94 rss_cfg->proto_hdrs.raw.pkt_len = pkt_len;
96 clib_mem_free (pkt_buf);
97 clib_mem_free (msk_buf);
102 /* Used for common flow creation */
104 avf_rss_parse_pattern (struct virtchnl_rss_cfg *rss_cfg,
105 struct avf_flow_item avf_items[],
106 struct avf_flow_error *error)
112 avf_rss_rule_create (struct avf_flow_vc_ctx *ctx,
113 struct virtchnl_rss_cfg *rss_cfg)
117 ret = ctx->vc_op (ctx->vc_hdl, VIRTCHNL_ADV_OP_ADD_RSS_CFG, rss_cfg,
118 sizeof (*rss_cfg), 0, 0);
124 avf_rss_rule_destroy (struct avf_flow_vc_ctx *ctx,
125 struct virtchnl_rss_cfg *rss_cfg)
129 ret = ctx->vc_op (ctx->vc_hdl, VIRTCHNL_ADV_OP_DEL_RSS_CFG, rss_cfg,
130 sizeof (*rss_cfg), 0, 0);
136 * fd.io coding-style-patch-verification: ON
139 * eval: (c-set-style "gnu")