aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/avf/avf_rss_lib.c
blob: 45843bdb00df2d422ee52373ad8a3094b14477fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 *------------------------------------------------------------------
 * Copyright (c) 2022 Intel and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#include <vppinfra/mem.h>
#include "avf_advanced_flow.h"

int
avf_rss_cfg_create (struct virtchnl_rss_cfg **rss_cfg, int tunnel_level)
{
  *rss_cfg = clib_mem_alloc (sizeof (**rss_cfg));
  if ((*rss_cfg) == NULL)
    return -1;

  clib_memset (*rss_cfg, 0, sizeof (**rss_cfg));

  (*rss_cfg)->proto_hdrs.tunnel_level = tunnel_level;

  return 0;
}

int
avf_rss_rcfg_destroy (struct virtchnl_rss_cfg *rss_cfg)
{
  clib_mem_free (rss_cfg);

  return 0;
}

int
avf_rss_parse_action (const struct avf_flow_action actions[],
		      struct virtchnl_rss_cfg *rss_cfg,
		      struct avf_flow_error *error)
{
  const struct avf_flow_action_rss *rss;
  int ret;

  rss = actions->conf;

  if (rss->func == AVF_ETH_HASH_FUNCTION_SIMPLE_XOR)
    {
      rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC;
      ret = avf_flow_error_set (error, AVF_FAILURE, AVF_FLOW_ERROR_TYPE_ACTION,
				actions, "simple xor is not supported.");
      return ret;
    }
  else if (rss->func == AVF_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ)
    {
      rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC;
    }
  else
    {
      rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
    }

  return 0;
}

int
avf_rss_parse_generic_pattern (struct virtchnl_rss_cfg *rss_cfg,
			       struct avf_flow_item avf_items[],
			       struct avf_flow_error *error)
{
  struct avf_flow_item *item = avf_items;
  u8 *pkt_buf, *msk_buf;
  u16 spec_len, pkt_len;

  spec_len = clib_strnlen (item->spec, VIRTCHNL_MAX_SIZE_GEN_PACKET);
  pkt_len = spec_len / 2;

  pkt_buf = clib_mem_alloc (pkt_len);
  msk_buf = clib_mem_alloc (pkt_len);

  avf_parse_generic_pattern (item, pkt_buf, msk_buf, spec_len);

  clib_memcpy (rss_cfg->proto_hdrs.raw.spec, pkt_buf, pkt_len);
  clib_memcpy (rss_cfg->proto_hdrs.raw.mask, msk_buf, pkt_len);

  rss_cfg->proto_hdrs.count = 0;
  rss_cfg->proto_hdrs.tunnel_level = 0;
  rss_cfg->proto_hdrs.raw.pkt_len = pkt_len;

  clib_mem_free (pkt_buf);
  clib_mem_free (msk_buf);

  return 0;
}

/* Used for common flow creation */
int
avf_rss_parse_pattern (struct virtchnl_rss_cfg *rss_cfg,
		       struct avf_flow_item avf_items[],
		       struct avf_flow_error *error)
{
  return -1;
}

int
avf_rss_rule_create (struct avf_flow_vc_ctx *ctx,
		     struct virtchnl_rss_cfg *rss_cfg)
{
  int ret;

  ret = ctx->vc_op (ctx->vc_hdl, VIRTCHNL_ADV_OP_ADD_RSS_CFG, rss_cfg,
		    sizeof (*rss_cfg), 0, 0);

  return ret;
}

int
avf_rss_rule_destroy (struct avf_flow_vc_ctx *ctx,
		      struct virtchnl_rss_cfg *rss_cfg)
{
  int ret;

  ret = ctx->vc_op (ctx->vc_hdl, VIRTCHNL_ADV_OP_DEL_RSS_CFG, rss_cfg,
		    sizeof (*rss_cfg), 0, 0);

  return ret;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */