1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
11 #include <rte_malloc.h>
12 #include <ethdev_driver.h>
14 #include <mlx5_malloc.h>
16 #include "mlx5_defs.h"
18 #include "mlx5_rxtx.h"
22 * DPDK callback to update the RSS hash configuration.
25 * Pointer to Ethernet device structure.
27 * RSS configuration data.
30 * 0 on success, a negative errno value otherwise and rte_errno is set.
33 mlx5_rss_hash_update(struct rte_eth_dev *dev,
34 struct rte_eth_rss_conf *rss_conf)
36 struct mlx5_priv *priv = dev->data->dev_private;
40 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
44 if (rss_conf->rss_key && rss_conf->rss_key_len) {
45 if (rss_conf->rss_key_len != MLX5_RSS_HASH_KEY_LEN) {
47 "port %u RSS key len must be %s Bytes long",
49 RTE_STR(MLX5_RSS_HASH_KEY_LEN));
53 priv->rss_conf.rss_key = mlx5_realloc(priv->rss_conf.rss_key,
55 rss_conf->rss_key_len,
57 if (!priv->rss_conf.rss_key) {
61 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
62 rss_conf->rss_key_len);
63 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
65 priv->rss_conf.rss_hf = rss_conf->rss_hf;
66 /* Enable the RSS hash in all Rx queues. */
67 for (i = 0, idx = 0; idx != priv->rxqs_n; ++i) {
68 if (!(*priv->rxqs)[i])
70 (*priv->rxqs)[i]->rss_hash = !!rss_conf->rss_hf &&
71 !!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS);
78 * DPDK callback to get the RSS hash configuration.
81 * Pointer to Ethernet device structure.
82 * @param[in, out] rss_conf
83 * RSS configuration data.
86 * 0 on success, a negative errno value otherwise and rte_errno is set.
89 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
90 struct rte_eth_rss_conf *rss_conf)
92 struct mlx5_priv *priv = dev->data->dev_private;
98 if (rss_conf->rss_key &&
99 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
100 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
101 priv->rss_conf.rss_key_len);
103 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
104 rss_conf->rss_hf = priv->rss_conf.rss_hf;
109 * Allocate/reallocate RETA index table.
112 * Pointer to Ethernet device.
114 * The size of the array to allocate.
117 * 0 on success, a negative errno value otherwise and rte_errno is set.
120 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
122 struct mlx5_priv *priv = dev->data->dev_private;
124 unsigned int old_size = priv->reta_idx_n;
126 if (priv->reta_idx_n == reta_size)
129 mem = mlx5_realloc(priv->reta_idx, MLX5_MEM_RTE,
130 reta_size * sizeof((*priv->reta_idx)[0]), 0,
136 priv->reta_idx = mem;
137 priv->reta_idx_n = reta_size;
138 if (old_size < reta_size)
139 memset(&(*priv->reta_idx)[old_size], 0,
140 (reta_size - old_size) *
141 sizeof((*priv->reta_idx)[0]));
146 * DPDK callback to get the RETA indirection table.
149 * Pointer to Ethernet device structure.
151 * Pointer to RETA configuration structure array.
153 * Size of the RETA table.
156 * 0 on success, a negative errno value otherwise and rte_errno is set.
159 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
160 struct rte_eth_rss_reta_entry64 *reta_conf,
163 struct mlx5_priv *priv = dev->data->dev_private;
167 if (!reta_size || reta_size > priv->reta_idx_n) {
171 /* Fill each entry of the table even if its bit is not set. */
172 for (idx = 0, i = 0; (i != reta_size); ++i) {
173 idx = i / RTE_RETA_GROUP_SIZE;
174 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
175 (*priv->reta_idx)[i];
181 * DPDK callback to update the RETA indirection table.
184 * Pointer to Ethernet device structure.
186 * Pointer to RETA configuration structure array.
188 * Size of the RETA table.
191 * 0 on success, a negative errno value otherwise and rte_errno is set.
194 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
195 struct rte_eth_rss_reta_entry64 *reta_conf,
199 struct mlx5_priv *priv = dev->data->dev_private;
208 ret = mlx5_rss_reta_index_resize(dev, reta_size);
211 for (idx = 0, i = 0; (i != reta_size); ++i) {
212 idx = i / RTE_RETA_GROUP_SIZE;
213 pos = i % RTE_RETA_GROUP_SIZE;
214 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
216 MLX5_ASSERT(reta_conf[idx].reta[pos] < priv->rxqs_n);
217 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
220 priv->skip_default_rss_reta = 1;
222 if (dev->data->dev_started) {
224 return mlx5_dev_start(dev);