1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
12 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
14 #pragma GCC diagnostic ignored "-Wpedantic"
16 #include <infiniband/verbs.h>
18 #pragma GCC diagnostic error "-Wpedantic"
21 #include <rte_malloc.h>
22 #include <rte_ethdev_driver.h>
24 #include "mlx5_defs.h"
26 #include "mlx5_rxtx.h"
29 * DPDK callback to update the RSS hash configuration.
32 * Pointer to Ethernet device structure.
34 * RSS configuration data.
37 * 0 on success, a negative errno value otherwise and rte_errno is set.
40 mlx5_rss_hash_update(struct rte_eth_dev *dev,
41 struct rte_eth_rss_conf *rss_conf)
43 struct mlx5_priv *priv = dev->data->dev_private;
47 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
51 if (rss_conf->rss_key && rss_conf->rss_key_len) {
52 if (rss_conf->rss_key_len != MLX5_RSS_HASH_KEY_LEN) {
54 "port %u RSS key len must be %s Bytes long",
56 RTE_STR(MLX5_RSS_HASH_KEY_LEN));
60 priv->rss_conf.rss_key = rte_realloc(priv->rss_conf.rss_key,
61 rss_conf->rss_key_len, 0);
62 if (!priv->rss_conf.rss_key) {
66 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
67 rss_conf->rss_key_len);
68 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
70 priv->rss_conf.rss_hf = rss_conf->rss_hf;
71 /* Enable the RSS hash in all Rx queues. */
72 for (i = 0, idx = 0; idx != priv->rxqs_n; ++i) {
73 if (!(*priv->rxqs)[i])
75 (*priv->rxqs)[i]->rss_hash = !!rss_conf->rss_hf &&
76 !!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS);
83 * DPDK callback to get the RSS hash configuration.
86 * Pointer to Ethernet device structure.
87 * @param[in, out] rss_conf
88 * RSS configuration data.
91 * 0 on success, a negative errno value otherwise and rte_errno is set.
94 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
95 struct rte_eth_rss_conf *rss_conf)
97 struct mlx5_priv *priv = dev->data->dev_private;
103 if (rss_conf->rss_key &&
104 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
105 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
106 priv->rss_conf.rss_key_len);
108 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
109 rss_conf->rss_hf = priv->rss_conf.rss_hf;
114 * Allocate/reallocate RETA index table.
117 * Pointer to Ethernet device.
119 * The size of the array to allocate.
122 * 0 on success, a negative errno value otherwise and rte_errno is set.
125 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
127 struct mlx5_priv *priv = dev->data->dev_private;
129 unsigned int old_size = priv->reta_idx_n;
131 if (priv->reta_idx_n == reta_size)
134 mem = rte_realloc(priv->reta_idx,
135 reta_size * sizeof((*priv->reta_idx)[0]), 0);
140 priv->reta_idx = mem;
141 priv->reta_idx_n = reta_size;
142 if (old_size < reta_size)
143 memset(&(*priv->reta_idx)[old_size], 0,
144 (reta_size - old_size) *
145 sizeof((*priv->reta_idx)[0]));
150 * DPDK callback to get the RETA indirection table.
153 * Pointer to Ethernet device structure.
155 * Pointer to RETA configuration structure array.
157 * Size of the RETA table.
160 * 0 on success, a negative errno value otherwise and rte_errno is set.
163 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
164 struct rte_eth_rss_reta_entry64 *reta_conf,
167 struct mlx5_priv *priv = dev->data->dev_private;
171 if (!reta_size || reta_size > priv->reta_idx_n) {
175 /* Fill each entry of the table even if its bit is not set. */
176 for (idx = 0, i = 0; (i != reta_size); ++i) {
177 idx = i / RTE_RETA_GROUP_SIZE;
178 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
179 (*priv->reta_idx)[i];
185 * DPDK callback to update the RETA indirection table.
188 * Pointer to Ethernet device structure.
190 * Pointer to RETA configuration structure array.
192 * Size of the RETA table.
195 * 0 on success, a negative errno value otherwise and rte_errno is set.
198 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
199 struct rte_eth_rss_reta_entry64 *reta_conf,
203 struct mlx5_priv *priv = dev->data->dev_private;
212 ret = mlx5_rss_reta_index_resize(dev, reta_size);
215 for (idx = 0, i = 0; (i != reta_size); ++i) {
216 idx = i / RTE_RETA_GROUP_SIZE;
217 pos = i % RTE_RETA_GROUP_SIZE;
218 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
220 MLX5_ASSERT(reta_conf[idx].reta[pos] < priv->rxqs_n);
221 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
223 if (dev->data->dev_started) {
225 priv->skip_default_rss_reta = 1;
226 return mlx5_dev_start(dev);