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 "-pedantic"
45 #include <infiniband/verbs.h>
47 #pragma GCC diagnostic error "-pedantic"
50 /* DPDK headers don't like -pedantic. */
52 #pragma GCC diagnostic ignored "-pedantic"
54 #include <rte_malloc.h>
55 #include <rte_ethdev.h>
57 #pragma GCC diagnostic error "-pedantic"
61 #include "mlx5_rxtx.h"
67 * Pointer to private structure.
69 * Hash key to register.
71 * Hash key length in bytes.
74 * 0 on success, errno value on failure.
77 rss_hash_rss_conf_new_key(struct priv *priv, const uint8_t *key,
80 struct rte_eth_rss_conf *rss_conf;
82 rss_conf = rte_realloc(priv->rss_conf,
83 (sizeof(*rss_conf) + key_len),
87 rss_conf->rss_key = (void *)(rss_conf + 1);
88 rss_conf->rss_key_len = key_len;
89 memcpy(rss_conf->rss_key, key, key_len);
90 priv->rss_conf = rss_conf;
95 * DPDK callback to update the RSS hash configuration.
98 * Pointer to Ethernet device structure.
100 * RSS configuration data.
103 * 0 on success, negative errno value on failure.
106 mlx5_rss_hash_update(struct rte_eth_dev *dev,
107 struct rte_eth_rss_conf *rss_conf)
109 struct priv *priv = dev->data->dev_private;
114 assert(priv->rss_conf != NULL);
116 /* Apply configuration. */
117 if (rss_conf->rss_key)
118 err = rss_hash_rss_conf_new_key(priv,
120 rss_conf->rss_key_len);
122 err = rss_hash_rss_conf_new_key(priv,
123 rss_hash_default_key,
124 rss_hash_default_key_len);
126 /* Store the configuration set into port configure.
127 * This will enable/disable hash RX queues associated to the protocols
128 * enabled/disabled by this update. */
129 priv->dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
137 * DPDK callback to get the RSS hash configuration.
140 * Pointer to Ethernet device structure.
141 * @param[in, out] rss_conf
142 * RSS configuration data.
145 * 0 on success, negative errno value on failure.
148 mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
149 struct rte_eth_rss_conf *rss_conf)
151 struct priv *priv = dev->data->dev_private;
155 assert(priv->rss_conf != NULL);
157 if (rss_conf->rss_key &&
158 rss_conf->rss_key_len >= priv->rss_conf->rss_key_len)
159 memcpy(rss_conf->rss_key,
160 priv->rss_conf->rss_key,
161 priv->rss_conf->rss_key_len);
162 rss_conf->rss_key_len = priv->rss_conf->rss_key_len;
163 /* FIXME: rss_hf should be more specific. */
164 rss_conf->rss_hf = ETH_RSS_PROTO_MASK;