1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
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 if (rss_conf->rss_key_len != rss_hash_default_key_len) {
55 "port %u RSS key len must be %zu Bytes long",
56 dev->data->port_id, rss_hash_default_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 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 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 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 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 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 return mlx5_dev_start(dev);