1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox.
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_malloc.h>
23 #include <rte_ethdev_driver.h>
26 #include "mlx5_defs.h"
27 #include "mlx5_rxtx.h"
30 * DPDK callback to update the RSS hash configuration.
33 * Pointer to Ethernet device structure.
35 * RSS configuration data.
38 * 0 on success, negative errno value on failure.
41 mlx5_rss_hash_update(struct rte_eth_dev *dev,
42 struct rte_eth_rss_conf *rss_conf)
44 struct priv *priv = dev->data->dev_private;
48 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
52 if (rss_conf->rss_key && rss_conf->rss_key_len) {
53 priv->rss_conf.rss_key = rte_realloc(priv->rss_conf.rss_key,
54 rss_conf->rss_key_len, 0);
55 if (!priv->rss_conf.rss_key) {
59 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
60 rss_conf->rss_key_len);
61 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
63 priv->rss_conf.rss_hf = rss_conf->rss_hf;
70 * DPDK callback to get the RSS hash configuration.
73 * Pointer to Ethernet device structure.
74 * @param[in, out] rss_conf
75 * RSS configuration data.
78 * 0 on success, negative errno value on failure.
81 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
82 struct rte_eth_rss_conf *rss_conf)
84 struct priv *priv = dev->data->dev_private;
89 if (rss_conf->rss_key &&
90 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
91 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
92 priv->rss_conf.rss_key_len);
94 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
95 rss_conf->rss_hf = priv->rss_conf.rss_hf;
101 * Allocate/reallocate RETA index table.
104 * Pointer to private structure.
106 * The size of the array to allocate.
109 * 0 on success, errno value on failure.
112 priv_rss_reta_index_resize(struct priv *priv, unsigned int reta_size)
115 unsigned int old_size = priv->reta_idx_n;
117 if (priv->reta_idx_n == reta_size)
120 mem = rte_realloc(priv->reta_idx,
121 reta_size * sizeof((*priv->reta_idx)[0]), 0);
124 priv->reta_idx = mem;
125 priv->reta_idx_n = reta_size;
127 if (old_size < reta_size)
128 memset(&(*priv->reta_idx)[old_size], 0,
129 (reta_size - old_size) *
130 sizeof((*priv->reta_idx)[0]));
138 * Pointer to private structure.
139 * @param[in, out] reta_conf
140 * Pointer to the first RETA configuration structure.
145 * 0 on success, errno value on failure.
148 priv_dev_rss_reta_query(struct priv *priv,
149 struct rte_eth_rss_reta_entry64 *reta_conf,
150 unsigned int reta_size)
155 if (!reta_size || reta_size > priv->reta_idx_n)
157 /* Fill each entry of the table even if its bit is not set. */
158 for (idx = 0, i = 0; (i != reta_size); ++i) {
159 idx = i / RTE_RETA_GROUP_SIZE;
160 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
161 (*priv->reta_idx)[i];
170 * Pointer to private structure.
171 * @param[in] reta_conf
172 * Pointer to the first RETA configuration structure.
177 * 0 on success, errno value on failure.
180 priv_dev_rss_reta_update(struct priv *priv,
181 struct rte_eth_rss_reta_entry64 *reta_conf,
182 unsigned int reta_size)
191 ret = priv_rss_reta_index_resize(priv, reta_size);
195 for (idx = 0, i = 0; (i != reta_size); ++i) {
196 idx = i / RTE_RETA_GROUP_SIZE;
197 pos = i % RTE_RETA_GROUP_SIZE;
198 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
200 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
201 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
207 * DPDK callback to get the RETA indirection table.
210 * Pointer to Ethernet device structure.
212 * Pointer to RETA configuration structure array.
214 * Size of the RETA table.
217 * 0 on success, negative errno value on failure.
220 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
221 struct rte_eth_rss_reta_entry64 *reta_conf,
225 struct priv *priv = dev->data->dev_private;
228 ret = priv_dev_rss_reta_query(priv, reta_conf, reta_size);
234 * DPDK callback to update the RETA indirection table.
237 * Pointer to Ethernet device structure.
239 * Pointer to RETA configuration structure array.
241 * Size of the RETA table.
244 * 0 on success, negative errno value on failure.
247 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
248 struct rte_eth_rss_reta_entry64 *reta_conf,
252 struct priv *priv = dev->data->dev_private;
255 ret = priv_dev_rss_reta_update(priv, reta_conf, reta_size);
257 if (dev->data->dev_started) {