Imported Upstream version 17.05.2
[deb_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 "-Wpedantic"
37 #endif
38 #include <rte_ether.h>
39 #include <rte_ethdev.h>
40 #include <rte_interrupts.h>
41 #include <rte_alarm.h>
42 #ifdef PEDANTIC
43 #pragma GCC diagnostic error "-Wpedantic"
44 #endif
45
46 #include "mlx5.h"
47 #include "mlx5_rxtx.h"
48 #include "mlx5_utils.h"
49
50 /**
51  * DPDK callback to start the device.
52  *
53  * Simulate device start by attaching all configured flows.
54  *
55  * @param dev
56  *   Pointer to Ethernet device structure.
57  *
58  * @return
59  *   0 on success, negative errno value on failure.
60  */
61 int
62 mlx5_dev_start(struct rte_eth_dev *dev)
63 {
64         struct priv *priv = dev->data->dev_private;
65         int err;
66
67         if (mlx5_is_secondary())
68                 return -E_RTE_SECONDARY;
69
70         priv_lock(priv);
71         if (priv->started) {
72                 priv_unlock(priv);
73                 return 0;
74         }
75         DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
76         err = priv_create_hash_rxqs(priv);
77         if (!err)
78                 err = priv_rehash_flows(priv);
79         if (!err)
80                 priv->started = 1;
81         else {
82                 ERROR("%p: an error occurred while configuring hash RX queues:"
83                       " %s",
84                       (void *)priv, strerror(err));
85                 goto error;
86         }
87         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_NONE)
88                 priv_fdir_enable(priv);
89         err = priv_flow_start(priv);
90         if (err) {
91                 priv->started = 0;
92                 ERROR("%p: an error occurred while configuring flows:"
93                       " %s",
94                       (void *)priv, strerror(err));
95                 goto error;
96         }
97         err = priv_rx_intr_vec_enable(priv);
98         if (err) {
99                 ERROR("%p: RX interrupt vector creation failed",
100                       (void *)priv);
101                 goto error;
102         }
103         priv_dev_interrupt_handler_install(priv, dev);
104         priv_xstats_init(priv);
105         priv_unlock(priv);
106         return 0;
107 error:
108         /* Rollback. */
109         priv_special_flow_disable_all(priv);
110         priv_mac_addrs_disable(priv);
111         priv_destroy_hash_rxqs(priv);
112         priv_flow_stop(priv);
113         priv_unlock(priv);
114         return -err;
115 }
116
117 /**
118  * DPDK callback to stop the device.
119  *
120  * Simulate device stop by detaching all configured flows.
121  *
122  * @param dev
123  *   Pointer to Ethernet device structure.
124  */
125 void
126 mlx5_dev_stop(struct rte_eth_dev *dev)
127 {
128         struct priv *priv = dev->data->dev_private;
129
130         if (mlx5_is_secondary())
131                 return;
132
133         priv_lock(priv);
134         if (!priv->started) {
135                 priv_unlock(priv);
136                 return;
137         }
138         DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
139         priv_special_flow_disable_all(priv);
140         priv_mac_addrs_disable(priv);
141         priv_destroy_hash_rxqs(priv);
142         priv_fdir_disable(priv);
143         priv_flow_stop(priv);
144         priv_rx_intr_vec_disable(priv);
145         priv_dev_interrupt_handler_uninstall(priv, dev);
146         priv->started = 0;
147         priv_unlock(priv);
148 }