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, a negative errno value otherwise and rte_errno is set.
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 if (rss_conf->rss_key_len != rss_hash_default_key_len) {
83 "port %u RSS key len must be %zu Bytes long",
84 dev->data->port_id, rss_hash_default_key_len);
88 priv->rss_conf.rss_key = rte_realloc(priv->rss_conf.rss_key,
89 rss_conf->rss_key_len, 0);
90 if (!priv->rss_conf.rss_key) {
94 memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
95 rss_conf->rss_key_len);
96 priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
98 priv->rss_conf.rss_hf = rss_conf->rss_hf;
99 /* Enable the RSS hash in all Rx queues. */
100 for (i = 0, idx = 0; idx != priv->rxqs_n; ++i) {
101 if (!(*priv->rxqs)[i])
103 (*priv->rxqs)[i]->rss_hash = !!rss_conf->rss_hf &&
104 !!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS);
111 * DPDK callback to get the RSS hash configuration.
114 * Pointer to Ethernet device structure.
115 * @param[in, out] rss_conf
116 * RSS configuration data.
119 * 0 on success, a negative errno value otherwise and rte_errno is set.
122 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
123 struct rte_eth_rss_conf *rss_conf)
125 struct priv *priv = dev->data->dev_private;
131 if (rss_conf->rss_key &&
132 (rss_conf->rss_key_len >= priv->rss_conf.rss_key_len)) {
133 memcpy(rss_conf->rss_key, priv->rss_conf.rss_key,
134 priv->rss_conf.rss_key_len);
136 rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
137 rss_conf->rss_hf = priv->rss_conf.rss_hf;
142 * Allocate/reallocate RETA index table.
145 * Pointer to Ethernet device.
147 * The size of the array to allocate.
150 * 0 on success, a negative errno value otherwise and rte_errno is set.
153 mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size)
155 struct priv *priv = dev->data->dev_private;
157 unsigned int old_size = priv->reta_idx_n;
159 if (priv->reta_idx_n == reta_size)
162 mem = rte_realloc(priv->reta_idx,
163 reta_size * sizeof((*priv->reta_idx)[0]), 0);
168 priv->reta_idx = mem;
169 priv->reta_idx_n = reta_size;
170 if (old_size < reta_size)
171 memset(&(*priv->reta_idx)[old_size], 0,
172 (reta_size - old_size) *
173 sizeof((*priv->reta_idx)[0]));
178 * DPDK callback to get the RETA indirection table.
181 * Pointer to Ethernet device structure.
183 * Pointer to RETA configuration structure array.
185 * Size of the RETA table.
188 * 0 on success, a negative errno value otherwise and rte_errno is set.
191 mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
192 struct rte_eth_rss_reta_entry64 *reta_conf,
195 struct priv *priv = dev->data->dev_private;
199 if (!reta_size || reta_size > priv->reta_idx_n) {
203 /* Fill each entry of the table even if its bit is not set. */
204 for (idx = 0, i = 0; (i != reta_size); ++i) {
205 idx = i / RTE_RETA_GROUP_SIZE;
206 reta_conf[idx].reta[i % RTE_RETA_GROUP_SIZE] =
207 (*priv->reta_idx)[i];
213 * DPDK callback to update the RETA indirection table.
216 * Pointer to Ethernet device structure.
218 * Pointer to RETA configuration structure array.
220 * Size of the RETA table.
223 * 0 on success, a negative errno value otherwise and rte_errno is set.
226 mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
227 struct rte_eth_rss_reta_entry64 *reta_conf,
231 struct priv *priv = dev->data->dev_private;
240 ret = mlx5_rss_reta_index_resize(dev, reta_size);
243 for (idx = 0, i = 0; (i != reta_size); ++i) {
244 idx = i / RTE_RETA_GROUP_SIZE;
245 pos = i % RTE_RETA_GROUP_SIZE;
246 if (((reta_conf[idx].mask >> i) & 0x1) == 0)
248 assert(reta_conf[idx].reta[pos] < priv->rxqs_n);
249 (*priv->reta_idx)[i] = reta_conf[idx].reta[pos];
251 if (dev->data->dev_started) {
253 return mlx5_dev_start(dev);