net/mlx5: fix packet length assert in MPRQ
[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(priv->nl_socket_route, mlx5_ifindex(dev),
51                                       1);
52                 if (ret)
53                         return ret;
54         }
55         ret = mlx5_traffic_restart(dev);
56         if (ret)
57                 DRV_LOG(ERR, "port %u cannot enable promiscuous mode: %s",
58                         dev->data->port_id, strerror(rte_errno));
59
60         /*
61          * rte_eth_dev_promiscuous_enable() rollback
62          * dev->data->promiscuous in the case of failure.
63          */
64         return ret;
65 }
66
67 /**
68  * DPDK callback to disable promiscuous mode.
69  *
70  * @param dev
71  *   Pointer to Ethernet device structure.
72  *
73  * @return
74  *   0 on success, a negative errno value otherwise and rte_errno is set.
75  */
76 int
77 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
78 {
79         struct mlx5_priv *priv = dev->data->dev_private;
80         int ret;
81
82         dev->data->promiscuous = 0;
83         if (priv->config.vf) {
84                 ret = mlx5_nl_promisc(priv->nl_socket_route, mlx5_ifindex(dev),
85                                       0);
86                 if (ret)
87                         return ret;
88         }
89         ret = mlx5_traffic_restart(dev);
90         if (ret)
91                 DRV_LOG(ERR, "port %u cannot disable promiscuous mode: %s",
92                         dev->data->port_id, strerror(rte_errno));
93
94         /*
95          * rte_eth_dev_promiscuous_disable() rollback
96          * dev->data->promiscuous in the case of failure.
97          */
98         return ret;
99 }
100
101 /**
102  * DPDK callback to enable allmulti mode.
103  *
104  * @param dev
105  *   Pointer to Ethernet device structure.
106  *
107  * @return
108  *   0 on success, a negative errno value otherwise and rte_errno is set.
109  */
110 int
111 mlx5_allmulticast_enable(struct rte_eth_dev *dev)
112 {
113         struct mlx5_priv *priv = dev->data->dev_private;
114         int ret;
115
116         dev->data->all_multicast = 1;
117         if (priv->isolated) {
118                 DRV_LOG(WARNING,
119                         "port %u cannot enable allmulticast mode"
120                         " in flow isolation mode",
121                         dev->data->port_id);
122                 return 0;
123         }
124         if (priv->config.vf) {
125                 ret = mlx5_nl_allmulti(priv->nl_socket_route, mlx5_ifindex(dev),
126                                        1);
127                 if (ret)
128                         goto error;
129         }
130         ret = mlx5_traffic_restart(dev);
131         if (ret)
132                 DRV_LOG(ERR, "port %u cannot enable allmulicast mode: %s",
133                         dev->data->port_id, strerror(rte_errno));
134 error:
135         /*
136          * rte_eth_allmulticast_enable() rollback
137          * dev->data->all_multicast in the case of failure.
138          */
139         return ret;
140 }
141
142 /**
143  * DPDK callback to disable allmulti mode.
144  *
145  * @param dev
146  *   Pointer to Ethernet device structure.
147  *
148  * @return
149  *   0 on success, a negative errno value otherwise and rte_errno is set.
150  */
151 int
152 mlx5_allmulticast_disable(struct rte_eth_dev *dev)
153 {
154         struct mlx5_priv *priv = dev->data->dev_private;
155         int ret;
156
157         dev->data->all_multicast = 0;
158         if (priv->config.vf) {
159                 ret = mlx5_nl_allmulti(priv->nl_socket_route, mlx5_ifindex(dev),
160                                        0);
161                 if (ret)
162                         goto error;
163         }
164         ret = mlx5_traffic_restart(dev);
165         if (ret)
166                 DRV_LOG(ERR, "port %u cannot disable allmulicast mode: %s",
167                         dev->data->port_id, strerror(rte_errno));
168 error:
169         /*
170          * rte_eth_allmulticast_disable() rollback
171          * dev->data->all_multicast in the case of failure.
172          */
173         return ret;
174 }