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 * Get a RSS configuration hash key.
60 * Pointer to private structure.
62 * RSS hash functions configuration must be retrieved for.
65 * Pointer to a RSS configuration structure or NULL if rss_hf cannot
68 static struct rte_eth_rss_conf *
69 rss_hash_get(struct priv *priv, uint64_t rss_hf)
73 for (i = 0; (i != hash_rxq_init_n); ++i) {
74 uint64_t dpdk_rss_hf = hash_rxq_init[i].dpdk_rss_hf;
76 if (!(dpdk_rss_hf & rss_hf))
78 return (*priv->rss_conf)[i];
87 * Pointer to private structure.
89 * Hash key to register.
91 * Hash key length in bytes.
93 * RSS hash functions the provided key applies to.
96 * 0 on success, errno value on failure.
99 rss_hash_rss_conf_new_key(struct priv *priv, const uint8_t *key,
100 unsigned int key_len, uint64_t rss_hf)
104 for (i = 0; (i != hash_rxq_init_n); ++i) {
105 struct rte_eth_rss_conf *rss_conf;
106 uint64_t dpdk_rss_hf = hash_rxq_init[i].dpdk_rss_hf;
108 if (!(dpdk_rss_hf & rss_hf))
110 rss_conf = rte_realloc((*priv->rss_conf)[i],
111 (sizeof(*rss_conf) + key_len),
115 rss_conf->rss_key = (void *)(rss_conf + 1);
116 rss_conf->rss_key_len = key_len;
117 rss_conf->rss_hf = dpdk_rss_hf;
118 memcpy(rss_conf->rss_key, key, key_len);
119 (*priv->rss_conf)[i] = rss_conf;
125 * DPDK callback to update the RSS hash configuration.
128 * Pointer to Ethernet device structure.
129 * @param[in] rss_conf
130 * RSS configuration data.
133 * 0 on success, negative errno value on failure.
136 mlx5_rss_hash_update(struct rte_eth_dev *dev,
137 struct rte_eth_rss_conf *rss_conf)
139 struct priv *priv = dev->data->dev_private;
144 assert(priv->rss_conf != NULL);
146 /* Apply configuration. */
147 if (rss_conf->rss_key)
148 err = rss_hash_rss_conf_new_key(priv,
150 rss_conf->rss_key_len,
152 /* Store protocols for which RSS is enabled. */
153 priv->rss_hf = rss_conf->rss_hf;
160 * DPDK callback to get the RSS hash configuration.
163 * Pointer to Ethernet device structure.
164 * @param[in, out] rss_conf
165 * RSS configuration data.
168 * 0 on success, negative errno value on failure.
171 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
172 struct rte_eth_rss_conf *rss_conf)
174 struct priv *priv = dev->data->dev_private;
175 struct rte_eth_rss_conf *priv_rss_conf;
179 assert(priv->rss_conf != NULL);
181 priv_rss_conf = rss_hash_get(priv, rss_conf->rss_hf);
182 if (!priv_rss_conf) {
183 rss_conf->rss_hf = 0;
187 if (rss_conf->rss_key &&
188 rss_conf->rss_key_len >= priv_rss_conf->rss_key_len)
189 memcpy(rss_conf->rss_key,
190 priv_rss_conf->rss_key,
191 priv_rss_conf->rss_key_len);
192 rss_conf->rss_key_len = priv_rss_conf->rss_key_len;
193 rss_conf->rss_hf = priv_rss_conf->rss_hf;
200 * Allocate/reallocate RETA index table.
203 * Pointer to private structure.
205 * The size of the array to allocate.
208 * 0 on success, errno value on failure.
211 priv_rss_reta_index_resize(struct priv *priv, unsigned int reta_size)
214 unsigned int old_size = priv->reta_idx_n;
216 if (priv->reta_idx_n == reta_size)
219 mem = rte_realloc(priv->reta_idx,
220 reta_size * sizeof((*priv->reta_idx)[0]), 0);
223 priv->reta_idx = mem;
224 priv->reta_idx_n = reta_size;
226 if (old_size < reta_size)
227 memset(&(*priv->reta_idx)[old_size], 0,
228 (reta_size - old_size) *
229 sizeof((*priv->reta_idx)[0]));
237 * Pointer to private structure.
238 * @param[in, out] reta_conf
239 * Pointer to the first RETA configuration structure.
244 * 0 on success, errno value on failure.
247 priv_dev_rss_reta_query(struct priv *priv,
248 struct rte_eth_rss_reta_entry64 *reta_conf,
249 unsigned int reta_size)
254 if (!reta_size || reta_size > priv->reta_idx_n)
256 /* Fill each entry of the table even if its bit is not set. */
257 for (idx = 0, i = 0; (i != reta_size); ++i) {
258 idx = i / RTE_RETA_GROUP_SIZE;
259 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
260 (*priv->reta_idx)[i];
269 * Pointer to private structure.
270 * @param[in] reta_conf
271 * Pointer to the first RETA configuration structure.
276 * 0 on success, errno value on failure.
279 priv_dev_rss_reta_update(struct priv *priv,
280 struct rte_eth_rss_reta_entry64 *reta_conf,
281 unsigned int reta_size)
290 ret = priv_rss_reta_index_resize(priv, reta_size);
294 for (idx = 0, i = 0; (i != reta_size); ++i) {
295 idx = i / RTE_RETA_GROUP_SIZE;
296 pos = i % RTE_RETA_GROUP_SIZE;
297 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
299 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
300 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
306 * DPDK callback to get the RETA indirection table.
309 * Pointer to Ethernet device structure.
311 * Pointer to RETA configuration structure array.
313 * Size of the RETA table.
316 * 0 on success, negative errno value on failure.
319 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
320 struct rte_eth_rss_reta_entry64 *reta_conf,
324 struct priv *priv = dev->data->dev_private;
327 ret = priv_dev_rss_reta_query(priv, reta_conf, reta_size);
333 * DPDK callback to update the RETA indirection table.
336 * Pointer to Ethernet device structure.
338 * Pointer to RETA configuration structure array.
340 * Size of the RETA table.
343 * 0 on success, negative errno value on failure.
346 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
347 struct rte_eth_rss_reta_entry64 *reta_conf,
351 struct priv *priv = dev->data->dev_private;
355 ret = priv_dev_rss_reta_update(priv, reta_conf, reta_size);
359 return mlx5_dev_start(dev);