mlx5: support promiscuous and allmulticast Rx modes
[dpdk.git] / drivers / net / mlx5 / mlx5_trigger.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2015 6WIND S.A.
5  *   Copyright 2015 Mellanox.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 /* DPDK headers don't like -pedantic. */
35 #ifdef PEDANTIC
36 #pragma GCC diagnostic ignored "-pedantic"
37 #endif
38 #include <rte_ether.h>
39 #include <rte_ethdev.h>
40 #ifdef PEDANTIC
41 #pragma GCC diagnostic error "-pedantic"
42 #endif
43
44 #include "mlx5.h"
45 #include "mlx5_rxtx.h"
46 #include "mlx5_utils.h"
47
48 /**
49  * DPDK callback to start the device.
50  *
51  * Simulate device start by attaching all configured flows.
52  *
53  * @param dev
54  *   Pointer to Ethernet device structure.
55  *
56  * @return
57  *   0 on success, negative errno value on failure.
58  */
59 int
60 mlx5_dev_start(struct rte_eth_dev *dev)
61 {
62         struct priv *priv = dev->data->dev_private;
63         unsigned int i = 0;
64         unsigned int r;
65         struct rxq *rxq;
66
67         priv_lock(priv);
68         if (priv->started) {
69                 priv_unlock(priv);
70                 return 0;
71         }
72         DEBUG("%p: attaching configured flows to all RX queues", (void *)dev);
73         priv->started = 1;
74         if (priv->rss) {
75                 rxq = &priv->rxq_parent;
76                 r = 1;
77         } else {
78                 rxq = (*priv->rxqs)[0];
79                 r = priv->rxqs_n;
80         }
81         /* Iterate only once when RSS is enabled. */
82         do {
83                 int ret;
84
85                 /* Ignore nonexistent RX queues. */
86                 if (rxq == NULL)
87                         continue;
88                 ret = rxq_mac_addrs_add(rxq);
89                 if (!ret && priv->promisc_req)
90                         ret = rxq_promiscuous_enable(rxq);
91                 if (!ret && priv->allmulti_req)
92                         ret = rxq_allmulticast_enable(rxq);
93                 if (!ret)
94                         continue;
95                 WARN("%p: QP flow attachment failed: %s",
96                      (void *)dev, strerror(ret));
97                 /* Rollback. */
98                 while (i != 0) {
99                         rxq = (*priv->rxqs)[--i];
100                         if (rxq != NULL) {
101                                 rxq_allmulticast_disable(rxq);
102                                 rxq_promiscuous_disable(rxq);
103                                 rxq_mac_addrs_del(rxq);
104                         }
105                 }
106                 priv->started = 0;
107                 priv_unlock(priv);
108                 return -ret;
109         } while ((--r) && ((rxq = (*priv->rxqs)[++i]), i));
110         priv_unlock(priv);
111         return 0;
112 }
113
114 /**
115  * DPDK callback to stop the device.
116  *
117  * Simulate device stop by detaching all configured flows.
118  *
119  * @param dev
120  *   Pointer to Ethernet device structure.
121  */
122 void
123 mlx5_dev_stop(struct rte_eth_dev *dev)
124 {
125         struct priv *priv = dev->data->dev_private;
126         unsigned int i = 0;
127         unsigned int r;
128         struct rxq *rxq;
129
130         priv_lock(priv);
131         if (!priv->started) {
132                 priv_unlock(priv);
133                 return;
134         }
135         DEBUG("%p: detaching flows from all RX queues", (void *)dev);
136         priv->started = 0;
137         if (priv->rss) {
138                 rxq = &priv->rxq_parent;
139                 r = 1;
140         } else {
141                 rxq = (*priv->rxqs)[0];
142                 r = priv->rxqs_n;
143         }
144         /* Iterate only once when RSS is enabled. */
145         do {
146                 /* Ignore nonexistent RX queues. */
147                 if (rxq == NULL)
148                         continue;
149                 rxq_allmulticast_disable(rxq);
150                 rxq_promiscuous_disable(rxq);
151                 rxq_mac_addrs_del(rxq);
152         } while ((--r) && ((rxq = (*priv->rxqs)[++i]), i));
153         priv_unlock(priv);
154 }