4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
43 #pragma GCC diagnostic ignored "-Wpedantic"
45 #include <infiniband/verbs.h>
47 #pragma GCC diagnostic error "-Wpedantic"
50 #include <rte_malloc.h>
51 #include <rte_ethdev.h>
54 #include "mlx5_defs.h"
55 #include "mlx5_rxtx.h"
58 * DPDK callback to update the RSS hash configuration.
61 * Pointer to Ethernet device structure.
63 * RSS configuration data.
66 * 0 on success, negative errno value on failure.
69 mlx5_rss_hash_update(struct rte_eth_dev *dev,
70 struct rte_eth_rss_conf *rss_conf)
72 struct priv *priv = dev->data->dev_private;
76 if (rss_conf->rss_hf & MLX5_RSS_HF_MASK) {
80 if (rss_conf->rss_key && rss_conf->rss_key_len) {
81 priv->rss_conf.rss_key = rte_realloc(priv->rss_conf.rss_key,
82 rss_conf->rss_key_len, 0);
83 if (!priv->rss_conf.rss_key) {
87 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
88 rss_conf->rss_key_len);
89 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
91 priv->rss_conf.rss_hf = rss_conf->rss_hf;
98 * DPDK callback to get the RSS hash configuration.
101 * Pointer to Ethernet device structure.
102 * @param[in, out] rss_conf
103 * RSS configuration data.
106 * 0 on success, negative errno value on failure.
109 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
110 struct rte_eth_rss_conf *rss_conf)
112 struct priv *priv = dev->data->dev_private;
117 if (rss_conf->rss_key &&
118 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
119 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
120 priv->rss_conf.rss_key_len);
122 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
123 rss_conf->rss_hf = priv->rss_conf.rss_hf;
129 * Allocate/reallocate RETA index table.
132 * Pointer to private structure.
134 * The size of the array to allocate.
137 * 0 on success, errno value on failure.
140 priv_rss_reta_index_resize(struct priv *priv, unsigned int reta_size)
143 unsigned int old_size = priv->reta_idx_n;
145 if (priv->reta_idx_n == reta_size)
148 mem = rte_realloc(priv->reta_idx,
149 reta_size * sizeof((*priv->reta_idx)[0]), 0);
152 priv->reta_idx = mem;
153 priv->reta_idx_n = reta_size;
155 if (old_size < reta_size)
156 memset(&(*priv->reta_idx)[old_size], 0,
157 (reta_size - old_size) *
158 sizeof((*priv->reta_idx)[0]));
166 * Pointer to private structure.
167 * @param[in, out] reta_conf
168 * Pointer to the first RETA configuration structure.
173 * 0 on success, errno value on failure.
176 priv_dev_rss_reta_query(struct priv *priv,
177 struct rte_eth_rss_reta_entry64 *reta_conf,
178 unsigned int reta_size)
183 if (!reta_size || reta_size > priv->reta_idx_n)
185 /* Fill each entry of the table even if its bit is not set. */
186 for (idx = 0, i = 0; (i != reta_size); ++i) {
187 idx = i / RTE_RETA_GROUP_SIZE;
188 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
189 (*priv->reta_idx)[i];
198 * Pointer to private structure.
199 * @param[in] reta_conf
200 * Pointer to the first RETA configuration structure.
205 * 0 on success, errno value on failure.
208 priv_dev_rss_reta_update(struct priv *priv,
209 struct rte_eth_rss_reta_entry64 *reta_conf,
210 unsigned int reta_size)
219 ret = priv_rss_reta_index_resize(priv, reta_size);
223 for (idx = 0, i = 0; (i != reta_size); ++i) {
224 idx = i / RTE_RETA_GROUP_SIZE;
225 pos = i % RTE_RETA_GROUP_SIZE;
226 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
228 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
229 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
235 * DPDK callback to get the RETA indirection table.
238 * Pointer to Ethernet device structure.
240 * Pointer to RETA configuration structure array.
242 * Size of the RETA table.
245 * 0 on success, negative errno value on failure.
248 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
249 struct rte_eth_rss_reta_entry64 *reta_conf,
253 struct priv *priv = dev->data->dev_private;
256 ret = priv_dev_rss_reta_query(priv, reta_conf, reta_size);
262 * DPDK callback to update the RETA indirection table.
265 * Pointer to Ethernet device structure.
267 * Pointer to RETA configuration structure array.
269 * Size of the RETA table.
272 * 0 on success, negative errno value on failure.
275 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
276 struct rte_eth_rss_reta_entry64 *reta_conf,
280 struct priv *priv = dev->data->dev_private;
283 ret = priv_dev_rss_reta_update(priv, reta_conf, reta_size);
285 if (dev->data->dev_started) {