56fc1b636de7cda0afd0052603fd64a3d4128bfe
[dpdk.git] / drivers / net / mlx5 / mlx5_rxmode.c
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  * @return
33  *   0 on success, a negative errno value otherwise and rte_errno is set.
34  */
35 int
36 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
37 {
38         struct mlx5_priv *priv = dev->data->dev_private;
39         int ret;
40
41         dev->data->promiscuous = 1;
42         if (priv->isolated) {
43                 DRV_LOG(WARNING,
44                         "port %u cannot enable promiscuous mode"
45                         " in flow isolation mode",
46                         dev->data->port_id);
47                 return 0;
48         }
49         if (priv->config.vf) {
50                 ret = mlx5_nl_promisc(dev, 1);
51                 if (ret)
52                         return ret;
53         }
54         ret = mlx5_traffic_restart(dev);
55         if (ret)
56                 DRV_LOG(ERR, "port %u cannot enable promiscuous mode: %s",
57                         dev->data->port_id, strerror(rte_errno));
58
59         /*
60          * rte_eth_dev_promiscuous_enable() rollback
61          * dev->data->promiscuous in the case of failure.
62          */
63         return ret;
64 }
65
66 /**
67  * DPDK callback to disable promiscuous mode.
68  *
69  * @param dev
70  *   Pointer to Ethernet device structure.
71  *
72  * @return
73  *   0 on success, a negative errno value otherwise and rte_errno is set.
74  */
75 int
76 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
77 {
78         struct mlx5_priv *priv = dev->data->dev_private;
79         int ret;
80
81         dev->data->promiscuous = 0;
82         if (priv->config.vf) {
83                 ret = mlx5_nl_promisc(dev, 0);
84                 if (ret)
85                         return ret;
86         }
87         ret = mlx5_traffic_restart(dev);
88         if (ret)
89                 DRV_LOG(ERR, "port %u cannot disable promiscuous mode: %s",
90                         dev->data->port_id, strerror(rte_errno));
91
92         /*
93          * rte_eth_dev_promiscuous_disable() rollback
94          * dev->data->promiscuous in the case of failure.
95          */
96         return ret;
97 }
98
99 /**
100  * DPDK callback to enable allmulti mode.
101  *
102  * @param dev
103  *   Pointer to Ethernet device structure.
104  */
105 void
106 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
107 {
108         struct mlx5_priv *priv = dev->data->dev_private;
109         int ret;
110
111         dev->data->all_multicast = 1;
112         if (priv->isolated) {
113                 DRV_LOG(WARNING,
114                         "port %u cannot enable allmulticast mode"
115                         " in flow isolation mode",
116                         dev->data->port_id);
117                 return;
118         }
119         if (priv->config.vf)
120                 mlx5_nl_allmulti(dev, 1);
121         ret = mlx5_traffic_restart(dev);
122         if (ret)
123                 DRV_LOG(ERR, "port %u cannot enable allmulicast mode: %s",
124                         dev->data->port_id, strerror(rte_errno));
125 }
126
127 /**
128  * DPDK callback to disable allmulti mode.
129  *
130  * @param dev
131  *   Pointer to Ethernet device structure.
132  */
133 void
134 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
135 {
136         struct mlx5_priv *priv = dev->data->dev_private;
137         int ret;
138
139         dev->data->all_multicast = 0;
140         if (priv->config.vf)
141                 mlx5_nl_allmulti(dev, 0);
142         ret = mlx5_traffic_restart(dev);
143         if (ret)
144                 DRV_LOG(ERR, "port %u cannot disable allmulicast mode: %s",
145                         dev->data->port_id, strerror(rte_errno));
146 }