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 */
78 [HASH_RXQ_FLOW_TYPE_ALLMULTI] = {
79 .dst_mac_val = "\x01\x00\x00\x00\x00\x00",
80 .dst_mac_mask = "\x01\x00\x00\x00\x00\x00",
84 #ifdef HAVE_FLOW_SPEC_IPV6
87 #endif /* HAVE_FLOW_SPEC_IPV6 */
94 * Enable a special flow in a hash RX queue.
97 * Pointer to hash RX queue structure.
102 * 0 on success, errno value on failure.
105 hash_rxq_special_flow_enable(struct hash_rxq *hash_rxq,
106 enum hash_rxq_flow_type flow_type)
108 struct ibv_exp_flow *flow;
109 FLOW_ATTR_SPEC_ETH(data, hash_rxq_flow_attr(hash_rxq, NULL, 0));
110 struct ibv_exp_flow_attr *attr = &data->attr;
111 struct ibv_exp_flow_spec_eth *spec = &data->spec;
115 /* Check if flow is relevant for this hash_rxq. */
116 if (!(special_flow_init[flow_type].hash_types & (1 << hash_rxq->type)))
118 /* Check if flow already exists. */
119 if (hash_rxq->special_flow[flow_type] != NULL)
123 * No padding must be inserted by the compiler between attr and spec.
124 * This layout is expected by libibverbs.
126 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec);
127 hash_rxq_flow_attr(hash_rxq, attr, sizeof(data));
128 /* The first specification must be Ethernet. */
129 assert(spec->type == IBV_EXP_FLOW_SPEC_ETH);
130 assert(spec->size == sizeof(*spec));
132 mac = special_flow_init[flow_type].dst_mac_val;
133 mask = special_flow_init[flow_type].dst_mac_mask;
134 *spec = (struct ibv_exp_flow_spec_eth){
135 .type = IBV_EXP_FLOW_SPEC_ETH,
136 .size = sizeof(*spec),
139 mac[0], mac[1], mac[2],
140 mac[3], mac[4], mac[5],
145 mask[0], mask[1], mask[2],
146 mask[3], mask[4], mask[5],
152 flow = ibv_exp_create_flow(hash_rxq->qp, attr);
154 /* It's not clear whether errno is always set in this case. */
155 ERROR("%p: flow configuration failed, errno=%d: %s",
156 (void *)hash_rxq, errno,
157 (errno ? strerror(errno) : "Unknown error"));
162 hash_rxq->special_flow[flow_type] = flow;
163 DEBUG("%p: enabling special flow %s (%d)",
164 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type);
169 * Disable a special flow in a hash RX queue.
172 * Pointer to hash RX queue structure.
177 hash_rxq_special_flow_disable(struct hash_rxq *hash_rxq,
178 enum hash_rxq_flow_type flow_type)
180 if (hash_rxq->special_flow[flow_type] == NULL)
182 DEBUG("%p: disabling special flow %s (%d)",
183 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type);
184 claim_zero(ibv_exp_destroy_flow(hash_rxq->special_flow[flow_type]));
185 hash_rxq->special_flow[flow_type] = NULL;
186 DEBUG("%p: special flow %s (%d) disabled",
187 (void *)hash_rxq, hash_rxq_flow_type_str(flow_type), flow_type);
191 * Enable a special flow in all hash RX queues.
199 * 0 on success, errno value on failure.
202 priv_special_flow_enable(struct priv *priv, enum hash_rxq_flow_type flow_type)
206 if (!priv_allow_flow_type(priv, flow_type))
208 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
209 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
212 ret = hash_rxq_special_flow_enable(hash_rxq, flow_type);
215 /* Failure, rollback. */
217 hash_rxq = &(*priv->hash_rxqs)[--i];
218 hash_rxq_special_flow_disable(hash_rxq, flow_type);
226 * Disable a special flow in all hash RX queues.
234 priv_special_flow_disable(struct priv *priv, enum hash_rxq_flow_type flow_type)
238 for (i = 0; (i != priv->hash_rxqs_n); ++i) {
239 struct hash_rxq *hash_rxq = &(*priv->hash_rxqs)[i];
241 hash_rxq_special_flow_disable(hash_rxq, flow_type);
246 * DPDK callback to enable promiscuous mode.
249 * Pointer to Ethernet device structure.
252 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
254 struct priv *priv = dev->data->dev_private;
258 priv->promisc_req = 1;
259 ret = priv_rehash_flows(priv);
261 ERROR("error while enabling promiscuous mode: %s",
267 * DPDK callback to disable promiscuous mode.
270 * Pointer to Ethernet device structure.
273 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
275 struct priv *priv = dev->data->dev_private;
279 priv->promisc_req = 0;
280 ret = priv_rehash_flows(priv);
282 ERROR("error while disabling promiscuous mode: %s",
288 * DPDK callback to enable allmulti mode.
291 * Pointer to Ethernet device structure.
294 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
296 struct priv *priv = dev->data->dev_private;
300 priv->allmulti_req = 1;
301 ret = priv_rehash_flows(priv);
303 ERROR("error while enabling allmulticast mode: %s",
309 * DPDK callback to disable allmulti mode.
312 * Pointer to Ethernet device structure.
315 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
317 struct priv *priv = dev->data->dev_private;
321 priv->allmulti_req = 0;
322 ret = priv_rehash_flows(priv);
324 ERROR("error while disabling allmulticast mode: %s",