4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_interrupts.h>
38 #include <rte_alarm.h>
41 #include "mlx5_rxtx.h"
42 #include "mlx5_utils.h"
45 priv_txq_stop(struct priv *priv)
49 for (i = 0; i != priv->txqs_n; ++i)
50 mlx5_priv_txq_release(priv, i);
54 priv_txq_start(struct priv *priv)
59 /* Add memory regions to Tx queues. */
60 for (i = 0; i != priv->txqs_n; ++i) {
63 struct mlx5_txq_ctrl *txq_ctrl = mlx5_priv_txq_get(priv, i);
67 LIST_FOREACH(mr, &priv->mr, next)
68 priv_txq_mp2mr_reg(priv, &txq_ctrl->txq, mr->mp, idx++);
69 txq_alloc_elts(txq_ctrl);
70 txq_ctrl->ibv = mlx5_priv_txq_ibv_new(priv, i);
83 priv_rxq_stop(struct priv *priv)
87 for (i = 0; i != priv->rxqs_n; ++i)
88 mlx5_priv_rxq_release(priv, i);
92 priv_rxq_start(struct priv *priv)
97 for (i = 0; i != priv->rxqs_n; ++i) {
98 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_priv_rxq_get(priv, i);
102 ret = rxq_alloc_elts(rxq_ctrl);
105 rxq_ctrl->ibv = mlx5_priv_rxq_ibv_new(priv, i);
106 if (!rxq_ctrl->ibv) {
118 * DPDK callback to start the device.
120 * Simulate device start by attaching all configured flows.
123 * Pointer to Ethernet device structure.
126 * 0 on success, negative errno value on failure.
129 mlx5_dev_start(struct rte_eth_dev *dev)
131 struct priv *priv = dev->data->dev_private;
132 struct mlx5_mr *mr = NULL;
135 if (mlx5_is_secondary())
136 return -E_RTE_SECONDARY;
139 DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
140 rte_mempool_walk(mlx5_mp2mr_iter, priv);
141 err = priv_txq_start(priv);
143 ERROR("%p: TXQ allocation failed: %s",
144 (void *)dev, strerror(err));
147 /* Update send callback. */
148 priv_dev_select_tx_function(priv, dev);
149 err = priv_rxq_start(priv);
151 ERROR("%p: RXQ allocation failed: %s",
152 (void *)dev, strerror(err));
155 /* Update receive callback. */
156 priv_dev_select_rx_function(priv, dev);
157 err = priv_create_hash_rxqs(priv);
159 err = priv_rehash_flows(priv);
161 ERROR("%p: an error occurred while configuring hash RX queues:"
163 (void *)priv, strerror(err));
166 if (dev->data->promiscuous)
167 mlx5_promiscuous_enable(dev);
168 err = priv_flow_start(priv, &priv->ctrl_flows);
170 ERROR("%p: an error occurred while configuring control flows:"
172 (void *)priv, strerror(err));
175 err = priv_flow_start(priv, &priv->flows);
177 ERROR("%p: an error occurred while configuring flows:"
179 (void *)priv, strerror(err));
182 err = priv_rx_intr_vec_enable(priv);
184 ERROR("%p: RX interrupt vector creation failed",
188 priv_dev_interrupt_handler_install(priv, dev);
189 priv_xstats_init(priv);
194 LIST_FOREACH(mr, &priv->mr, next)
195 priv_mr_release(priv, mr);
196 priv_special_flow_disable_all(priv);
197 priv_mac_addrs_disable(priv);
198 priv_destroy_hash_rxqs(priv);
199 priv_flow_stop(priv, &priv->flows);
200 priv_flow_flush(priv, &priv->ctrl_flows);
208 * DPDK callback to stop the device.
210 * Simulate device stop by detaching all configured flows.
213 * Pointer to Ethernet device structure.
216 mlx5_dev_stop(struct rte_eth_dev *dev)
218 struct priv *priv = dev->data->dev_private;
221 if (mlx5_is_secondary())
225 dev->data->dev_started = 0;
226 /* Prevent crashes when queues are still in use. */
227 dev->rx_pkt_burst = removed_rx_burst;
228 dev->tx_pkt_burst = removed_tx_burst;
230 usleep(1000 * priv->rxqs_n);
231 DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
232 priv_special_flow_disable_all(priv);
233 priv_mac_addrs_disable(priv);
234 priv_destroy_hash_rxqs(priv);
235 priv_flow_stop(priv, &priv->flows);
236 priv_flow_flush(priv, &priv->ctrl_flows);
237 priv_rx_intr_vec_disable(priv);
238 priv_dev_interrupt_handler_uninstall(priv, dev);
241 LIST_FOREACH(mr, &priv->mr, next) {
242 priv_mr_release(priv, mr);