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"
62 * Enable promiscuous mode in a RX queue.
65 * Pointer to RX queue structure.
68 * 0 on success, errno value on failure.
71 rxq_promiscuous_enable(struct rxq *rxq)
73 struct ibv_flow *flow;
74 struct ibv_flow_attr attr = {
75 .type = IBV_FLOW_ATTR_ALL_DEFAULT,
77 .port = rxq->priv->port,
83 if (rxq->promisc_flow != NULL)
85 DEBUG("%p: enabling promiscuous mode", (void *)rxq);
87 flow = ibv_create_flow(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",
92 (errno ? strerror(errno) : "Unknown error"));
97 rxq->promisc_flow = flow;
98 DEBUG("%p: promiscuous mode enabled", (void *)rxq);
103 * DPDK callback to enable promiscuous mode.
106 * Pointer to Ethernet device structure.
109 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
111 struct priv *priv = dev->data->dev_private;
116 priv->promisc_req = 1;
117 /* If device isn't started, this is all we need to do. */
121 ret = rxq_promiscuous_enable(&priv->rxq_parent);
128 for (i = 0; (i != priv->rxqs_n); ++i) {
129 if ((*priv->rxqs)[i] == NULL)
131 ret = rxq_promiscuous_enable((*priv->rxqs)[i]);
134 /* Failure, rollback. */
136 if ((*priv->rxqs)[--i] != NULL)
137 rxq_promiscuous_disable((*priv->rxqs)[i]);
146 * Disable promiscuous mode in a RX queue.
149 * Pointer to RX queue structure.
152 rxq_promiscuous_disable(struct rxq *rxq)
156 if (rxq->promisc_flow == NULL)
158 DEBUG("%p: disabling promiscuous mode", (void *)rxq);
159 claim_zero(ibv_destroy_flow(rxq->promisc_flow));
160 rxq->promisc_flow = NULL;
161 DEBUG("%p: promiscuous mode disabled", (void *)rxq);
165 * DPDK callback to disable promiscuous mode.
168 * Pointer to Ethernet device structure.
171 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
173 struct priv *priv = dev->data->dev_private;
177 priv->promisc_req = 0;
179 rxq_promiscuous_disable(&priv->rxq_parent);
182 for (i = 0; (i != priv->rxqs_n); ++i)
183 if ((*priv->rxqs)[i] != NULL)
184 rxq_promiscuous_disable((*priv->rxqs)[i]);
190 * Enable allmulti mode in a RX queue.
193 * Pointer to RX queue structure.
196 * 0 on success, errno value on failure.
199 rxq_allmulticast_enable(struct rxq *rxq)
201 struct ibv_flow *flow;
202 struct ibv_flow_attr attr = {
203 .type = IBV_FLOW_ATTR_MC_DEFAULT,
205 .port = rxq->priv->port,
209 if (rxq->allmulti_flow != NULL)
211 DEBUG("%p: enabling allmulticast mode", (void *)rxq);
213 flow = ibv_create_flow(rxq->qp, &attr);
215 /* It's not clear whether errno is always set in this case. */
216 ERROR("%p: flow configuration failed, errno=%d: %s",
218 (errno ? strerror(errno) : "Unknown error"));
223 rxq->allmulti_flow = flow;
224 DEBUG("%p: allmulticast mode enabled", (void *)rxq);
229 * DPDK callback to enable allmulti mode.
232 * Pointer to Ethernet device structure.
235 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
237 struct priv *priv = dev->data->dev_private;
242 priv->allmulti_req = 1;
243 /* If device isn't started, this is all we need to do. */
247 ret = rxq_allmulticast_enable(&priv->rxq_parent);
254 for (i = 0; (i != priv->rxqs_n); ++i) {
255 if ((*priv->rxqs)[i] == NULL)
257 ret = rxq_allmulticast_enable((*priv->rxqs)[i]);
260 /* Failure, rollback. */
262 if ((*priv->rxqs)[--i] != NULL)
263 rxq_allmulticast_disable((*priv->rxqs)[i]);
272 * Disable allmulti mode in a RX queue.
275 * Pointer to RX queue structure.
278 rxq_allmulticast_disable(struct rxq *rxq)
280 if (rxq->allmulti_flow == NULL)
282 DEBUG("%p: disabling allmulticast mode", (void *)rxq);
283 claim_zero(ibv_destroy_flow(rxq->allmulti_flow));
284 rxq->allmulti_flow = NULL;
285 DEBUG("%p: allmulticast mode disabled", (void *)rxq);
289 * DPDK callback to disable allmulti mode.
292 * Pointer to Ethernet device structure.
295 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
297 struct priv *priv = dev->data->dev_private;
301 priv->allmulti_req = 0;
303 rxq_allmulticast_disable(&priv->rxq_parent);
306 for (i = 0; (i != priv->rxqs_n); ++i)
307 if ((*priv->rxqs)[i] != NULL)
308 rxq_allmulticast_disable((*priv->rxqs)[i]);