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 && 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;
112 if (rss_conf->rss_key &&
113 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
114 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
115 priv->rss_conf.rss_key_len);
117 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
118 rss_conf->rss_hf = priv->rss_conf.rss_hf;
124 * Allocate/reallocate RETA index table.
127 * Pointer to private structure.
129 * The size of the array to allocate.
132 * 0 on success, errno value on failure.
135 priv_rss_reta_index_resize(struct priv *priv, unsigned int reta_size)
138 unsigned int old_size = priv->reta_idx_n;
140 if (priv->reta_idx_n == reta_size)
143 mem = rte_realloc(priv->reta_idx,
144 reta_size * sizeof((*priv->reta_idx)[0]), 0);
147 priv->reta_idx = mem;
148 priv->reta_idx_n = reta_size;
150 if (old_size < reta_size)
151 memset(&(*priv->reta_idx)[old_size], 0,
152 (reta_size - old_size) *
153 sizeof((*priv->reta_idx)[0]));
161 * Pointer to private structure.
162 * @param[in, out] reta_conf
163 * Pointer to the first RETA configuration structure.
168 * 0 on success, errno value on failure.
171 priv_dev_rss_reta_query(struct priv *priv,
172 struct rte_eth_rss_reta_entry64 *reta_conf,
173 unsigned int reta_size)
178 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];
193 * Pointer to private structure.
194 * @param[in] reta_conf
195 * Pointer to the first RETA configuration structure.
200 * 0 on success, errno value on failure.
203 priv_dev_rss_reta_update(struct priv *priv,
204 struct rte_eth_rss_reta_entry64 *reta_conf,
205 unsigned int reta_size)
214 ret = priv_rss_reta_index_resize(priv, reta_size);
218 for (idx = 0, i = 0; (i != reta_size); ++i) {
219 idx = i / RTE_RETA_GROUP_SIZE;
220 pos = i % RTE_RETA_GROUP_SIZE;
221 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
223 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
224 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
230 * DPDK callback to get the RETA indirection table.
233 * Pointer to Ethernet device structure.
235 * Pointer to RETA configuration structure array.
237 * Size of the RETA table.
240 * 0 on success, negative errno value on failure.
243 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
244 struct rte_eth_rss_reta_entry64 *reta_conf,
248 struct priv *priv = dev->data->dev_private;
251 ret = priv_dev_rss_reta_query(priv, reta_conf, reta_size);
257 * DPDK callback to update the RETA indirection table.
260 * Pointer to Ethernet device structure.
262 * Pointer to RETA configuration structure array.
264 * Size of the RETA table.
267 * 0 on success, negative errno value on failure.
270 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
271 struct rte_eth_rss_reta_entry64 *reta_conf,
275 struct priv *priv = dev->data->dev_private;
278 ret = priv_dev_rss_reta_update(priv, reta_conf, reta_size);
280 if (dev->data->dev_started) {