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_exp_flow *flow;
77 FLOW_ATTR_SPEC_ETH(data, hash_rxq_flow_attr(hash_rxq, NULL, 0));
78 struct ibv_exp_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_exp_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 if (!priv_allow_flow_type(priv, HASH_RXQ_FLOW_TYPE_PROMISC))
118 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
119 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
122 ret = hash_rxq_promiscuous_enable(hash_rxq);
125 /* Failure, rollback. */
127 hash_rxq = &(*priv->hash_rxqs)[--i];
128 hash_rxq_promiscuous_disable(hash_rxq);
136 * DPDK callback to enable promiscuous mode.
139 * Pointer to Ethernet device structure.
142 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
144 struct priv *priv = dev->data->dev_private;
148 priv->promisc_req = 1;
149 ret = priv_promiscuous_enable(priv);
151 ERROR("cannot enable promiscuous mode: %s", strerror(ret));
153 priv_mac_addrs_disable(priv);
154 priv_allmulticast_disable(priv);
160 * Disable promiscuous mode in a hash RX queue.
163 * Pointer to hash RX queue structure.
166 hash_rxq_promiscuous_disable(struct hash_rxq *hash_rxq)
168 if (hash_rxq->promisc_flow == NULL)
170 DEBUG("%p: disabling promiscuous mode", (void *)hash_rxq);
171 claim_zero(ibv_exp_destroy_flow(hash_rxq->promisc_flow));
172 hash_rxq->promisc_flow = NULL;
173 DEBUG("%p: promiscuous mode disabled", (void *)hash_rxq);
177 * Disable promiscuous mode in all hash RX queues.
183 priv_promiscuous_disable(struct priv *priv)
187 for (i = 0; (i != priv->hash_rxqs_n); ++i)
188 hash_rxq_promiscuous_disable(&(*priv->hash_rxqs)[i]);
192 * DPDK callback to disable promiscuous mode.
195 * Pointer to Ethernet device structure.
198 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
200 struct priv *priv = dev->data->dev_private;
203 priv->promisc_req = 0;
204 priv_promiscuous_disable(priv);
205 priv_mac_addrs_enable(priv);
206 priv_allmulticast_enable(priv);
211 * Enable allmulti mode in a hash RX queue.
214 * Pointer to hash RX queue structure.
217 * 0 on success, errno value on failure.
220 hash_rxq_allmulticast_enable(struct hash_rxq *hash_rxq)
222 struct ibv_exp_flow *flow;
223 FLOW_ATTR_SPEC_ETH(data, hash_rxq_flow_attr(hash_rxq, NULL, 0));
224 struct ibv_exp_flow_attr *attr = &data->attr;
225 struct ibv_exp_flow_spec_eth *spec = &data->spec;
227 if (hash_rxq->allmulti_flow != NULL)
229 DEBUG("%p: enabling allmulticast mode", (void *)hash_rxq);
231 * No padding must be inserted by the compiler between attr and spec.
232 * This layout is expected by libibverbs.
234 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec);
235 hash_rxq_flow_attr(hash_rxq, attr, sizeof(data));
236 *spec = (struct ibv_exp_flow_spec_eth){
237 .type = IBV_EXP_FLOW_SPEC_ETH,
238 .size = sizeof(*spec),
240 .dst_mac = "\x01\x00\x00\x00\x00\x00",
243 .dst_mac = "\x01\x00\x00\x00\x00\x00",
247 flow = ibv_exp_create_flow(hash_rxq->qp, attr);
249 /* It's not clear whether errno is always set in this case. */
250 ERROR("%p: flow configuration failed, errno=%d: %s",
251 (void *)hash_rxq, errno,
252 (errno ? strerror(errno) : "Unknown error"));
257 hash_rxq->allmulti_flow = flow;
258 DEBUG("%p: allmulticast mode enabled", (void *)hash_rxq);
263 * Enable allmulti mode in most hash RX queues.
264 * TCP queues are exempted to save resources.
270 * 0 on success, errno value on failure.
273 priv_allmulticast_enable(struct priv *priv)
277 if (!priv_allow_flow_type(priv, HASH_RXQ_FLOW_TYPE_ALLMULTI))
279 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
280 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
283 /* allmulticast not relevant for TCP. */
284 if (hash_rxq->type == HASH_RXQ_TCPV4)
286 ret = hash_rxq_allmulticast_enable(hash_rxq);
289 /* Failure, rollback. */
291 hash_rxq = &(*priv->hash_rxqs)[--i];
292 hash_rxq_allmulticast_disable(hash_rxq);
300 * DPDK callback to enable allmulti mode.
303 * Pointer to Ethernet device structure.
306 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
308 struct priv *priv = dev->data->dev_private;
312 priv->allmulti_req = 1;
313 ret = priv_allmulticast_enable(priv);
315 ERROR("cannot enable allmulticast mode: %s", strerror(ret));
320 * Disable allmulti mode in a hash RX queue.
323 * Pointer to hash RX queue structure.
326 hash_rxq_allmulticast_disable(struct hash_rxq *hash_rxq)
328 if (hash_rxq->allmulti_flow == NULL)
330 DEBUG("%p: disabling allmulticast mode", (void *)hash_rxq);
331 claim_zero(ibv_exp_destroy_flow(hash_rxq->allmulti_flow));
332 hash_rxq->allmulti_flow = NULL;
333 DEBUG("%p: allmulticast mode disabled", (void *)hash_rxq);
337 * Disable allmulti mode in all hash RX queues.
343 priv_allmulticast_disable(struct priv *priv)
347 for (i = 0; (i != priv->hash_rxqs_n); ++i)
348 hash_rxq_allmulticast_disable(&(*priv->hash_rxqs)[i]);
352 * DPDK callback to disable allmulti mode.
355 * Pointer to Ethernet device structure.
358 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
360 struct priv *priv = dev->data->dev_private;
363 priv->allmulti_req = 0;
364 priv_allmulticast_disable(priv);