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_rxtx.h"
57 * DPDK callback to update the RSS hash configuration.
60 * Pointer to Ethernet device structure.
62 * RSS configuration data.
65 * 0 on success, negative errno value on failure.
68 mlx5_rss_hash_update(struct rte_eth_dev *dev,
69 struct rte_eth_rss_conf *rss_conf)
71 struct priv *priv = dev->data->dev_private;
75 if (rss_conf->rss_key_len) {
76 priv->rss_conf.rss_key = rte_realloc(priv->rss_conf.rss_key,
77 rss_conf->rss_key_len, 0);
78 if (!priv->rss_conf.rss_key) {
82 memcpy(&priv->rss_conf.rss_key, rss_conf->rss_key,
83 rss_conf->rss_key_len);
84 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
86 priv->rss_conf.rss_hf = rss_conf->rss_hf;
93 * DPDK callback to get the RSS hash configuration.
96 * Pointer to Ethernet device structure.
97 * @param[in, out] rss_conf
98 * RSS configuration data.
101 * 0 on success, negative errno value on failure.
104 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
105 struct rte_eth_rss_conf *rss_conf)
107 struct priv *priv = dev->data->dev_private;
111 if (!rss_conf->rss_key) {
115 if (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);
127 * Allocate/reallocate RETA index table.
130 * Pointer to private structure.
132 * The size of the array to allocate.
135 * 0 on success, errno value on failure.
138 priv_rss_reta_index_resize(struct priv *priv, unsigned int reta_size)
141 unsigned int old_size = priv->reta_idx_n;
143 if (priv->reta_idx_n == reta_size)
146 mem = rte_realloc(priv->reta_idx,
147 reta_size * sizeof((*priv->reta_idx)[0]), 0);
150 priv->reta_idx = mem;
151 priv->reta_idx_n = reta_size;
153 if (old_size < reta_size)
154 memset(&(*priv->reta_idx)[old_size], 0,
155 (reta_size - old_size) *
156 sizeof((*priv->reta_idx)[0]));
164 * Pointer to private structure.
165 * @param[in, out] reta_conf
166 * Pointer to the first RETA configuration structure.
171 * 0 on success, errno value on failure.
174 priv_dev_rss_reta_query(struct priv *priv,
175 struct rte_eth_rss_reta_entry64 *reta_conf,
176 unsigned int reta_size)
181 if (!reta_size || reta_size > priv->reta_idx_n)
183 /* Fill each entry of the table even if its bit is not set. */
184 for (idx = 0, i = 0; (i != reta_size); ++i) {
185 idx = i / RTE_RETA_GROUP_SIZE;
186 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
187 (*priv->reta_idx)[i];
196 * Pointer to private structure.
197 * @param[in] reta_conf
198 * Pointer to the first RETA configuration structure.
203 * 0 on success, errno value on failure.
206 priv_dev_rss_reta_update(struct priv *priv,
207 struct rte_eth_rss_reta_entry64 *reta_conf,
208 unsigned int reta_size)
217 ret = priv_rss_reta_index_resize(priv, reta_size);
221 for (idx = 0, i = 0; (i != reta_size); ++i) {
222 idx = i / RTE_RETA_GROUP_SIZE;
223 pos = i % RTE_RETA_GROUP_SIZE;
224 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
226 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
227 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
233 * DPDK callback to get the RETA indirection table.
236 * Pointer to Ethernet device structure.
238 * Pointer to RETA configuration structure array.
240 * Size of the RETA table.
243 * 0 on success, negative errno value on failure.
246 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
247 struct rte_eth_rss_reta_entry64 *reta_conf,
251 struct priv *priv = dev->data->dev_private;
254 ret = priv_dev_rss_reta_query(priv, reta_conf, reta_size);
260 * DPDK callback to update the RETA indirection table.
263 * Pointer to Ethernet device structure.
265 * Pointer to RETA configuration structure array.
267 * Size of the RETA table.
270 * 0 on success, negative errno value on failure.
273 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
274 struct rte_eth_rss_reta_entry64 *reta_conf,
278 struct priv *priv = dev->data->dev_private;
280 assert(!mlx5_is_secondary());
282 ret = priv_dev_rss_reta_update(priv, reta_conf, reta_size);
284 if (dev->data->dev_started) {