760cc2f0b0d9bca080a1d68fa5373d43ecd882d4
[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  * @return
106  *   0 on success, a negative errno value otherwise and rte_errno is set.
107  */
108 int
109 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
110 {
111         struct mlx5_priv *priv = dev->data->dev_private;
112         int ret;
113
114         dev->data->all_multicast = 1;
115         if (priv->isolated) {
116                 DRV_LOG(WARNING,
117                         "port %u cannot enable allmulticast mode"
118                         " in flow isolation mode",
119                         dev->data->port_id);
120                 return 0;
121         }
122         if (priv->config.vf) {
123                 ret = mlx5_nl_allmulti(dev, 1);
124                 if (ret)
125                         goto error;
126         }
127         ret = mlx5_traffic_restart(dev);
128         if (ret)
129                 DRV_LOG(ERR, "port %u cannot enable allmulicast mode: %s",
130                         dev->data->port_id, strerror(rte_errno));
131 error:
132         /*
133          * rte_eth_allmulticast_enable() rollback
134          * dev->data->all_multicast in the case of failure.
135          */
136         return ret;
137 }
138
139 /**
140  * DPDK callback to disable allmulti mode.
141  *
142  * @param dev
143  *   Pointer to Ethernet device structure.
144  *
145  * @return
146  *   0 on success, a negative errno value otherwise and rte_errno is set.
147  */
148 int
149 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
150 {
151         struct mlx5_priv *priv = dev->data->dev_private;
152         int ret;
153
154         dev->data->all_multicast = 0;
155         if (priv->config.vf) {
156                 ret = mlx5_nl_allmulti(dev, 0);
157                 if (ret)
158                         goto error;
159         }
160         ret = mlx5_traffic_restart(dev);
161         if (ret)
162                 DRV_LOG(ERR, "port %u cannot disable allmulicast mode: %s",
163                         dev->data->port_id, strerror(rte_errno));
164 error:
165         /*
166          * rte_eth_allmulticast_disable() rollback
167          * dev->data->all_multicast in the case of failure.
168          */
169         return ret;
170 }