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 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
70 if (rxq == NULL || rxq->ctrl == NULL)
72 rxq->ctrl->rxq.rss_hash = !!rss_conf->rss_hf &&
73 !!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS);
80 * DPDK callback to get the RSS hash configuration.
83 * Pointer to Ethernet device structure.
84 * @param[in, out] rss_conf
85 * RSS configuration data.
88 * 0 on success, a negative errno value otherwise and rte_errno is set.
91 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
92 struct rte_eth_rss_conf *rss_conf)
94 struct mlx5_priv *priv = dev->data->dev_private;
100 if (rss_conf->rss_key &&
101 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
102 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
103 priv->rss_conf.rss_key_len);
105 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
106 rss_conf->rss_hf = priv->rss_conf.rss_hf;
111 * Allocate/reallocate RETA index table.
114 * Pointer to Ethernet device.
116 * The size of the array to allocate.
119 * 0 on success, a negative errno value otherwise and rte_errno is set.
122 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
124 struct mlx5_priv *priv = dev->data->dev_private;
126 unsigned int old_size = priv->reta_idx_n;
128 if (priv->reta_idx_n == reta_size)
131 mem = mlx5_realloc(priv->reta_idx, MLX5_MEM_RTE,
132 reta_size * sizeof((*priv->reta_idx)[0]), 0,
138 priv->reta_idx = mem;
139 priv->reta_idx_n = reta_size;
140 if (old_size < reta_size)
141 memset(&(*priv->reta_idx)[old_size], 0,
142 (reta_size - old_size) *
143 sizeof((*priv->reta_idx)[0]));
148 * DPDK callback to get the RETA indirection table.
151 * Pointer to Ethernet device structure.
153 * Pointer to RETA configuration structure array.
155 * Size of the RETA table.
158 * 0 on success, a negative errno value otherwise and rte_errno is set.
161 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
162 struct rte_eth_rss_reta_entry64 *reta_conf,
165 struct mlx5_priv *priv = dev->data->dev_private;
169 if (!reta_size || reta_size > priv->reta_idx_n) {
173 /* Fill each entry of the table even if its bit is not set. */
174 for (idx = 0, i = 0; (i != reta_size); ++i) {
175 idx = i / RTE_ETH_RETA_GROUP_SIZE;
176 reta_conf[idx].reta[i % RTE_ETH_RETA_GROUP_SIZE] =
177 (*priv->reta_idx)[i];
183 * DPDK callback to update the RETA indirection table.
186 * Pointer to Ethernet device structure.
188 * Pointer to RETA configuration structure array.
190 * Size of the RETA table.
193 * 0 on success, a negative errno value otherwise and rte_errno is set.
196 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
197 struct rte_eth_rss_reta_entry64 *reta_conf,
201 struct mlx5_priv *priv = dev->data->dev_private;
210 ret = mlx5_rss_reta_index_resize(dev, reta_size);
213 for (idx = 0, i = 0; (i != reta_size); ++i) {
214 idx = i / RTE_ETH_RETA_GROUP_SIZE;
215 pos = i % RTE_ETH_RETA_GROUP_SIZE;
216 if (((reta_conf[idx].mask >> pos) & 0x1) == 0)
218 MLX5_ASSERT(reta_conf[idx].reta[pos] < priv->rxqs_n);
219 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
221 priv->skip_default_rss_reta = 1;
222 return mlx5_traffic_restart(dev);