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.
39 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
41 #pragma GCC diagnostic ignored "-pedantic"
43 #include <infiniband/verbs.h>
45 #pragma GCC diagnostic error "-pedantic"
48 /* DPDK headers don't like -pedantic. */
50 #pragma GCC diagnostic ignored "-pedantic"
52 #include <rte_ethdev.h>
54 #pragma GCC diagnostic error "-pedantic"
58 #include "mlx5_rxtx.h"
59 #include "mlx5_utils.h"
61 static void hash_rxq_promiscuous_disable(struct hash_rxq *);
62 static void hash_rxq_allmulticast_disable(struct hash_rxq *);
65 * Enable promiscuous mode in a hash RX queue.
68 * Pointer to hash RX queue structure.
71 * 0 on success, errno value on failure.
74 hash_rxq_promiscuous_enable(struct hash_rxq *hash_rxq)
76 struct ibv_flow *flow;
77 FLOW_ATTR_SPEC_ETH(data, hash_rxq_flow_attr(hash_rxq, NULL, 0));
78 struct ibv_flow_attr *attr = &data->attr;
80 if (hash_rxq->promisc_flow != NULL)
82 DEBUG("%p: enabling promiscuous mode", (void *)hash_rxq);
83 /* Promiscuous flows only differ from normal flows by not filtering
84 * on specific MAC addresses. */
85 hash_rxq_flow_attr(hash_rxq, attr, sizeof(data));
87 flow = ibv_create_flow(hash_rxq->qp, attr);
89 /* It's not clear whether errno is always set in this case. */
90 ERROR("%p: flow configuration failed, errno=%d: %s",
91 (void *)hash_rxq, errno,
92 (errno ? strerror(errno) : "Unknown error"));
97 hash_rxq->promisc_flow = flow;
98 DEBUG("%p: promiscuous mode enabled", (void *)hash_rxq);
103 * Enable promiscuous mode in all hash RX queues.
109 * 0 on success, errno value on failure.
112 priv_promiscuous_enable(struct priv *priv)
116 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
117 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
120 ret = hash_rxq_promiscuous_enable(hash_rxq);
123 /* Failure, rollback. */
125 hash_rxq = &(*priv->hash_rxqs)[--i];
126 hash_rxq_promiscuous_disable(hash_rxq);
134 * DPDK callback to enable promiscuous mode.
137 * Pointer to Ethernet device structure.
140 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
142 struct priv *priv = dev->data->dev_private;
146 priv->promisc_req = 1;
147 ret = priv_promiscuous_enable(priv);
149 ERROR("cannot enable promiscuous mode: %s", strerror(ret));
154 * Disable promiscuous mode in a hash RX queue.
157 * Pointer to hash RX queue structure.
160 hash_rxq_promiscuous_disable(struct hash_rxq *hash_rxq)
162 if (hash_rxq->promisc_flow == NULL)
164 DEBUG("%p: disabling promiscuous mode", (void *)hash_rxq);
165 claim_zero(ibv_destroy_flow(hash_rxq->promisc_flow));
166 hash_rxq->promisc_flow = NULL;
167 DEBUG("%p: promiscuous mode disabled", (void *)hash_rxq);
171 * Disable promiscuous mode in all hash RX queues.
177 priv_promiscuous_disable(struct priv *priv)
181 for (i = 0; (i != priv->hash_rxqs_n); ++i)
182 hash_rxq_promiscuous_disable(&(*priv->hash_rxqs)[i]);
186 * DPDK callback to disable promiscuous mode.
189 * Pointer to Ethernet device structure.
192 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
194 struct priv *priv = dev->data->dev_private;
197 priv->promisc_req = 0;
198 priv_promiscuous_disable(priv);
203 * Enable allmulti mode in a hash RX queue.
206 * Pointer to hash RX queue structure.
209 * 0 on success, errno value on failure.
212 hash_rxq_allmulticast_enable(struct hash_rxq *hash_rxq)
214 struct ibv_flow *flow;
215 FLOW_ATTR_SPEC_ETH(data, hash_rxq_flow_attr(hash_rxq, NULL, 0));
216 struct ibv_flow_attr *attr = &data->attr;
217 struct ibv_flow_spec_eth *spec = &data->spec;
219 if (hash_rxq->allmulti_flow != NULL)
221 DEBUG("%p: enabling allmulticast mode", (void *)hash_rxq);
223 * No padding must be inserted by the compiler between attr and spec.
224 * This layout is expected by libibverbs.
226 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec);
227 hash_rxq_flow_attr(hash_rxq, attr, sizeof(data));
228 *spec = (struct ibv_flow_spec_eth){
229 .type = IBV_FLOW_SPEC_ETH,
230 .size = sizeof(*spec),
232 .dst_mac = "\x01\x00\x00\x00\x00\x00",
235 .dst_mac = "\x01\x00\x00\x00\x00\x00",
239 flow = ibv_create_flow(hash_rxq->qp, attr);
241 /* It's not clear whether errno is always set in this case. */
242 ERROR("%p: flow configuration failed, errno=%d: %s",
243 (void *)hash_rxq, errno,
244 (errno ? strerror(errno) : "Unknown error"));
249 hash_rxq->allmulti_flow = flow;
250 DEBUG("%p: allmulticast mode enabled", (void *)hash_rxq);
255 * Enable allmulti mode in most hash RX queues.
256 * TCP queues are exempted to save resources.
262 * 0 on success, errno value on failure.
265 priv_allmulticast_enable(struct priv *priv)
269 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
270 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
273 /* allmulticast not relevant for TCP. */
274 if (hash_rxq->type == HASH_RXQ_TCPV4)
276 ret = hash_rxq_allmulticast_enable(hash_rxq);
279 /* Failure, rollback. */
281 hash_rxq = &(*priv->hash_rxqs)[--i];
282 hash_rxq_allmulticast_disable(hash_rxq);
290 * DPDK callback to enable allmulti mode.
293 * Pointer to Ethernet device structure.
296 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
298 struct priv *priv = dev->data->dev_private;
302 priv->allmulti_req = 1;
303 ret = priv_allmulticast_enable(priv);
305 ERROR("cannot enable allmulticast mode: %s", strerror(ret));
310 * Disable allmulti mode in a hash RX queue.
313 * Pointer to hash RX queue structure.
316 hash_rxq_allmulticast_disable(struct hash_rxq *hash_rxq)
318 if (hash_rxq->allmulti_flow == NULL)
320 DEBUG("%p: disabling allmulticast mode", (void *)hash_rxq);
321 claim_zero(ibv_destroy_flow(hash_rxq->allmulti_flow));
322 hash_rxq->allmulti_flow = NULL;
323 DEBUG("%p: allmulticast mode disabled", (void *)hash_rxq);
327 * Disable allmulti mode in all hash RX queues.
333 priv_allmulticast_disable(struct priv *priv)
337 for (i = 0; (i != priv->hash_rxqs_n); ++i)
338 hash_rxq_allmulticast_disable(&(*priv->hash_rxqs)[i]);
342 * DPDK callback to disable allmulti mode.
345 * Pointer to Ethernet device structure.
348 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
350 struct priv *priv = dev->data->dev_private;
353 priv->allmulti_req = 0;
354 priv_allmulticast_disable(priv);