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;
126 if (old_size < reta_size)
127 memset(&(*priv->reta_idx)[old_size], 0,
128 (reta_size - old_size) *
129 sizeof((*priv->reta_idx)[0]));
137 * Pointer to private structure.
138 * @param[in, out] reta_conf
139 * Pointer to the first RETA configuration structure.
144 * 0 on success, errno value on failure.
147 priv_dev_rss_reta_query(struct priv *priv,
148 struct rte_eth_rss_reta_entry64 *reta_conf,
149 unsigned int reta_size)
154 if (!reta_size || reta_size > priv->reta_idx_n)
156 /* Fill each entry of the table even if its bit is not set. */
157 for (idx = 0, i = 0; (i != reta_size); ++i) {
158 idx = i / RTE_RETA_GROUP_SIZE;
159 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
160 (*priv->reta_idx)[i];
169 * Pointer to private structure.
170 * @param[in] reta_conf
171 * Pointer to the first RETA configuration structure.
176 * 0 on success, errno value on failure.
179 priv_dev_rss_reta_update(struct priv *priv,
180 struct rte_eth_rss_reta_entry64 *reta_conf,
181 unsigned int reta_size)
190 ret = priv_rss_reta_index_resize(priv, reta_size);
193 for (idx = 0, i = 0; (i != reta_size); ++i) {
194 idx = i / RTE_RETA_GROUP_SIZE;
195 pos = i % RTE_RETA_GROUP_SIZE;
196 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
198 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
199 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
205 * DPDK callback to get the RETA indirection table.
208 * Pointer to Ethernet device structure.
210 * Pointer to RETA configuration structure array.
212 * Size of the RETA table.
215 * 0 on success, negative errno value on failure.
218 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
219 struct rte_eth_rss_reta_entry64 *reta_conf,
223 struct priv *priv = dev->data->dev_private;
226 ret = priv_dev_rss_reta_query(priv, reta_conf, reta_size);
232 * DPDK callback to update the RETA indirection table.
235 * Pointer to Ethernet device structure.
237 * Pointer to RETA configuration structure array.
239 * Size of the RETA table.
242 * 0 on success, negative errno value on failure.
245 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
246 struct rte_eth_rss_reta_entry64 *reta_conf,
250 struct priv *priv = dev->data->dev_private;
253 ret = priv_dev_rss_reta_update(priv, reta_conf, reta_size);
255 if (dev->data->dev_started) {