net/mlx5: fix crash during RETA update
[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 #include <unistd.h>
34
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_interrupts.h>
38 #include <rte_alarm.h>
39
40 #include "mlx5.h"
41 #include "mlx5_rxtx.h"
42 #include "mlx5_utils.h"
43
44 /**
45  * DPDK callback to start the device.
46  *
47  * Simulate device start by attaching all configured flows.
48  *
49  * @param dev
50  *   Pointer to Ethernet device structure.
51  *
52  * @return
53  *   0 on success, negative errno value on failure.
54  */
55 int
56 mlx5_dev_start(struct rte_eth_dev *dev)
57 {
58         struct priv *priv = dev->data->dev_private;
59         int err;
60
61         if (mlx5_is_secondary())
62                 return -E_RTE_SECONDARY;
63
64         priv_lock(priv);
65         /* Update Rx/Tx callback. */
66         priv_dev_select_tx_function(priv, dev);
67         priv_dev_select_rx_function(priv, dev);
68         DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
69         err = priv_create_hash_rxqs(priv);
70         if (!err)
71                 err = priv_rehash_flows(priv);
72         else {
73                 ERROR("%p: an error occurred while configuring hash RX queues:"
74                       " %s",
75                       (void *)priv, strerror(err));
76                 goto error;
77         }
78         err = priv_flow_start(priv);
79         if (err) {
80                 ERROR("%p: an error occurred while configuring flows:"
81                       " %s",
82                       (void *)priv, strerror(err));
83                 goto error;
84         }
85         err = priv_rx_intr_vec_enable(priv);
86         if (err) {
87                 ERROR("%p: RX interrupt vector creation failed",
88                       (void *)priv);
89                 goto error;
90         }
91         priv_dev_interrupt_handler_install(priv, dev);
92         priv_xstats_init(priv);
93         priv_unlock(priv);
94         return 0;
95 error:
96         /* Rollback. */
97         priv_special_flow_disable_all(priv);
98         priv_mac_addrs_disable(priv);
99         priv_destroy_hash_rxqs(priv);
100         priv_flow_stop(priv);
101         priv_unlock(priv);
102         return -err;
103 }
104
105 /**
106  * DPDK callback to stop the device.
107  *
108  * Simulate device stop by detaching all configured flows.
109  *
110  * @param dev
111  *   Pointer to Ethernet device structure.
112  */
113 void
114 mlx5_dev_stop(struct rte_eth_dev *dev)
115 {
116         struct priv *priv = dev->data->dev_private;
117
118         if (mlx5_is_secondary())
119                 return;
120
121         priv_lock(priv);
122         dev->data->dev_started = 0;
123         /* Prevent crashes when queues are still in use. */
124         dev->rx_pkt_burst = removed_rx_burst;
125         dev->tx_pkt_burst = removed_tx_burst;
126         rte_wmb();
127         usleep(1000 * priv->rxqs_n);
128         DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
129         priv_special_flow_disable_all(priv);
130         priv_mac_addrs_disable(priv);
131         priv_destroy_hash_rxqs(priv);
132         priv_flow_stop(priv);
133         priv_rx_intr_vec_disable(priv);
134         priv_dev_interrupt_handler_uninstall(priv, dev);
135         priv_unlock(priv);
136 }