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 if (idx == MLX5_PMD_TX_MP_CACHE)
72 txq_alloc_elts(txq_ctrl);
73 txq_ctrl->ibv = mlx5_priv_txq_ibv_new(priv, i);
86 priv_rxq_stop(struct priv *priv)
90 for (i = 0; i != priv->rxqs_n; ++i)
91 mlx5_priv_rxq_release(priv, i);
95 priv_rxq_start(struct priv *priv)
100 for (i = 0; i != priv->rxqs_n; ++i) {
101 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_priv_rxq_get(priv, i);
105 ret = rxq_alloc_elts(rxq_ctrl);
108 rxq_ctrl->ibv = mlx5_priv_rxq_ibv_new(priv, i);
109 if (!rxq_ctrl->ibv) {
121 * DPDK callback to start the device.
123 * Simulate device start by attaching all configured flows.
126 * Pointer to Ethernet device structure.
129 * 0 on success, negative errno value on failure.
132 mlx5_dev_start(struct rte_eth_dev *dev)
134 struct priv *priv = dev->data->dev_private;
135 struct mlx5_mr *mr = NULL;
138 dev->data->dev_started = 1;
140 err = priv_flow_create_drop_queue(priv);
142 ERROR("%p: Drop queue allocation failed: %s",
143 (void *)dev, strerror(err));
146 DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
147 rte_mempool_walk(mlx5_mp2mr_iter, priv);
148 err = priv_txq_start(priv);
150 ERROR("%p: TXQ allocation failed: %s",
151 (void *)dev, strerror(err));
154 err = priv_rxq_start(priv);
156 ERROR("%p: RXQ allocation failed: %s",
157 (void *)dev, strerror(err));
160 err = priv_rx_intr_vec_enable(priv);
162 ERROR("%p: RX interrupt vector creation failed",
166 priv_xstats_init(priv);
167 /* Update link status and Tx/Rx callbacks for the first time. */
168 memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link));
169 priv_link_update(priv, 1);
170 priv_dev_interrupt_handler_install(priv, dev);
175 dev->data->dev_started = 0;
176 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
177 priv_mr_release(priv, mr);
178 priv_flow_stop(priv, &priv->flows);
179 priv_dev_traffic_disable(priv, dev);
182 priv_flow_delete_drop_queue(priv);
188 * DPDK callback to stop the device.
190 * Simulate device stop by detaching all configured flows.
193 * Pointer to Ethernet device structure.
196 mlx5_dev_stop(struct rte_eth_dev *dev)
198 struct priv *priv = dev->data->dev_private;
202 dev->data->dev_started = 0;
203 /* Prevent crashes when queues are still in use. */
204 dev->rx_pkt_burst = removed_rx_burst;
205 dev->tx_pkt_burst = removed_tx_burst;
207 usleep(1000 * priv->rxqs_n);
208 DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
209 priv_flow_stop(priv, &priv->flows);
210 priv_dev_traffic_disable(priv, dev);
211 priv_rx_intr_vec_disable(priv);
212 priv_dev_interrupt_handler_uninstall(priv, dev);
215 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
216 priv_mr_release(priv, mr);
217 priv_flow_delete_drop_queue(priv);
222 * Enable traffic flows configured by control plane
225 * Pointer to Ethernet device private data.
227 * Pointer to Ethernet device structure.
233 priv_dev_traffic_enable(struct priv *priv, struct rte_eth_dev *dev)
235 struct rte_flow_item_eth bcast = {
236 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
238 struct rte_flow_item_eth ipv6_multi_spec = {
239 .dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
241 struct rte_flow_item_eth ipv6_multi_mask = {
242 .dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
244 struct rte_flow_item_eth unicast = {
245 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
247 struct rte_flow_item_eth unicast_mask = {
248 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
250 const unsigned int vlan_filter_n = priv->vlan_filter_n;
251 const struct ether_addr cmp = {
252 .addr_bytes = "\x00\x00\x00\x00\x00\x00",
260 if (dev->data->promiscuous) {
261 struct rte_flow_item_eth promisc = {
262 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
263 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
267 claim_zero(mlx5_ctrl_flow(dev, &promisc, &promisc));
270 if (dev->data->all_multicast) {
271 struct rte_flow_item_eth multicast = {
272 .dst.addr_bytes = "\x01\x00\x00\x00\x00\x00",
273 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
277 claim_zero(mlx5_ctrl_flow(dev, &multicast, &multicast));
279 /* Add broadcast/multicast flows. */
280 for (i = 0; i != vlan_filter_n; ++i) {
281 uint16_t vlan = priv->vlan_filter[i];
283 struct rte_flow_item_vlan vlan_spec = {
284 .tci = rte_cpu_to_be_16(vlan),
286 struct rte_flow_item_vlan vlan_mask = {
290 ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
291 &vlan_spec, &vlan_mask);
294 ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
296 &vlan_spec, &vlan_mask);
300 if (!vlan_filter_n) {
301 ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
304 ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
310 /* Add MAC address flows. */
311 for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
312 struct ether_addr *mac = &dev->data->mac_addrs[i];
314 if (!memcmp(mac, &cmp, sizeof(*mac)))
316 memcpy(&unicast.dst.addr_bytes,
319 for (j = 0; j != vlan_filter_n; ++j) {
320 uint16_t vlan = priv->vlan_filter[j];
322 struct rte_flow_item_vlan vlan_spec = {
323 .tci = rte_cpu_to_be_16(vlan),
325 struct rte_flow_item_vlan vlan_mask = {
329 ret = mlx5_ctrl_flow_vlan(dev, &unicast,
336 if (!vlan_filter_n) {
337 ret = mlx5_ctrl_flow(dev, &unicast,
350 * Disable traffic flows configured by control plane
353 * Pointer to Ethernet device private data.
355 * Pointer to Ethernet device structure.
361 priv_dev_traffic_disable(struct priv *priv, struct rte_eth_dev *dev)
364 priv_flow_flush(priv, &priv->ctrl_flows);
369 * Restart traffic flows configured by control plane
372 * Pointer to Ethernet device private data.
374 * Pointer to Ethernet device structure.
380 priv_dev_traffic_restart(struct priv *priv, struct rte_eth_dev *dev)
382 if (dev->data->dev_started) {
383 priv_dev_traffic_disable(priv, dev);
384 priv_dev_traffic_enable(priv, dev);
390 * Restart traffic flows configured by control plane
393 * Pointer to Ethernet device structure.
399 mlx5_traffic_restart(struct rte_eth_dev *dev)
401 struct priv *priv = dev->data->dev_private;
404 priv_dev_traffic_restart(priv, dev);