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 <rte_ethdev_driver.h>
14 #include <mlx5_malloc.h>
16 #include "mlx5_defs.h"
18 #include "mlx5_rxtx.h"
21 * DPDK callback to update the RSS hash configuration.
24 * Pointer to Ethernet device structure.
26 * RSS configuration data.
29 * 0 on success, a negative errno value otherwise and rte_errno is set.
32 mlx5_rss_hash_update(struct rte_eth_dev *dev,
33 struct rte_eth_rss_conf *rss_conf)
35 struct mlx5_priv *priv = dev->data->dev_private;
39 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
43 if (rss_conf->rss_key && rss_conf->rss_key_len) {
44 if (rss_conf->rss_key_len != MLX5_RSS_HASH_KEY_LEN) {
46 "port %u RSS key len must be %s Bytes long",
48 RTE_STR(MLX5_RSS_HASH_KEY_LEN));
52 priv->rss_conf.rss_key = mlx5_realloc(priv->rss_conf.rss_key,
54 rss_conf->rss_key_len,
56 if (!priv->rss_conf.rss_key) {
60 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
61 rss_conf->rss_key_len);
62 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
64 priv->rss_conf.rss_hf = rss_conf->rss_hf;
65 /* Enable the RSS hash in all Rx queues. */
66 for (i = 0, idx = 0; idx != priv->rxqs_n; ++i) {
67 if (!(*priv->rxqs)[i])
69 (*priv->rxqs)[i]->rss_hash = !!rss_conf->rss_hf &&
70 !!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS);
77 * DPDK callback to get the RSS hash configuration.
80 * Pointer to Ethernet device structure.
81 * @param[in, out] rss_conf
82 * RSS configuration data.
85 * 0 on success, a negative errno value otherwise and rte_errno is set.
88 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
89 struct rte_eth_rss_conf *rss_conf)
91 struct mlx5_priv *priv = dev->data->dev_private;
97 if (rss_conf->rss_key &&
98 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
99 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
100 priv->rss_conf.rss_key_len);
102 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
103 rss_conf->rss_hf = priv->rss_conf.rss_hf;
108 * Allocate/reallocate RETA index table.
111 * Pointer to Ethernet device.
113 * The size of the array to allocate.
116 * 0 on success, a negative errno value otherwise and rte_errno is set.
119 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
121 struct mlx5_priv *priv = dev->data->dev_private;
123 unsigned int old_size = priv->reta_idx_n;
125 if (priv->reta_idx_n == reta_size)
128 mem = mlx5_realloc(priv->reta_idx, MLX5_MEM_RTE,
129 reta_size * sizeof((*priv->reta_idx)[0]), 0,
135 priv->reta_idx = mem;
136 priv->reta_idx_n = reta_size;
137 if (old_size < reta_size)
138 memset(&(*priv->reta_idx)[old_size], 0,
139 (reta_size - old_size) *
140 sizeof((*priv->reta_idx)[0]));
145 * DPDK callback to get the RETA indirection table.
148 * Pointer to Ethernet device structure.
150 * Pointer to RETA configuration structure array.
152 * Size of the RETA table.
155 * 0 on success, a negative errno value otherwise and rte_errno is set.
158 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
159 struct rte_eth_rss_reta_entry64 *reta_conf,
162 struct mlx5_priv *priv = dev->data->dev_private;
166 if (!reta_size || reta_size > priv->reta_idx_n) {
170 /* Fill each entry of the table even if its bit is not set. */
171 for (idx = 0, i = 0; (i != reta_size); ++i) {
172 idx = i / RTE_RETA_GROUP_SIZE;
173 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
174 (*priv->reta_idx)[i];
180 * DPDK callback to update the RETA indirection table.
183 * Pointer to Ethernet device structure.
185 * Pointer to RETA configuration structure array.
187 * Size of the RETA table.
190 * 0 on success, a negative errno value otherwise and rte_errno is set.
193 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
194 struct rte_eth_rss_reta_entry64 *reta_conf,
198 struct mlx5_priv *priv = dev->data->dev_private;
207 ret = mlx5_rss_reta_index_resize(dev, reta_size);
210 for (idx = 0, i = 0; (i != reta_size); ++i) {
211 idx = i / RTE_RETA_GROUP_SIZE;
212 pos = i % RTE_RETA_GROUP_SIZE;
213 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
215 MLX5_ASSERT(reta_conf[idx].reta[pos] < priv->rxqs_n);
216 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
218 if (dev->data->dev_started) {
220 priv->skip_default_rss_reta = 1;
221 return mlx5_dev_start(dev);