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 "-Wpedantic"
43 #include <infiniband/verbs.h>
45 #pragma GCC diagnostic error "-Wpedantic"
48 #include <rte_ethdev.h>
51 #include "mlx5_rxtx.h"
52 #include "mlx5_utils.h"
54 /* Initialization data for special flows. */
55 static const struct special_flow_init special_flow_init[] = {
56 [HASH_RXQ_FLOW_TYPE_PROMISC] = {
57 .dst_mac_val = "\x00\x00\x00\x00\x00\x00",
58 .dst_mac_mask = "\x00\x00\x00\x00\x00\x00",
70 [HASH_RXQ_FLOW_TYPE_ALLMULTI] = {
71 .dst_mac_val = "\x01\x00\x00\x00\x00\x00",
72 .dst_mac_mask = "\x01\x00\x00\x00\x00\x00",
82 [HASH_RXQ_FLOW_TYPE_BROADCAST] = {
83 .dst_mac_val = "\xff\xff\xff\xff\xff\xff",
84 .dst_mac_mask = "\xff\xff\xff\xff\xff\xff",
94 [HASH_RXQ_FLOW_TYPE_IPV6MULTI] = {
95 .dst_mac_val = "\x33\x33\x00\x00\x00\x00",
96 .dst_mac_mask = "\xff\xff\x00\x00\x00\x00",
107 * Enable a special flow in a hash RX queue for a given VLAN index.
110 * Pointer to hash RX queue structure.
117 * 0 on success, errno value on failure.
120 hash_rxq_special_flow_enable_vlan(struct hash_rxq *hash_rxq,
121 enum hash_rxq_flow_type flow_type,
122 unsigned int vlan_index)
124 struct priv *priv = hash_rxq->priv;
125 struct ibv_exp_flow *flow;
126 FLOW_ATTR_SPEC_ETH(data, priv_flow_attr(priv, NULL, 0, hash_rxq->type));
127 struct ibv_exp_flow_attr *attr = &data->attr;
128 struct ibv_exp_flow_spec_eth *spec = &data->spec;
131 unsigned int vlan_enabled = (priv->vlan_filter_n &&
132 special_flow_init[flow_type].per_vlan);
133 unsigned int vlan_id = priv->vlan_filter[vlan_index];
135 /* Check if flow is relevant for this hash_rxq. */
136 if (!(special_flow_init[flow_type].hash_types & (1 << hash_rxq->type)))
138 /* Check if flow already exists. */
139 if (hash_rxq->special_flow[flow_type][vlan_index] != NULL)
143 * No padding must be inserted by the compiler between attr and spec.
144 * This layout is expected by libibverbs.
146 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec);
147 priv_flow_attr(priv, attr, sizeof(data), hash_rxq->type);
148 /* The first specification must be Ethernet. */
149 assert(spec->type == IBV_EXP_FLOW_SPEC_ETH);
150 assert(spec->size == sizeof(*spec));
152 mac = special_flow_init[flow_type].dst_mac_val;
153 mask = special_flow_init[flow_type].dst_mac_mask;
154 *spec = (struct ibv_exp_flow_spec_eth){
155 .type = IBV_EXP_FLOW_SPEC_ETH,
156 .size = sizeof(*spec),
159 mac[0], mac[1], mac[2],
160 mac[3], mac[4], mac[5],
162 .vlan_tag = (vlan_enabled ?
163 rte_cpu_to_be_16(vlan_id) :
168 mask[0], mask[1], mask[2],
169 mask[3], mask[4], mask[5],
171 .vlan_tag = (vlan_enabled ?
172 rte_cpu_to_be_16(0xfff) :
178 flow = ibv_exp_create_flow(hash_rxq->qp, attr);
180 /* It's not clear whether errno is always set in this case. */
181 ERROR("%p: flow configuration failed, errno=%d: %s",
182 (void *)hash_rxq, errno,
183 (errno ? strerror(errno) : "Unknown error"));
188 hash_rxq->special_flow[flow_type][vlan_index] = flow;
189 DEBUG("%p: special flow %s (index %d) VLAN %u (index %u) enabled",
190 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type,
191 vlan_id, vlan_index);
196 * Disable a special flow in a hash RX queue for a given VLAN index.
199 * Pointer to hash RX queue structure.
206 hash_rxq_special_flow_disable_vlan(struct hash_rxq *hash_rxq,
207 enum hash_rxq_flow_type flow_type,
208 unsigned int vlan_index)
210 struct ibv_exp_flow *flow =
211 hash_rxq->special_flow[flow_type][vlan_index];
215 claim_zero(ibv_exp_destroy_flow(flow));
216 hash_rxq->special_flow[flow_type][vlan_index] = NULL;
217 DEBUG("%p: special flow %s (index %d) VLAN %u (index %u) disabled",
218 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type,
219 hash_rxq->priv->vlan_filter[vlan_index], vlan_index);
223 * Enable a special flow in a hash RX queue.
226 * Pointer to hash RX queue structure.
233 * 0 on success, errno value on failure.
236 hash_rxq_special_flow_enable(struct hash_rxq *hash_rxq,
237 enum hash_rxq_flow_type flow_type)
239 struct priv *priv = hash_rxq->priv;
243 assert((unsigned int)flow_type < RTE_DIM(hash_rxq->special_flow));
244 assert(RTE_DIM(hash_rxq->special_flow[flow_type]) ==
245 RTE_DIM(priv->vlan_filter));
246 /* Add a special flow for each VLAN filter when relevant. */
248 ret = hash_rxq_special_flow_enable_vlan(hash_rxq, flow_type, i);
250 /* Failure, rollback. */
252 hash_rxq_special_flow_disable_vlan(hash_rxq,
257 } while (special_flow_init[flow_type].per_vlan &&
258 ++i < priv->vlan_filter_n);
263 * Disable a special flow in a hash RX queue.
266 * Pointer to hash RX queue structure.
271 hash_rxq_special_flow_disable(struct hash_rxq *hash_rxq,
272 enum hash_rxq_flow_type flow_type)
276 assert((unsigned int)flow_type < RTE_DIM(hash_rxq->special_flow));
277 for (i = 0; (i != RTE_DIM(hash_rxq->special_flow[flow_type])); ++i)
278 hash_rxq_special_flow_disable_vlan(hash_rxq, flow_type, i);
282 * Enable a special flow in all hash RX queues.
290 * 0 on success, errno value on failure.
293 priv_special_flow_enable(struct priv *priv, enum hash_rxq_flow_type flow_type)
297 if (!priv_allow_flow_type(priv, flow_type))
299 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
300 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
303 ret = hash_rxq_special_flow_enable(hash_rxq, flow_type);
306 /* Failure, rollback. */
308 hash_rxq = &(*priv->hash_rxqs)[--i];
309 hash_rxq_special_flow_disable(hash_rxq, flow_type);
317 * Disable a special flow in all hash RX queues.
325 priv_special_flow_disable(struct priv *priv, enum hash_rxq_flow_type flow_type)
329 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
330 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
332 hash_rxq_special_flow_disable(hash_rxq, flow_type);
337 * Enable all special flows in all hash RX queues.
343 priv_special_flow_enable_all(struct priv *priv)
345 enum hash_rxq_flow_type flow_type;
349 for (flow_type = HASH_RXQ_FLOW_TYPE_PROMISC;
350 flow_type != HASH_RXQ_FLOW_TYPE_MAC;
354 ret = priv_special_flow_enable(priv, flow_type);
357 /* Failure, rollback. */
359 priv_special_flow_disable(priv, --flow_type);
366 * Disable all special flows in all hash RX queues.
372 priv_special_flow_disable_all(struct priv *priv)
374 enum hash_rxq_flow_type flow_type;
376 for (flow_type = HASH_RXQ_FLOW_TYPE_PROMISC;
377 flow_type != HASH_RXQ_FLOW_TYPE_MAC;
379 priv_special_flow_disable(priv, flow_type);
383 * DPDK callback to enable promiscuous mode.
386 * Pointer to Ethernet device structure.
389 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
391 struct priv *priv = dev->data->dev_private;
394 if (mlx5_is_secondary())
398 priv->promisc_req = 1;
399 ret = priv_rehash_flows(priv);
401 ERROR("error while enabling promiscuous mode: %s",
407 * DPDK callback to disable promiscuous mode.
410 * Pointer to Ethernet device structure.
413 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
415 struct priv *priv = dev->data->dev_private;
418 if (mlx5_is_secondary())
422 priv->promisc_req = 0;
423 ret = priv_rehash_flows(priv);
425 ERROR("error while disabling promiscuous mode: %s",
431 * DPDK callback to enable allmulti mode.
434 * Pointer to Ethernet device structure.
437 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
439 struct priv *priv = dev->data->dev_private;
442 if (mlx5_is_secondary())
446 priv->allmulti_req = 1;
447 ret = priv_rehash_flows(priv);
449 ERROR("error while enabling allmulticast mode: %s",
455 * DPDK callback to disable allmulti mode.
458 * Pointer to Ethernet device structure.
461 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
463 struct priv *priv = dev->data->dev_private;
466 if (mlx5_is_secondary())
470 priv->allmulti_req = 0;
471 ret = priv_rehash_flows(priv);
473 ERROR("error while disabling allmulticast mode: %s",