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_malloc.h>
26 #include "mlx5_defs.h"
28 #include "mlx5_rxtx.h"
31 * DPDK callback to update the RSS hash configuration.
34 * Pointer to Ethernet device structure.
36 * RSS configuration data.
39 * 0 on success, a negative errno value otherwise and rte_errno is set.
42 mlx5_rss_hash_update(struct rte_eth_dev *dev,
43 struct rte_eth_rss_conf *rss_conf)
45 struct mlx5_priv *priv = dev->data->dev_private;
49 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
53 if (rss_conf->rss_key && rss_conf->rss_key_len) {
54 if (rss_conf->rss_key_len != MLX5_RSS_HASH_KEY_LEN) {
56 "port %u RSS key len must be %s Bytes long",
58 RTE_STR(MLX5_RSS_HASH_KEY_LEN));
62 priv->rss_conf.rss_key = mlx5_realloc(priv->rss_conf.rss_key,
64 rss_conf->rss_key_len,
66 if (!priv->rss_conf.rss_key) {
70 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
71 rss_conf->rss_key_len);
72 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
74 priv->rss_conf.rss_hf = rss_conf->rss_hf;
75 /* Enable the RSS hash in all Rx queues. */
76 for (i = 0, idx = 0; idx != priv->rxqs_n; ++i) {
77 if (!(*priv->rxqs)[i])
79 (*priv->rxqs)[i]->rss_hash = !!rss_conf->rss_hf &&
80 !!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS);
87 * DPDK callback to get the RSS hash configuration.
90 * Pointer to Ethernet device structure.
91 * @param[in, out] rss_conf
92 * RSS configuration data.
95 * 0 on success, a negative errno value otherwise and rte_errno is set.
98 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
99 struct rte_eth_rss_conf *rss_conf)
101 struct mlx5_priv *priv = dev->data->dev_private;
107 if (rss_conf->rss_key &&
108 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
109 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
110 priv->rss_conf.rss_key_len);
112 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
113 rss_conf->rss_hf = priv->rss_conf.rss_hf;
118 * Allocate/reallocate RETA index table.
121 * Pointer to Ethernet device.
123 * The size of the array to allocate.
126 * 0 on success, a negative errno value otherwise and rte_errno is set.
129 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
131 struct mlx5_priv *priv = dev->data->dev_private;
133 unsigned int old_size = priv->reta_idx_n;
135 if (priv->reta_idx_n == reta_size)
138 mem = mlx5_realloc(priv->reta_idx, MLX5_MEM_RTE,
139 reta_size * sizeof((*priv->reta_idx)[0]), 0,
145 priv->reta_idx = mem;
146 priv->reta_idx_n = reta_size;
147 if (old_size < reta_size)
148 memset(&(*priv->reta_idx)[old_size], 0,
149 (reta_size - old_size) *
150 sizeof((*priv->reta_idx)[0]));
155 * DPDK callback to get the RETA indirection table.
158 * Pointer to Ethernet device structure.
160 * Pointer to RETA configuration structure array.
162 * Size of the RETA table.
165 * 0 on success, a negative errno value otherwise and rte_errno is set.
168 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
169 struct rte_eth_rss_reta_entry64 *reta_conf,
172 struct mlx5_priv *priv = dev->data->dev_private;
176 if (!reta_size || reta_size > priv->reta_idx_n) {
180 /* Fill each entry of the table even if its bit is not set. */
181 for (idx = 0, i = 0; (i != reta_size); ++i) {
182 idx = i / RTE_RETA_GROUP_SIZE;
183 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
184 (*priv->reta_idx)[i];
190 * DPDK callback to update the RETA indirection table.
193 * Pointer to Ethernet device structure.
195 * Pointer to RETA configuration structure array.
197 * Size of the RETA table.
200 * 0 on success, a negative errno value otherwise and rte_errno is set.
203 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
204 struct rte_eth_rss_reta_entry64 *reta_conf,
208 struct mlx5_priv *priv = dev->data->dev_private;
217 ret = mlx5_rss_reta_index_resize(dev, reta_size);
220 for (idx = 0, i = 0; (i != reta_size); ++i) {
221 idx = i / RTE_RETA_GROUP_SIZE;
222 pos = i % RTE_RETA_GROUP_SIZE;
223 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
225 MLX5_ASSERT(reta_conf[idx].reta[pos] < priv->rxqs_n);
226 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
228 if (dev->data->dev_started) {
230 priv->skip_default_rss_reta = 1;
231 return mlx5_dev_start(dev);