1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox.
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_malloc.h>
23 #include <rte_ethdev_driver.h>
26 #include "mlx5_defs.h"
27 #include "mlx5_rxtx.h"
30 * DPDK callback to update the RSS hash configuration.
33 * Pointer to Ethernet device structure.
35 * RSS configuration data.
38 * 0 on success, a negative errno value otherwise and rte_errno is set.
41 mlx5_rss_hash_update(struct rte_eth_dev *dev,
42 struct rte_eth_rss_conf *rss_conf)
44 struct priv *priv = dev->data->dev_private;
48 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
52 if (rss_conf->rss_key && rss_conf->rss_key_len) {
53 priv->rss_conf.rss_key = rte_realloc(priv->rss_conf.rss_key,
54 rss_conf->rss_key_len, 0);
55 if (!priv->rss_conf.rss_key) {
59 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
60 rss_conf->rss_key_len);
61 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
63 priv->rss_conf.rss_hf = rss_conf->rss_hf;
64 /* Enable the RSS hash in all Rx queues. */
65 for (i = 0, idx = 0; idx != priv->rxqs_n; ++i) {
66 if (!(*priv->rxqs)[i])
68 (*priv->rxqs)[i]->rss_hash = !!rss_conf->rss_hf &&
69 !!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS);
76 * DPDK callback to get the RSS hash configuration.
79 * Pointer to Ethernet device structure.
80 * @param[in, out] rss_conf
81 * RSS configuration data.
84 * 0 on success, a negative errno value otherwise and rte_errno is set.
87 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
88 struct rte_eth_rss_conf *rss_conf)
90 struct priv *priv = dev->data->dev_private;
96 if (rss_conf->rss_key &&
97 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
98 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
99 priv->rss_conf.rss_key_len);
101 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
102 rss_conf->rss_hf = priv->rss_conf.rss_hf;
107 * Allocate/reallocate RETA index table.
110 * Pointer to Ethernet device.
112 * The size of the array to allocate.
115 * 0 on success, a negative errno value otherwise and rte_errno is set.
118 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
120 struct priv *priv = dev->data->dev_private;
122 unsigned int old_size = priv->reta_idx_n;
124 if (priv->reta_idx_n == reta_size)
127 mem = rte_realloc(priv->reta_idx,
128 reta_size * sizeof((*priv->reta_idx)[0]), 0);
133 priv->reta_idx = mem;
134 priv->reta_idx_n = reta_size;
135 if (old_size < reta_size)
136 memset(&(*priv->reta_idx)[old_size], 0,
137 (reta_size - old_size) *
138 sizeof((*priv->reta_idx)[0]));
143 * DPDK callback to get the RETA indirection table.
146 * Pointer to Ethernet device structure.
148 * Pointer to RETA configuration structure array.
150 * Size of the RETA table.
153 * 0 on success, a negative errno value otherwise and rte_errno is set.
156 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
157 struct rte_eth_rss_reta_entry64 *reta_conf,
160 struct priv *priv = dev->data->dev_private;
164 if (!reta_size || reta_size > priv->reta_idx_n) {
168 /* Fill each entry of the table even if its bit is not set. */
169 for (idx = 0, i = 0; (i != reta_size); ++i) {
170 idx = i / RTE_RETA_GROUP_SIZE;
171 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
172 (*priv->reta_idx)[i];
178 * DPDK callback to update the RETA indirection table.
181 * Pointer to Ethernet device structure.
183 * Pointer to RETA configuration structure array.
185 * Size of the RETA table.
188 * 0 on success, a negative errno value otherwise and rte_errno is set.
191 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
192 struct rte_eth_rss_reta_entry64 *reta_conf,
196 struct priv *priv = dev->data->dev_private;
205 ret = mlx5_rss_reta_index_resize(dev, reta_size);
208 for (idx = 0, i = 0; (i != reta_size); ++i) {
209 idx = i / RTE_RETA_GROUP_SIZE;
210 pos = i % RTE_RETA_GROUP_SIZE;
211 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
213 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
214 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
216 if (dev->data->dev_started) {
218 return mlx5_dev_start(dev);