xref: /dpdk/drivers/net/mlx5/mlx5_rxmode.c (revision 25d11a86c56d50947af33d0b79ede622809bd8b9)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2015 6WIND S.A.
3  * Copyright 2015 Mellanox Technologies, Ltd
4  */
5 
6 #include <stddef.h>
7 #include <errno.h>
8 #include <string.h>
9 
10 /* Verbs header. */
11 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
12 #ifdef PEDANTIC
13 #pragma GCC diagnostic ignored "-Wpedantic"
14 #endif
15 #include <infiniband/verbs.h>
16 #ifdef PEDANTIC
17 #pragma GCC diagnostic error "-Wpedantic"
18 #endif
19 
20 #include <rte_ethdev_driver.h>
21 
22 #include "mlx5.h"
23 #include "mlx5_rxtx.h"
24 #include "mlx5_utils.h"
25 
26 /**
27  * DPDK callback to enable promiscuous mode.
28  *
29  * @param dev
30  *   Pointer to Ethernet device structure.
31  */
32 void
33 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
34 {
35 	struct priv *priv = dev->data->dev_private;
36 	int ret;
37 
38 	dev->data->promiscuous = 1;
39 	if (priv->isolated) {
40 		DRV_LOG(WARNING,
41 			"port %u cannot enable promiscuous mode"
42 			" in flow isolation mode",
43 			dev->data->port_id);
44 		return;
45 	}
46 	if (priv->config.vf)
47 		mlx5_nl_promisc(dev, 1);
48 	ret = mlx5_traffic_restart(dev);
49 	if (ret)
50 		DRV_LOG(ERR, "port %u cannot enable promiscuous mode: %s",
51 			dev->data->port_id, strerror(rte_errno));
52 }
53 
54 /**
55  * DPDK callback to disable promiscuous mode.
56  *
57  * @param dev
58  *   Pointer to Ethernet device structure.
59  */
60 void
61 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
62 {
63 	struct priv *priv = dev->data->dev_private;
64 	int ret;
65 
66 	dev->data->promiscuous = 0;
67 	if (priv->config.vf)
68 		mlx5_nl_promisc(dev, 0);
69 	ret = mlx5_traffic_restart(dev);
70 	if (ret)
71 		DRV_LOG(ERR, "port %u cannot disable promiscuous mode: %s",
72 			dev->data->port_id, strerror(rte_errno));
73 }
74 
75 /**
76  * DPDK callback to enable allmulti mode.
77  *
78  * @param dev
79  *   Pointer to Ethernet device structure.
80  */
81 void
82 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
83 {
84 	struct priv *priv = dev->data->dev_private;
85 	int ret;
86 
87 	dev->data->all_multicast = 1;
88 	if (priv->isolated) {
89 		DRV_LOG(WARNING,
90 			"port %u cannot enable allmulticast mode"
91 			" in flow isolation mode",
92 			dev->data->port_id);
93 		return;
94 	}
95 	if (priv->config.vf)
96 		mlx5_nl_allmulti(dev, 1);
97 	ret = mlx5_traffic_restart(dev);
98 	if (ret)
99 		DRV_LOG(ERR, "port %u cannot enable allmulicast mode: %s",
100 			dev->data->port_id, strerror(rte_errno));
101 }
102 
103 /**
104  * DPDK callback to disable allmulti mode.
105  *
106  * @param dev
107  *   Pointer to Ethernet device structure.
108  */
109 void
110 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
111 {
112 	struct priv *priv = dev->data->dev_private;
113 	int ret;
114 
115 	dev->data->all_multicast = 0;
116 	if (priv->config.vf)
117 		mlx5_nl_allmulti(dev, 0);
118 	ret = mlx5_traffic_restart(dev);
119 	if (ret)
120 		DRV_LOG(ERR, "port %u cannot disable allmulicast mode: %s",
121 			dev->data->port_id, strerror(rte_errno));
122 }
123