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 /* Initialization data for special flows. */
62 static const struct special_flow_init special_flow_init[] = {
63 [HASH_RXQ_FLOW_TYPE_PROMISC] = {
64 .dst_mac_val = "\x00\x00\x00\x00\x00\x00",
65 .dst_mac_mask = "\x00\x00\x00\x00\x00\x00",
70 #ifdef HAVE_FLOW_SPEC_IPV6
74 #endif /* HAVE_FLOW_SPEC_IPV6 */
79 [HASH_RXQ_FLOW_TYPE_ALLMULTI] = {
80 .dst_mac_val = "\x01\x00\x00\x00\x00\x00",
81 .dst_mac_mask = "\x01\x00\x00\x00\x00\x00",
85 #ifdef HAVE_FLOW_SPEC_IPV6
88 #endif /* HAVE_FLOW_SPEC_IPV6 */
93 [HASH_RXQ_FLOW_TYPE_BROADCAST] = {
94 .dst_mac_val = "\xff\xff\xff\xff\xff\xff",
95 .dst_mac_mask = "\xff\xff\xff\xff\xff\xff",
99 #ifdef HAVE_FLOW_SPEC_IPV6
100 1 << HASH_RXQ_UDPV6 |
102 #endif /* HAVE_FLOW_SPEC_IPV6 */
107 #ifdef HAVE_FLOW_SPEC_IPV6
108 [HASH_RXQ_FLOW_TYPE_IPV6MULTI] = {
109 .dst_mac_val = "\x33\x33\x00\x00\x00\x00",
110 .dst_mac_mask = "\xff\xff\x00\x00\x00\x00",
112 1 << HASH_RXQ_UDPV6 |
118 #endif /* HAVE_FLOW_SPEC_IPV6 */
122 * Enable a special flow in a hash RX queue for a given VLAN index.
125 * Pointer to hash RX queue structure.
132 * 0 on success, errno value on failure.
135 hash_rxq_special_flow_enable_vlan(struct hash_rxq *hash_rxq,
136 enum hash_rxq_flow_type flow_type,
137 unsigned int vlan_index)
139 struct priv *priv = hash_rxq->priv;
140 struct ibv_exp_flow *flow;
141 FLOW_ATTR_SPEC_ETH(data, priv_flow_attr(priv, NULL, 0, hash_rxq->type));
142 struct ibv_exp_flow_attr *attr = &data->attr;
143 struct ibv_exp_flow_spec_eth *spec = &data->spec;
146 unsigned int vlan_enabled = (priv->vlan_filter_n &&
147 special_flow_init[flow_type].per_vlan);
148 unsigned int vlan_id = priv->vlan_filter[vlan_index];
150 /* Check if flow is relevant for this hash_rxq. */
151 if (!(special_flow_init[flow_type].hash_types & (1 << hash_rxq->type)))
153 /* Check if flow already exists. */
154 if (hash_rxq->special_flow[flow_type][vlan_index] != NULL)
158 * No padding must be inserted by the compiler between attr and spec.
159 * This layout is expected by libibverbs.
161 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec);
162 priv_flow_attr(priv, attr, sizeof(data), hash_rxq->type);
163 /* The first specification must be Ethernet. */
164 assert(spec->type == IBV_EXP_FLOW_SPEC_ETH);
165 assert(spec->size == sizeof(*spec));
167 mac = special_flow_init[flow_type].dst_mac_val;
168 mask = special_flow_init[flow_type].dst_mac_mask;
169 *spec = (struct ibv_exp_flow_spec_eth){
170 .type = IBV_EXP_FLOW_SPEC_ETH,
171 .size = sizeof(*spec),
174 mac[0], mac[1], mac[2],
175 mac[3], mac[4], mac[5],
177 .vlan_tag = (vlan_enabled ? htons(vlan_id) : 0),
181 mask[0], mask[1], mask[2],
182 mask[3], mask[4], mask[5],
184 .vlan_tag = (vlan_enabled ? htons(0xfff) : 0),
189 flow = ibv_exp_create_flow(hash_rxq->qp, attr);
191 /* It's not clear whether errno is always set in this case. */
192 ERROR("%p: flow configuration failed, errno=%d: %s",
193 (void *)hash_rxq, errno,
194 (errno ? strerror(errno) : "Unknown error"));
199 hash_rxq->special_flow[flow_type][vlan_index] = flow;
200 DEBUG("%p: special flow %s (index %d) VLAN %u (index %u) enabled",
201 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type,
202 vlan_id, vlan_index);
207 * Disable a special flow in a hash RX queue for a given VLAN index.
210 * Pointer to hash RX queue structure.
217 hash_rxq_special_flow_disable_vlan(struct hash_rxq *hash_rxq,
218 enum hash_rxq_flow_type flow_type,
219 unsigned int vlan_index)
221 struct ibv_exp_flow *flow =
222 hash_rxq->special_flow[flow_type][vlan_index];
226 claim_zero(ibv_exp_destroy_flow(flow));
227 hash_rxq->special_flow[flow_type][vlan_index] = NULL;
228 DEBUG("%p: special flow %s (index %d) VLAN %u (index %u) disabled",
229 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type,
230 hash_rxq->priv->vlan_filter[vlan_index], vlan_index);
234 * Enable a special flow in a hash RX queue.
237 * Pointer to hash RX queue structure.
244 * 0 on success, errno value on failure.
247 hash_rxq_special_flow_enable(struct hash_rxq *hash_rxq,
248 enum hash_rxq_flow_type flow_type)
250 struct priv *priv = hash_rxq->priv;
254 assert((unsigned int)flow_type < RTE_DIM(hash_rxq->special_flow));
255 assert(RTE_DIM(hash_rxq->special_flow[flow_type]) ==
256 RTE_DIM(priv->vlan_filter));
257 /* Add a special flow for each VLAN filter when relevant. */
259 ret = hash_rxq_special_flow_enable_vlan(hash_rxq, flow_type, i);
261 /* Failure, rollback. */
263 hash_rxq_special_flow_disable_vlan(hash_rxq,
268 } while (special_flow_init[flow_type].per_vlan &&
269 ++i < priv->vlan_filter_n);
274 * Disable a special flow in a hash RX queue.
277 * Pointer to hash RX queue structure.
282 hash_rxq_special_flow_disable(struct hash_rxq *hash_rxq,
283 enum hash_rxq_flow_type flow_type)
287 assert((unsigned int)flow_type < RTE_DIM(hash_rxq->special_flow));
288 for (i = 0; (i != RTE_DIM(hash_rxq->special_flow[flow_type])); ++i)
289 hash_rxq_special_flow_disable_vlan(hash_rxq, flow_type, i);
293 * Enable a special flow in all hash RX queues.
301 * 0 on success, errno value on failure.
304 priv_special_flow_enable(struct priv *priv, enum hash_rxq_flow_type flow_type)
308 if (!priv_allow_flow_type(priv, flow_type))
310 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
311 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
314 ret = hash_rxq_special_flow_enable(hash_rxq, flow_type);
317 /* Failure, rollback. */
319 hash_rxq = &(*priv->hash_rxqs)[--i];
320 hash_rxq_special_flow_disable(hash_rxq, flow_type);
328 * Disable a special flow in all hash RX queues.
336 priv_special_flow_disable(struct priv *priv, enum hash_rxq_flow_type flow_type)
340 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
341 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
343 hash_rxq_special_flow_disable(hash_rxq, flow_type);
348 * Enable all special flows in all hash RX queues.
354 priv_special_flow_enable_all(struct priv *priv)
356 enum hash_rxq_flow_type flow_type;
358 for (flow_type = 0; flow_type != HASH_RXQ_FLOW_TYPE_MAC; ++flow_type) {
361 ret = priv_special_flow_enable(priv, flow_type);
364 /* Failure, rollback. */
366 priv_special_flow_disable(priv, --flow_type);
373 * Disable all special flows in all hash RX queues.
379 priv_special_flow_disable_all(struct priv *priv)
381 enum hash_rxq_flow_type flow_type;
383 for (flow_type = 0; flow_type != HASH_RXQ_FLOW_TYPE_MAC; ++flow_type)
384 priv_special_flow_disable(priv, flow_type);
388 * DPDK callback to enable promiscuous mode.
391 * Pointer to Ethernet device structure.
394 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
396 struct priv *priv = dev->data->dev_private;
399 if (mlx5_is_secondary())
403 priv->promisc_req = 1;
404 ret = priv_rehash_flows(priv);
406 ERROR("error while enabling promiscuous mode: %s",
412 * DPDK callback to disable promiscuous mode.
415 * Pointer to Ethernet device structure.
418 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
420 struct priv *priv = dev->data->dev_private;
423 if (mlx5_is_secondary())
427 priv->promisc_req = 0;
428 ret = priv_rehash_flows(priv);
430 ERROR("error while disabling promiscuous mode: %s",
436 * DPDK callback to enable allmulti mode.
439 * Pointer to Ethernet device structure.
442 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
444 struct priv *priv = dev->data->dev_private;
447 if (mlx5_is_secondary())
451 priv->allmulti_req = 1;
452 ret = priv_rehash_flows(priv);
454 ERROR("error while enabling allmulticast mode: %s",
460 * DPDK callback to disable allmulti mode.
463 * Pointer to Ethernet device structure.
466 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
468 struct priv *priv = dev->data->dev_private;
471 if (mlx5_is_secondary())
475 priv->allmulti_req = 0;
476 ret = priv_rehash_flows(priv);
478 ERROR("error while disabling allmulticast mode: %s",